Events and revenue in React Native

After this page, purchases in your app show up in Analytics with their revenue, on the tap, channel and campaign that brought the user.

On this page 6
  1. 1. Know what's already reported
  2. 2. Record a purchase
  3. 3. Understand which tap gets the credit
  4. Link events to your users (optional)
  5. Common errors
  6. Next steps
Time
About 5 minutes
You need
The SDK installed and started (Install & set up)
Works on
Android, iPhone

1. Know what's already reported

Every time a link opens the app, the SDK reports it once. You don't write any analytics code for this.

How the app opened Joined to
Verified link tapped in WhatsApp, Gmail, Messages… The link (also counted as a tap)
Browser handed off to the app (yourapp://…) The exact tap
First open after a Play install The exact tap that sent the user to the store
First open after an App Store install The matched tap
Your own https links Host and path only, never the query

Reports that can't be sent (offline, server busy) are saved and retried on the next start and whenever the app comes back to the foreground, for up to 7 days (100 at most). Each open has an id, so nothing is counted twice. Navigation never waits for a report.

You should see: after tapping a link, Dashboard → Analytics shows the tap and the app open within a minute.

2. Record a purchase

TypeScript
import { links } from './links';

links.trackEvent('purchase', { value: 49.99, currency: 'USD' }); // the tap is attached automatically

trackEvent returns a promise that resolves to true when the event was accepted. Use any event name (signup, add_to_cart); value, currency and eventId are optional. Pass your order id as eventId ({ value: 49.99, currency: 'USD', eventId: order.id }): Strait counts each one once, so a retry never counts twice; left out, the SDK makes one. An event that can't be sent (offline, server busy) is kept and sent later, for up to 7 days; trackEvent then resolves false.

You should see: the purchase at the bottom of the funnel in Analytics, with its revenue, on the channel of the link you tapped.

3. Understand which tap gets the credit

The event carries the tap id of the most recent link open, as long as that open was in the last 7 days. The tap id comes from a browser hand-off to yourapp://…?strait_click=…, a Google Play install, an open from a verified short link, or an iPhone install match. When our server matches an open or an install, it sends the tap id back with its answer. That lets Analytics put the revenue on the exact tap's channel and A/B variant. Each newer open replaces the remembered tap with its own, so an older tap never takes credit for a newer open; if an open comes with no tap id, the remembered one is forgotten and the event carries none. To name the tap yourself, pass clickId, which overrides the remembered one. The server keeps it only if it's a tap of your workspace; otherwise it drops the id and still records the event.

You should see: two links tapped one after the other credit a purchase to the second one only.

Call setUserId with your own user id after your sign-in, and again when the app starts with someone already signed in: it is kept in memory only. Call it with null on sign-out. (React Native SDK 0.11.4 or later.)

TypeScript
links.setUserId(user.id);   // after sign-in, and at launch when already signed in
links.setUserId(null);      // on sign-out

Later trackEvent calls carry the id to your app.event webhook as userId, so you can join the tap, link and campaign to your own users and see which campaigns bring paying ones. Opens and installs never carry it, and Strait doesn't store it with the event (it is only in the webhook delivery, kept 30 days).

  • Emails and phone numbers are hashed on the device. An id with @ is sent as the SHA-256 hex of the lower-cased email. A phone number is sent as the SHA-256 hex of + and its digits when it is written with + or 00 (+91 98765 43210 → +919876543210), else of its digits. The webhook then has userIdHashed: true. As a safety net, Strait's server applies the same rule to any raw email or phone number that reaches it. To join, hash your own value the same way (the full rule).
  • Opt-out clears it. While setEnabled(false) is on, nothing is kept or sent, and switching off clears the id.
  • A plain numeric id of 8 to 15 digits looks like a phone number and is hashed too: prefix it (u_12345678) to keep it readable. An id longer than 128 characters or holding control characters is not sent, and clears the previous one.
  • Anyone with your publishable key can send any userId, so treat it as a claim, like revenue sent from the app.

Common errors

  • The purchase shows as direct. The last link open was more than 7 days ago, or the app was opened without a link since. That's by design.
  • trackEvent resolves to false. The phone was offline, the server was busy, or the key is wrong. When offline or busy, the SDK keeps the event and sends it later, for up to 7 days. Pass eventId: order.id so a retry from your own code never counts twice.
  • Revenue is counted twice. You also send the same purchase from your server with the Node SDK. Send it from one place.

Next steps