DocsSDK

Viewthrough SDK

Installs, onboarding, paywall and checkout — straight from your app, without PostHog. Only the money events, batched and offline-safe. Revenue keeps coming from RevenueCat.
  • React Native · Swift · Kotlin · Flutter · HTTP
  • Offline-safe batching
  • No IDFA, no ATT prompt

1Get your key

In Viewthrough: Integrations → Connect SDK → pick the app → Create SDK key. The key (vts_…) is shown once; it can only write events, never read anything, so it is fine inside your app binary.

2Add it to your app

Pick your stack. The methods are the same everywhere — only the spelling follows the language.

Install

Terminal
npm install @viewthrough/sdk @react-native-async-storage/async-storage

Code

React Native / Expo
import { createViewthrough } from "@viewthrough/sdk";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Platform } from "react-native";

export const vt = createViewthrough({
  key: "vts_YOUR_KEY",
  platform: Platform.OS === "ios" ? "ios" : "android",
  appVersion: "1.0.0",          // e.g. Constants.expoConfig?.version
  storage: AsyncStorage,
});

// after login — the SAME id you give RevenueCat (Purchases.logIn)
vt.identify(user.id);

vt.onboardingCompleted();
vt.paywallShown({ surface: "onboarding" });
vt.checkoutStarted({ product_id: "pro_yearly" });

Swift, Kotlin and Dart ship as a single file you drop into your project — no package manager, nothing to configure: Viewthrough.swift, Viewthrough.kt, viewthrough.dart. The Swift Package lives at github.com/viewthrough/viewthrough-ios-sdk; the React Native package is @viewthrough/sdk on npm.

3The one rule: same id as RevenueCat

This is what links a purchase to its post

The SDK makes a device_id on first start and keeps it on the device — that is the install. After login, call identify(userId) with the same id you give RevenueCat (Purchases.logIn(userId)). That is how a purchase finds its install, and the install its creator post. No login in your app? Give RevenueCat the device id instead.

On logout call reset(): the user id is forgotten, the device id stays — it is still the same install.

Events

Only these exist. Anything else is rejected by the server — Viewthrough is not a product-analytics tool.

CallEventMeaning
automaticinstallfirst start on this device
automatic / appOpened()app_opencold start (and foreground, if you call it)
onboardingStarted()onboarding_started
onboardingCompleted()onboarding_completed
paywallShown(surface)paywall_shownsurface: onboarding, settings, feature_gate …
checkoutStarted(productId, plan)checkout_started
trialStarted(productId)trial_startedwhat the app saw — the store's truth comes from RevenueCat
purchase(productId, plan)purchasesame

setAttribution(acquisitionSource: …) stores the “How did you hear about us?” answer; installUtmCampaign ties the install to a Viewthrough tracking link (Play Install Referrer or deep link). Both change the device, they are not counted as events.

How sending works

  • Events queue on the device and go out in batches: after 20 events or 30 seconds, whichever comes first. flush() sends now; the SDKs also flush when the app goes to the background.
  • Offline or server error: the queue stays and the SDK retries with backoff (1 s → 5 min). Nothing is dropped except when the queue exceeds 5,000 events (the oldest go) or the server rejects a batch as malformed (HTTP 400).
  • Every event has a UUID — a batch sent twice counts once.
  • A wrong or revoked key (HTTP 401) stops sending until the next start; the queue is kept.

HTTP API (any platform)

One request per batch, up to 100 events. Make a UUID on first start and keep it; send install once, app_open on each cold start, the funnel events where they happen.

HTTP
POST https://viewthrough.app/api/v1/events
Authorization: Bearer vts_…
Content-Type: application/json

{
  "device_id": "4a7c…",
  "user_id": "user_42",
  "platform": "ios",
  "app_version": "2.4.1",
  "os_version": "18.1",
  "locale": "de-DE",
  "sent_at": "2026-11-05T10:00:05Z",
  "events": [
    { "event_id": "3f1d…", "event": "install",       "ts": "2026-11-05T09:59:58Z" },
    { "event_id": "8b2e…", "event": "paywall_shown", "ts": "2026-11-05T10:00:03Z",
      "props": { "surface": "onboarding" } }
  ]
}
  • Authorization: Bearer vts_… or X-Viewthrough-Key: vts_….
  • event_id: a UUID per event — the server deduplicates on it. ts: ISO 8601 or epoch milliseconds, device time is fine.
  • Control events: identify (with user_id), set_attribution (props), opt_out, opt_in.
  • Optional root fields: os_version, locale, sdk { name, version }, sent_at (lets the server correct a wrong device clock).
  • Answers: 202 accepted · 400 malformed (drop the batch, it will never pass) · 401 unknown key · 413 too many events · 429 slow down · 5xx retry later.

Privacy

  • Consent first: with requireConsent (all four SDKs) nothing is stored on the device and nothing is sent until optIn(). The choice is remembered; optOut() withdraws it.
  • optOut() stops collection, discards events still waiting on the device and removes the device from every count; optIn() resumes.
  • What leaves the device: the random device id, the user id you pass to identify, platform, app and OS version, locale, the events with timestamps and the props you pass. No names or email addresses in props or user ids.
  • No IP is stored. The country is derived on the server from the request, then the request is forgotten; for rate limiting only a keyed hash of the IP is kept, for at most two days.
  • No IDFA, no ATT prompt, no fingerprinting. The device id is a random UUID.
  • You decide whether and on which legal basis the SDK runs in your app (e.g. consent under ePrivacy Art. 5(3) / TDDDG § 25) and inform your users. Viewthrough processes the data on your behalf under the data processing agreement.