Docs
SDK

Installation

Install and initialize the Layers SDK on Expo, React Native, iOS, Android, Flutter, Unity, 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 your project's real value — 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/expo", {
        "ios": { "attUsageDescription": "Helps show personalized content." }
      }]
    ]
  }
}

Initialize and track events

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

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

export default function App() {
  useEffect(() => {
    layers.init();
  }, []);

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

  return <YourApp />;
}

// Or wrap your tree with LayersProvider, which creates and initializes
// the client for you — pass the config, not an instance:
// import { LayersProvider } from '@layers/expo';
// <LayersProvider config={{ appId: 'YOUR_APP_ID', environment: 'production' }}>...</LayersProvider>

Install dependencies

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

Add the ATT usage description on iOS

Before calling layers.requestTrackingPermission(), add this key to the app target's Info.plist:

<key>NSUserTrackingUsageDescription</key>
<string>Explain why your app requests permission to use advertising identifiers.</string>

Initialize and track events

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

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

export default function App() {
  useEffect(() => {
    layers.init();
  }, []);

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

  return <YourApp />;
}

Add the Swift Package

// Package.swift
.package(url: "https://github.com/layers/layers-sdk-ios.git", from: "3.3.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("com.layers.sdk:layers-android:3.3.0")

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: ^3.3.0

Initialize and track events

import 'package:layers_flutter/layers_flutter.dart';

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

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

Add the package

The Unity SDK ships as a UPM package. Add it to Packages/manifest.json:

{
  "dependencies": {
    "com.layers.analytics": "https://github.com/layers/layers-sdk-unity.git#v3.3.0"
  }
}

Or in the Unity Editor: Window → Package Manager → + → Add package from git URL, then paste https://github.com/layers/layers-sdk-unity.git#v3.3.0.

Initialize and track events

Initialize once, early, from a bootstrap MonoBehaviour in your first scene:

using System.Collections.Generic;
using Layers.Unity;
using UnityEngine;

public class LayersBootstrap : MonoBehaviour
{
    void Awake()
    {
        LayersSDK.Initialize(new LayersConfig
        {
            AppId = "YOUR_APP_ID",
            Environment = LayersEnvironment.Production,
        });
    }
}
LayersSDK.Track("purchase_success", new Dictionary<string, object>
{
    ["product_id"] = "premium",
    ["revenue"] = 9.99,
});

Configure the iOS and Android build

Create a settings asset with Assets → Create → Layers → Settings to set the ATT usage description, SKAdNetwork IDs, URL schemes, and associated domains. The included post-build processors write those into Info.plist, link the required iOS frameworks, and add the Android deep-link intent filters at build time.

Unity targets iOS and Android, on Unity 2021.3 LTS or later (iOS 13+, Android API 21+). WebGL is not supported: for a web build, load the @layers/client web SDK from the hosting page instead (see the Web tab).

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();

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',
  environment: 'production',
});
await layers.init();

// Node takes a per-call distinctId as the first argument
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