LemuAIDocs

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

Open in ChatGPTOpen in ClaudeMarkdown

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#

PlatformPackageSource kindGuide
Any websiteThe snippet from your sourceWebsiteWebsite and JavaScript
JavaScript with a bundlernpm @lemuai/analyticsWebsiteWebsite and JavaScript
React and Next.jsnpm @lemuai/reactWebsiteReact and Next.js
React Native and Exponpm @lemuai/react-nativeAppReact Native and Expo
Android (Kotlin, Java)Maven Central com.lemuai:analyticsAppAndroid
iOS and tvOS (Swift, Objective-C)Swift Package Manager or CocoaPods LemuAnalyticsAppiOS
Flutter (Android, iOS, web, desktop)pub.dev lemu_analyticsAppFlutter

Get a write key#

Every SDK needs the write key of a tracking source.

  1. 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.

  2. 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.

  3. 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.

CallWhat 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.5 is ₹1,499.50).
  • currency: an ISO 4217 code such as INR.
  • the order id (order_id in JavaScript, orderId on 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 identify with an email or a phone finds the matching contact, or creates one.
  • An identify with 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.

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) until setConsent(false).
  • optOut() stops all tracking and clears the queue, and is remembered. optIn() turns tracking back on.

How events are sent#

WebsitesApps
WhenEvery second or every 10 events, and when the page is hiddenEvery 30 seconds or every 20 events, when the app goes to the background, and right after a purchase
If sending failsRetried with increasing waits, up to 5 minutes apart, while the page is openKept on the device, also across restarts, and retried with increasing waits, up to 5 minutes apart, for up to 20 hours
QueueUp to 1,000 events, in memoryUp 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#

  1. Turn on debug mode

    Start the SDK with debug on. It logs every call, request and response.

  2. Send an event

    Open your site or app and do something you track, or call flush() to send straight away.

  3. 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#