# 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

URL: https://docs.lemuai.com/sdks/overview

**Note:** **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](https://docs.lemuai.com/sdks/javascript#add-the-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](https://docs.lemuai.com/sdks/javascript) |
| JavaScript with a bundler | npm `@lemuai/analytics` | Website | [Website and JavaScript](https://docs.lemuai.com/sdks/javascript) |
| React and Next.js | npm `@lemuai/react` | Website | [React and Next.js](https://docs.lemuai.com/sdks/react) |
| React Native and Expo | npm `@lemuai/react-native` | App | [React Native and Expo](https://docs.lemuai.com/sdks/react-native) |
| Android (Kotlin, Java) | Maven Central `com.lemuai:analytics` | App | [Android](https://docs.lemuai.com/sdks/android) |
| iOS and tvOS (Swift, Objective-C) | Swift Package Manager or CocoaPods `LemuAnalytics` | App | [iOS](https://docs.lemuai.com/sdks/ios) |
| Flutter (Android, iOS, web, desktop) | pub.dev `lemu_analytics` | App | [Flutter](https://docs.lemuai.com/sdks/flutter) |

## Get a write key

Every SDK needs the write key of a [tracking source](https://docs.lemuai.com/website-pixel/overview).

**Step: 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.

**Step: Name it**

Give it a **Name**, for example "Main store" or "Android and iOS app". You can list the [Allowed sites](https://docs.lemuai.com/website-pixel/overview#allowed-sites) or [Allowed apps](https://docs.lemuai.com/website-pixel/overview#allowed-apps) now or later. Then click **Create**.

**Step: 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](https://docs.lemuai.com/sdks/events).

## 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](https://docs.lemuai.com/website-pixel/standard-events#conversion-events) for what Lemu does when a field is missing, and [send purchases from your server too](https://docs.lemuai.com/website-pixel/standard-events#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](https://docs.lemuai.com/website-pixel/overview#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) until `setConsent(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](https://docs.lemuai.com/website-pixel/overview#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](https://docs.lemuai.com/sdks/android#google-play-data-safety) and [App Store privacy](https://docs.lemuai.com/sdks/ios#app-store-privacy).

## Check that events arrive

**Step: Turn on debug mode**

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

**Step: Send an event**

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

**Step: 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](https://docs.lemuai.com/website-pixel/overview#recent-events).

Events also appear in the [Event Log](https://docs.lemuai.com/event-log/overview).

## Next steps

  - [Website and JavaScript](https://docs.lemuai.com/sdks/javascript): The snippet for any website, or the npm package
  - [React and Next.js](https://docs.lemuai.com/sdks/react): A provider, a hook and page tracking
  - [React Native and Expo](https://docs.lemuai.com/sdks/react-native): Events, screens, installs and deep links
  - [Android](https://docs.lemuai.com/sdks/android): Kotlin and Java, with the Play install referrer
  - [iOS](https://docs.lemuai.com/sdks/ios): Swift, SwiftUI, UIKit and Objective-C
  - [Flutter](https://docs.lemuai.com/sdks/flutter): One SDK for mobile, web and desktop
  - [Event reference](https://docs.lemuai.com/sdks/events): Every event name, constant and parameter
  - [Standard and conversion events](https://docs.lemuai.com/website-pixel/standard-events): The fields orders need and how ROI is calculated
