Skip to main content
The React Native client is one TypeScript file with no imports. It runs on Hermes and in Expo. It keeps a random install id in the storage you pass in, queues events while the network is down, and sends them to https://in.crispstats.com/e. It does not read the advertising identifier.

Get the file

From the folder where you keep app code, for example src/analytics:
Then import it by its relative path, such as ./crispstats. To update, download it again.

Count screens

Create one client in its own module and import it wherever you need it.
Replace cs_pk_xxxxxxxx with the site’s public key from Settings, Tracking code, and com.acme.app with the bundle id or application id. platform is the device, ios or android, not the name of the SDK. revenue takes minor units: 4900 with USD is $49.00. A negative amount is ignored. storage must have get and set. AsyncStorage names them getItem and setItem, so wrap it with asyncStorage as above. memoryStorage() keeps everything in memory, which suits tests. Platform.Version on Android is the API level, not the Android release. Pass the release string when you have it. Call screen on each navigation. The client sends the previous screen’s visible time first. bindAppState calls leave when the app leaves the foreground and resume when it comes back, so time on screen stops while the app is in the background. After 30 minutes or more away, the collector has started a new session, so resume counts the current screen again and its time starts from zero. A screen name is one to eight segments of letters, numbers, spaces, ., _ and -, separated by /, each up to 80 characters and 200 in all. Settings/Account is stored as the page /Settings/Account. A name outside these rules, such as ../secret or Search?q=x, is ignored and nothing is sent.

Tablets

device is phone unless you pass tablet. deviceFor returns tablet on an iPad (Platform.isPad) or when the shorter side of the window is at least 600 dp, which is the usual Android tablet line. The sample above uses it. Pass the link’s campaign tags with the screen it opens. campaignFromUrl reads them from the URL.
campaignFromUrl("acme://promo?utm_source=newsletter&utm_medium=email") returns { utm_medium: "email", utm_source: "newsletter" }. The third argument of screen takes:
  • campaign: query parameters such as utm_source, utm_medium, utm_campaign, utm_term, utm_content, ref and ad click ids such as gclid. A key is lower-cased and must be 1 to 32 letters, numbers or _. A value is trimmed and must be 1 to 200 characters. Other pairs are left out, and at most 10 are kept.
  • referrer: the URL that sent the user, up to 2,000 characters.
Both apply to that one screen view. utm_source and utm_medium set the channel, the same way they do on a web page. Later events on the screen do not repeat them.

Opt out

optOut drops anything still queued, sends nothing, and is remembered in storage across launches. optIn starts sending again. If the app opted out before the first launch finished, optIn creates the install id then.

Errors

The message is grouped on the Errors page. The source is the screen or file name, and it is optional.

When the network is down

Events wait in storage, up to the newest 100. The client tries again when it starts, when the app returns to the foreground, after each new event, and on a timer that waits 1 second, then 2, then 4, up to 60. A request that takes longer than 10 seconds is tried again later. await analytics.flush() sends the queue now. No call throws, and no call waits for the network. Time on screen is measured from when you call screen, leave and resume, not from when the request finishes. If an option can never produce a valid event, such as a site key that does not start with cs_pk_, an appId that is not a bundle id, or an empty appVersion, the client sends nothing and logs one console.warn that names the problem.

A stronger install id

The install id is 16 random bytes from crypto.getRandomValues. Hermes does not always provide it, and then the client falls back to Math.random. For a stronger id, install react-native-get-random-values and import it once, first thing in the app’s entry file:
In Expo, you can use expo-crypto instead:
The language and time zone come from Intl when the device has it, as a tag such as en-US and a zone such as Europe/Berlin. Pass locale and timezone to set them yourself.

What gets stored

The screen is a pageview. The browser breakdown shows iOS app or Android app, and a tablet shows as tablet. The app version, build, OS version and SDK name are properties on the event, and the SDK is react-native. The install id itself is not stored. See mobile apps for the rest of the mapping.
Last modified on December 2, 2026