Events and revenue on Android

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

On this page 6
  1. 1. Know what's already reported
  2. 2. Record a purchase (off the main thread)
  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 client created and started (Install & set up)
Works on
Android

1. Know what's already reported

Every link open is reported once, joined to its tap where possible: verified links from chat apps, browser hand-offs, the first open after a Play install, and your own https links (host and path only). Reports that can't be sent are saved under storage and retried on the next start, whenever onAppState(ACTIVE) is called, and after any report that gets through, for up to 7 days (100 at most).

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

2. Record a purchase (off the main thread)

trackEvent is a blocking call that returns true when the event was accepted:

Kotlin
Thread { links.trackEvent("purchase", value = 49.99, currency = "USD") }.start()

Use any event name; value, currency, linkId, clickId and eventId are optional. Pass your order id as eventId (eventId = order.id): Strait counts each one once, so a retry never counts twice. Left out, the SDK makes one.

You should see: the purchase and its revenue at the bottom of the funnel in Analytics.

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, or an open from a verified short link. 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. (Android SDK 0.10.5 or later.)

Kotlin
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 links.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

  • NetworkOnMainThreadException. trackEvent ran on the main thread. Call it from a background thread or coroutine.
  • The purchase shows as direct. The last link open was more than 7 days ago, or the app was opened without a link since.
  • trackEvent returns 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.

Next steps