React Native SDK
@cohorly/react-native is a standalone React Native client. It has no hard dependency on react-native or any storage library - it works out of the box with an in-memory store and upgrades to persistent storage when you inject one.
Install
pnpm add @cohorly/react-native
# recommended, for persistence across app restarts
pnpm add @react-native-async-storage/async-storageInitialize
Call init() once near app launch. Inject AsyncStorage so the distinct id, queued events, and super properties survive restarts.
import AsyncStorage from "@react-native-async-storage/async-storage";
import { init, track, identify, register, people } from "@cohorly/react-native";
init({
apiHost: "https://api.cohorly.com",
token: "YOUR_PROJECT_TOKEN",
storage: AsyncStorage, // omit to fall back to in-memory storage
});
register({ app_version: "1.2.0" });
track("Screen Viewed", { screen: "Home" });
identify("user_123");
people.set({ plan: "pro" });Without storage, the client uses InMemoryStorage (also exported), which works but loses the distinct id, queue, and super properties on every app restart.
API
| Member | Signature | Notes |
|---|---|---|
init | (options) => CohorlyClient | apiHost required; token, storage, flushInterval, flushAt, fetch, disabled optional. |
track | (event, properties?) => void | Queue an event. |
identify | (distinctId) => void | Local only - this package does not send an /alias call. |
reset | () => void | Clears identity, super properties, and un-flushed events. |
register / unregister | (props) / (key) | Super properties merged into every event. |
people.* | set / setOnce / increment / unset / deleteUser | Queued and sent to /engage. |
flush | () => Promise<void> | Manual flush. |
getDistinctId | () => string | Current distinct id. |
Note the People delete method here is people.deleteUser() (not delete), and identify() is local only - it does not emit an /alias request like the web SDK does.
Batching
Events are queued and flushed automatically every 5 seconds or once 20 events have accumulated - both configurable via flushInterval and flushAt. Queued events are persisted to storage, so nothing is lost if the app closes before a flush. You can also construct new CohorlyClient(options) directly for multiple instances or dependency injection.