@statlark/react-native
v0.1.1
Published
Statlark Expo / React Native SDK — offline event queue, screen views, identify() and payment() with web-tracker parity.
Downloads
30
Maintainers
Readme
@statlark/react-native
Statlark analytics for Expo / React Native apps. Screen views, custom goals,
identify() and payment() — the same contract as the web tracker, so app and web
activity merge into one person (and one lifetime value) in your Statlark dashboard.
- Offline-durable — events persist and deliver when connectivity returns.
- Zero backend — just your site's public id; no API key.
- Revenue-aware — report in-app purchases with
payment().
Install
npx expo install @statlark/react-nativeOptional peers the SDK uses when present (all in a typical Expo app):
@react-native-async-storage/async-storage (persistence), expo-crypto (ids),
expo-device (phone/tablet), expo-router (auto screen tracking). Without
AsyncStorage the SDK still runs, but the visitor id + offline queue won't survive
an app restart.
Setup
Wrap your app once, at the root (e.g. app/_layout.tsx with expo-router):
import { StatlarkProvider } from "@statlark/react-native";
import { StatlarkScreenTracking } from "@statlark/react-native/expo-router";
export default function RootLayout() {
return (
<StatlarkProvider config={{ site: "sl_xxxxxxxx" }}>
<StatlarkScreenTracking />
{/* your navigator */}
</StatlarkProvider>
);
}<StatlarkScreenTracking /> auto-fires a screen view on every expo-router route
change. Not using expo-router? Omit it and call screen() yourself.
Usage
import { useStatlark } from "@statlark/react-native";
function Example() {
const statlark = useStatlark();
// A conversion goal (shows in your Goals report).
statlark.goal("signup", { plan: "pro" });
// Tie this device to a person — the key to the web→app funnel. Use the same
// user id / email you use on the web so the two merge into one profile.
statlark.identify({ user_id: user.id, user_email: user.email });
// An in-app purchase (App Store IAP). Report it from your purchase-success
// handler; provider defaults to "app_store".
statlark.payment({
amount: 9.99,
currency: "USD",
transaction_id: purchase.transactionId,
customer_email: user.email,
});
}Config
| Option | Default | Notes |
|---|---|---|
| site | — | Required. Your website public id (sl_…). |
| endpoint | https://collect.statlark.com | The hosted collector (stamps geo from the device IP). |
| storage | AsyncStorage → memory | Provide your own { getItem, setItem, removeItem } if you don't use AsyncStorage. |
| debug | false | Log each tracked event. |
| disablePayments | false | Make payment() a no-op. |
| sessionTimeoutMs | 1800000 (30 min) | Background time before a resume starts a new session. |
Notes
- All methods are fire-and-forget and never throw into your app.
- IAP revenue is client-reported (there's no App Store webhook), matching how mobile analytics generally works. Report it from a verified purchase callback.
- Device metadata is limited to the analytics buckets Statlark charts: iOS/Android and phone/tablet.
