Settings · 6 min read
SDKs
Send events, purchases and known users to Lemu from your website, JavaScript and React apps, and your Android, iOS, Flutter and React Native apps
Setup required: the SDK packages (@lemuai/analytics, @lemuai/react, @lemuai/react-native, com.lemuai:analytics, LemuAnalytics and lemu_analytics) are rolling out. If a package isn't available yet, contact LemuAI support for access. The website snippet needs no package.
The Lemu SDKs send what people do on your website and in your apps to Lemu: page and screen views, Meta's standard events such as AddToCart and Purchase, and identify for people you know. Lemu uses these events for contact activity and segments, to start journeys, and to calculate the revenue and ROI of your journeys and campaigns.
Pick your SDK#
| Platform | Package | Source kind | Guide |
|---|---|---|---|
| Any website | The snippet from your source | Website | Website and JavaScript |
| JavaScript with a bundler | npm @lemuai/analytics | Website | Website and JavaScript |
| React and Next.js | npm @lemuai/react | Website | React and Next.js |
| React Native and Expo | npm @lemuai/react-native | App | React Native and Expo |
| Android (Kotlin, Java) | Maven Central com.lemuai:analytics | App | Android |
| iOS and tvOS (Swift, Objective-C) | Swift Package Manager or CocoaPods LemuAnalytics | App | iOS |
| Flutter (Android, iOS, web, desktop) | pub.dev lemu_analytics | App | Flutter |
Get a write key#
Every SDK needs the write key of a tracking source.
Add a source
In Lemu, open Settings → Tracking Sources. Under Add a tracking source, choose Website for a website or a JavaScript, React or Next.js app. Choose App for an Android, iOS, Flutter or React Native app.
Name it
Give it a Name, for example "Main store" or "Android and iOS app". You can list the Allowed sites or Allowed apps now or later. Then click Create.
Copy the write key
On the new source, under Set up, copy the write key. It starts with
lpk_.
Under Set up, the source also shows install and setup code for each platform with your key filled in: Any website and React / Next.js on a website source, and Android, iOS, Flutter and React Native on an app source.
The write key is public by design and safe to ship in your site or app: it can only send events, never read anything. One app source can serve the same app on every platform, for example your Android and iOS builds. Create a separate source for each environment, such as staging, so test events stay apart.
What every SDK does#
Every SDK has the same calls. Each guide shows them in that platform's language.
| Call | What it does |
|---|---|
track(event, properties) | Sends any event. Use Meta's standard name, such as AddToCart, when one fits |
purchase(...) | Sends a Purchase with value, currency and your order id, straight away |
identify(userId, traits) | Ties the visitor or install to your own user id and sends their contact details |
reset() | Call on logout: starts a new anonymous id and clears the user id |
page() or screen(name) | A page view on a website, a screen view in an app |
setConsent(granted) | Starts or stops sending when the SDK waits for consent |
optOut() and optIn() | Turns all tracking off or back on, remembered on the device |
flush() | Sends queued events now |
Every SDK has constants for the standard event names (LemuEvent), so the names can't be misspelled. See the event reference.
Purchases, revenue and ROI#
Send every order with purchase, with three fields:
value: the order total, in major units (1499.5is ₹1,499.50).currency: an ISO 4217 code such asINR.- the order id (
order_idin JavaScript,orderIdon Android, iOS and Flutter): the same id your store and backend use.
Lemu counts one conversion per order id, however many times the order is reported: by your app, your website, Shopify or your server. Without it, every report counts as a separate sale. See Conversion events for what Lemu does when a field is missing, and send purchases from your server too for the most reliable numbers.
Known users#
Call identify when someone signs up or logs in, with your own user id and their contact details (email, phone in international format such as +919876543210, first_name, last_name). The user id is sent with every later event until reset.
- An
identifywith an email or a phone finds the matching contact, or creates one. - An
identifywith only your user id links to an existing contact with that id. It never creates one. - Before
identify, a visitor or install is anonymous and isn't a contact. Once they identify, their earlier anonymous activity shows up on the contact.
Contact details belong in identify only. Lemu removes keys such as email, phone and address from event properties.
To let tracked actions from identified people start journeys, switch on Let identified visitors' tracked actions trigger journeys on the source. See Trigger journeys.
Consent and opt-out#
If you need consent before tracking, for example under GDPR or the DPDP Act, start the SDK with requireConsent and call setConsent(true) once the person agrees.
- Until consent, nothing is sent and nothing is stored on the device, not even the anonymous id. Up to 50 events wait in memory and are sent once consent is given.
setConsent(false)discards the waiting and queued events. A granted consent is remembered (in the browser, across visits; in an app, across launches) untilsetConsent(false).optOut()stops all tracking and clears the queue, and is remembered.optIn()turns tracking back on.
How events are sent#
| Websites | Apps | |
|---|---|---|
| When | Every second or every 10 events, and when the page is hidden | Every 30 seconds or every 20 events, when the app goes to the background, and right after a purchase |
| If sending fails | Retried with increasing waits, up to 5 minutes apart, while the page is open | Kept on the device, also across restarts, and retried with increasing waits, up to 5 minutes apart, for up to 20 hours |
| Queue | Up to 1,000 events, in memory | Up to 1,000 events, for up to 7 days. When it's full, the oldest event that isn't a purchase is dropped first |
Each request carries up to 50 events. The same event received twice within 24 hours is recorded once, so retries never double count. See Limits and duplicates.
The SDKs never throw into your code. A bad argument, such as an empty event name, is ignored and logged in debug mode.
Privacy#
The SDKs collect a random anonymous id for each browser or app install, the events and properties your code sends, the user id and traits you pass to identify, and basic app and device details such as the app version, OS version, device model, locale and time zone. They collect no advertising ids (IDFA, GAID) and no hardware ids.
For app store forms, see Google Play data safety and App Store privacy.
Check that events arrive#
Turn on debug mode
Start the SDK with
debugon. It logs every call, request and response.Send an event
Open your site or app and do something you track, or call
flush()to send straight away.Look in Lemu
In Settings → Tracking Sources, the source shows when the last event arrived. Under Recent events, click Show recent events to see the last 50 events from the past hour as Lemu stored them, then Refresh for new ones. See Recent events.
Events also appear in the Event Log.
Next steps#
Website and JavaScript
The snippet for any website, or the npm package
React and Next.js
A provider, a hook and page tracking
React Native and Expo
Events, screens, installs and deep links
Android
Kotlin and Java, with the Play install referrer
iOS
Swift, SwiftUI, UIKit and Objective-C
Flutter
One SDK for mobile, web and desktop
Event reference
Every event name, constant and parameter
Standard and conversion events
The fields orders need and how ROI is calculated
Was this page helpful?
Docs