Events and revenue in Flutter

After this page, purchases in your Flutter 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
  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 package installed and started (Install & set up)
Works on
Android, iPhone

1. Know what's already reported

Every link open is reported once, automatically: verified links from chat apps, browser hand-offs, the first open after a Play install, iPhone install matches, and your own https links (host and path only). Opens that can't be sent are saved and retried for up to 7 days.

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

2. Record a purchase

Dart
await links.trackEvent('purchase', value: 49.99, currency: 'USD');

trackEvent returns true when the event was accepted. 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. An event that can't be sent (offline, server busy) is kept and sent later, for up to 7 days.

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, 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. (Flutter SDK 0.10.7 or later.)

Dart
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.
  • 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.
  • Revenue is counted twice. The same purchase is also sent from your server. Send it from one place.

Next steps