Docs
SDK

Installation

Install and initialize the Layers SDK on Expo, React Native, iOS, Android, Flutter, Web, or Node — install the package, initialize with your App ID, and send your first event.

View as Markdown

Pick your platform below. Each guide installs the package, initializes the SDK with your App ID, and sends a first event. Replace YOUR_APP_ID with the value from your project's Events screen — see Get your App ID.

Prefer to let an AI do it? Prompt your coding agent bundles these same steps into a ready-to-paste prompt for Claude, Cursor, or any coding agent.

The SDK auto-tracks sessions and app-lifecycle events once initialized. The track() call in each snippet is just to prove the pipe works — see Tracking events for the events worth sending.

Install dependencies

npm install @layers/expo @layers/react-native expo-tracking-transparency expo-linking

Add the plugin to app.json

Add the Layers plugin to the plugins array under expo:

{
  "expo": {
    "plugins": [
      ["@layers/react-native/plugin", {
        "ios": { "attUsageDescription": "Helps show personalized content." },
        "enableDebug": true
      }]
    ]
  }
}

Initialize and track events

import { LayersReactNative } from '@layers/expo';

const layers = new LayersReactNative({
  appId: 'YOUR_APP_ID',
  enableDebug: __DEV__,
});

useEffect(() => {
  layers.init();
}, []);

// Track events
layers.track('purchase_success', { product_id: 'premium', revenue: 9.99 });

// Or wrap your tree with LayersProvider for React context:
// import { LayersProvider } from '@layers/expo';
// <LayersProvider client={layers}>...</LayersProvider>

Install dependencies

npm install @layers/react-native @react-native-community/netinfo @react-native-async-storage/async-storage
cd ios && pod install

Initialize and track events

import { LayersReactNative } from '@layers/react-native';

const layers = new LayersReactNative({
  appId: 'YOUR_APP_ID',
  enableDebug: __DEV__,
});

useEffect(() => {
  layers.init();
}, []);

layers.track('purchase_success', { product_id: 'premium', revenue: 9.99 });

Add the Swift Package

// Package.swift
.package(url: "https://github.com/layers/layers-sdk-ios.git", from: "1.0.0")

Initialize and track events

import Layers

Layers.initialize(config: LayersConfig(
    appId: "YOUR_APP_ID",
    environment: .production
))

Layers.track("purchase_success", properties: ["product_id": "premium", "revenue": 9.99])

Add the dependency

// build.gradle.kts
implementation("io.layers.sdk:layers-android:2.0.0-alpha.1")

Initialize and track events

// Application.onCreate()
LayersAndroid.configure(this) {
    appId = "YOUR_APP_ID"
    environment = Environment.PRODUCTION
}

LayersAndroid.track("purchase_success", mapOf("product_id" to "premium", "revenue" to 9.99))

Add the dependency

# pubspec.yaml
dependencies:
  layers_flutter: ^0.1.0

Initialize and track events

import 'package:layers_flutter/layers_flutter.dart';

await Layers.init(LayersConfig(
  appId: 'YOUR_APP_ID',
  environment: 'production',
));

await Layers.track('purchase_success', properties: {'product_id': 'premium', 'revenue': 9.99});

Install the package

npm install @layers/client

Initialize and track events

import { LayersClient } from '@layers/client';

const layers = new LayersClient({
  appId: 'YOUR_APP_ID',
  environment: 'production',
});
await layers.init();

await layers.track('purchase_success', { product_id: 'premium', revenue: 9.99 });

Install the package

npm install @layers/node

Initialize and track events

import { LayersNode } from '@layers/node';

const layers = new LayersNode({
  appId: 'YOUR_APP_ID',
});
await layers.init();

// Node takes a per-call distinctId as the first argument
await layers.track('user-123', 'purchase_success', { product_id: 'premium', revenue: 9.99 });

Node is server-side, so there's no ambient user. Every call takes the user's distinctId as its first argument — the client SDKs infer it from the active session instead.

Next

On this page