Docs
← Back to site

Mobile and desktop apps

1 min readUpdated November 11, 2026

The app sends straight from the device. Nothing secret is in it: the site key and receive address are public. Each screen counts as a page of the site.

React Native
import { createAppClient } from 'nahnu-analytics-sdk/app';
import { AppState, Dimensions, Platform } from 'react-native';

const app = createAppClient({
  siteKey: SITE_KEY,         // site.site_key
  receiveUrl: RECEIVE_URL,   // site.install.receive_url
  domain: 'app.example.com', // one of the site's domains
  platform: Platform.OS,
  appVersion: '2.1.0',
  screenWidth: Dimensions.get('window').width,
});

app.screen('Home'); // on each screen change (React Navigation's state listener)
app.event('Purchase', { revenue: { amount: 12.5, currency: 'EUR' } });
app.identify(user.id);
AppState.addEventListener('change', (s) => (s === 'active' ? app.resume() : app.pause()));
React Native
import { createAppClient } from 'nahnu-analytics-sdk/app';
import { AppState, Dimensions, Platform } from 'react-native';

const app = createAppClient({
  siteKey: SITE_KEY,         // site.site_key
  receiveUrl: RECEIVE_URL,   // site.install.receive_url
  domain: 'app.example.com', // one of the site's domains
  platform: Platform.OS,
  appVersion: '2.1.0',
  screenWidth: Dimensions.get('window').width,
});

app.screen('Home'); // on each screen change (React Navigation's state listener)
app.event('Purchase', { revenue: { amount: 12.5, currency: 'EUR' } });
app.identify(user.id);
AppState.addEventListener('change', (s) => (s === 'active' ? app.resume() : app.pause()));

Offline#

What can’t be sent waits in order and goes out with the next screen, on resume(), or on flush() (call it when NetInfo says you’re back).

  • Pass storage: AsyncStorage (or MMKV) to keep the queue across app restarts.
  • Up to maxQueue items are kept (default 200; the oldest go first). pending() says how many wait.
  • Queued items count when they arrive, not when they happened.
  • setEnabled(false) stops all sending, for an opt-out switch in your settings.

Give each app its own site, or its own domain on the user’s site, so app and web can be told apart. The platform property separates iOS from Android in Goals & events › Properties.

Swift, Kotlin or anything else#

POST JSON as text/plain to the receive address. One line per kind:

Request bodies
{"k":"<site key>","n":"v","u":"https://app.example.com/Home","r":"","w":390,"p":{"platform":"ios"}}
{"k":"<site key>","n":"c","c":"Purchase","u":"https://app.example.com/Cart","m":{"a":12.5,"c":"EUR"}}
{"k":"<site key>","n":"x","u":"https://app.example.com/Home","e":42}

A screen (v), an event (c), and leaving a screen after e seconds (x). The u host must be one of the site’s domains.

Was this helpful?