Mobile apps
How sessions, screens, offline delivery, app versions and privacy work when you track a native or cross-platform app.
Mobile SDKs send the same events as the web tracker to the same endpoint, POST /api/event, so app and web traffic share one dashboard, funnels and retention. A few things work differently in apps, and this page explains them. Platforms in the dashboard breaks traffic down by platform, app version and device model.
SDKs
| Platform | Package | Status |
|---|---|---|
| React Native and Expo | @stancelens/react-native | Ready; build from the repository until it's on npm |
| iOS (Swift) | packages/swift | Ready; add as a local Swift package |
| Android (Kotlin) | packages/android | Ready; build to a local Maven repository |
| Flutter | stancelens | Ready; install from Git until it's on pub.dev |
The behaviour below is what the server does for every SDK. Each SDK page lists its own defaults (queue size, flush interval, retry timing).
Sessions
On the web the server splits visits after 30 minutes of inactivity (the site's Session timeout under Site settings → Collection). Apps own their sessions instead: the SDK sends a session_id with every event, and the server uses it as-is (scoped to the site and install), so a session never splits or merges because events arrived late or out of order.
- A new session starts after 30 minutes without activity (
sessionTimeoutin React Native). - Time in the background counts as inactivity: returning after more than 30 minutes starts a new session, and the open screen is sent again as its first view.
- Restarting the app within 30 minutes continues the session.
reset()(log out) starts a new session with a new anonymous ID.
Screens
A screen view is a pageview whose path is "/" + screen name: the screen Settings/Profile is stored as /Settings/Profile, with the name as the title. Everything that works on page paths (top pages, entry and exit pages, page goals, funnel steps, f_path filters) works on screens.
- Name screens like URL paths, with
/for nesting, and keep IDs out of them:Product, notProduct/8812. Put the ID in a property if you need it. - When the screen changes or the app goes to the background, the time spent on it, background excluded, is sent as engagement (if at least one second) and shows up as time on page.
- Events tracked while a screen is open carry its path, so a breakdown of a custom event by page works for apps too.
- Navigation integrations send screens for you: React Navigation and Expo Router.
The screen field is something else: it's the display size (393x852), as on the web.
Offline delivery
Every event is written to an on-device queue with the time it happened (ts) and sent in batches. Events recorded without a connection go out on a later flush or the next launch, and are stored at their original time.
- The server accepts events up to 72 hours old from an SDK (30 days with an API key, which is only for servers). Older events are dropped as
ts_too_old, so an app that stays offline for longer loses those events. - Events more than 5 minutes in the future are dropped; anything less is clamped to now.
- An SDK may also send
sent_at, its clock when the request left the device. The server then shifts everytsin the batch by the difference between its clock and the device's, which corrects devices with a wrong clock. The Swift, Android, Flutter and React Native SDKs all send it, as does the JavaScript SDK. - Every event from those SDKs also carries a client event
id. A retry carrying anidthe server has seen for that site in the last 24 hours is dropped as a duplicate, so a batch that reached the server but whose response was lost isn't counted twice. - In React Native the queue holds 1,000 events by default (
maxQueueSize); beyond that the oldest are dropped.
App versions and devices
Each event carries platform, app_version, os, os_version, device_model, device_type and sdk. The session keeps the platform, app version and device model of its first event.
- Format
app_versionasversion (build), e.g.2.4.1 (318), so releases sort and group sensibly. The React Native SDK detects it (see what it collects); passcontext: { app_version }to override. device_typeismobile,tablet,desktoportv, and fills the same Device breakdown as web traffic.- For native platforms the server takes OS and device from these fields rather than from the User-Agent.
Privacy
Apps can't use the web tracker's daily visitor hash, because many devices share an IP and the hash would change every day. Instead each SDK generates a random install ID (vid) on first launch and stores it on the device.
- The install ID is random. It isn't derived from the device, it isn't an advertising ID (IDFA, GAID), and it's replaced by
reset(). Deleting the app deletes it. - No contacts, location or advertising identifiers are read.
uidis only sent after you callidentify; that is personal data, see Identify users.optOut()stops all sending and is remembered across launches;defaultOptOut: truestarts opted out until the user agrees.- Erase a user's data with `DELETE /api/v1/users/:id`.
Privacy manifests and store labels
Apple asks apps and SDKs to declare collected data in a privacy manifest (PrivacyInfo.xcprivacy) and on the App Store privacy label; Google Play has a similar Data safety form. The Swift package ships its own manifest. The React Native SDK has no native code, so declare what it collects in your app's manifest and store forms:
| Data | Apple data type | Linked to the user | Used for tracking |
|---|---|---|---|
| Events, screens, engagement | Product Interaction | No (yes once you call identify) | No |
Install ID (vid) | Device ID | No | No |
User ID from identify | User ID | Yes | No |
| Revenue events | Purchase History | No (yes once you call identify) | No |
$error reports, if captureErrors is on | Crash Data | No | No |
Stancelens doesn't track users across other companies' apps or sites, so NSPrivacyTracking is false and there are no tracking domains. Which purposes you declare (Analytics, App Functionality) depends on how you use the data. This is guidance, not legal advice.
Payload reference
Writing your own SDK, or sending from a platform without one? Post one event or an array of up to 100 to POST /api/event (CORS open, JSON or text/plain). The response is 202 with { accepted, dropped, sid, results }: results has one entry per event, { "ok": true } or { "ok": false, "reason": "…" } (the reasons are listed under Send events). Each event may be up to 64 KiB of JSON; a bigger one is dropped as too_large and the rest are stored. A request body over 1 MB is 413, and too many requests from one address is 429 with Retry-After (seconds).
| Field | |
|---|---|
site | Required. Site ID. |
name | Default pageview. Names starting with $ are reserved. |
url or path | Page URL, or "/" + screen name in apps. |
referrer, title, language, timezone | Strings. Country comes from your CDN's geo headers, else timezone (IANA), else the region in language. A country field is only honoured on server-side events sent with an API key. |
screen | Display size, "1440x900". |
props | Custom properties. Numeric props.revenue with props.currency is counted as revenue. |
revenue | A number, or { amount, currency }. |
duration | Milliseconds engaged (page views and $engagement). For $engagement, the server keeps the largest value per page view, so send the running total for the screen, not the time since the last ping. |
ts | Epoch ms when it happened; see offline delivery. |
sent_at | Device clock in epoch ms when the request was sent. |
id | Client event ID for de-duplication. |
vid | Stable anonymous install or browser ID. |
uid | Your user ID, after identify. Required for $identify. |
traits | With $identify: properties merged into the user profile. |
session_id | SDK-owned session ID. |
platform | web, ios, android, react-native, flutter or server. |
app_version, os, os_version, device_model | Strings, e.g. "2.4.1 (318)", "iOS", "18.1", "iPhone16,2". |
device_type | mobile, tablet, desktop or tv. |
sdk | Name and version, e.g. "stancelens-swift/1.0.0". |
Set platform (or an sdk starting with stancelens-). Bot filtering then only drops known crawlers and headless browsers, so HTTP-library user agents like okhttp/4.12 or Dart/3.5 get through. Without it, the event is treated as web traffic and the stricter browser check applies.