tigr-react-native
v0.1.5
Published
tigr analytics SDK for React Native & Expo — drop-in capture of app lifecycle, sessions and errors.
Downloads
648
Maintainers
Readme
tigr is a product analytics platform that turns raw events into clear, actionable insights. No charts to decode, no data team required — you install the SDK, and tigr does the rest. This package is the React Native / Expo client.
Install
npm install tigr-react-native @react-native-async-storage/async-storageAsyncStorage is a peer dependency (used to persist the visitor id across launches). Already using MMKV or another store? Pass your own adapter via the
storageoption — see Configuration.
Quick start
Wrap your app once with your project API key. Sessions, app lifecycle (foreground/background) and uncaught errors are captured automatically.
import { TigrProvider } from 'tigr-react-native'
export default function App() {
return (
<TigrProvider config={{ apiKey: 'tigr_pk_...' }}>
<RootNavigator />
</TigrProvider>
)
}Get your API key from your project's Settings at usetigr.app.
Tracking custom events
Grab the client in any component with useTigr():
import { useTigr } from 'tigr-react-native'
function UpgradeButton() {
const tigr = useTigr()
return (
<Button title="Upgrade" onPress={() => tigr.track('upgrade_pressed', { plan: 'pro' })} />
)
}Identifying users
const tigr = useTigr()
tigr.setUser(user.id, { name: user.name, email: user.email }) // on login
tigr.reset() // on logoutidentify() is the same as setUser() — use whichever reads better.
Screen tracking
There's no automatic pageview on mobile — emit a screen_view on navigation:
// React Navigation
<NavigationContainer
onStateChange={() => {
const name = navigationRef.getCurrentRoute()?.name
if (name) tigr.track('screen_view', { screen: name })
}}
>Configuration
<TigrProvider
config={{
apiKey: 'tigr_pk_...',
autoCapture: true, // true | false | { lifecycle, error }
flushInterval: 2000, // ms before a buffered batch is sent (default 2000)
batchSize: 20, // force a flush at this many events (default 20)
debug: false, // log every event + flush to the console
devMode: false, // when true, the SDK does nothing (use in development)
}}
>| Option | Type | Default | Description |
| --------------- | ------------------------------------- | ------- | ----------- |
| apiKey | string | — | Required. Your project API key. |
| host | string | tigr cloud | Where events are sent. Override for a self-hosted / local ingestion service. |
| autoCapture | boolean \| Partial<AutoCaptureOptions> | true | Toggle automatic signals individually or all at once. |
| storage | StorageAdapter | AsyncStorage | Persistence adapter for the visitor id (pass your own, e.g. an MMKV wrapper). |
| flushInterval | number | 2000 | Ms to wait after the first buffered event before sending. |
| batchSize | number | 20 | Flush immediately once the queue reaches this size. |
| debug | boolean | false | Console-log every event and flush. |
| devMode | boolean | false | When true the SDK does nothing — no capture, no network. Turn it on in development so your own activity doesn't pollute analytics. |
Auto-captured signals
lifecycle (app foreground/background → app_background) · error (uncaught JS
errors). Both on by default — turn either off:
<TigrProvider config={{ apiKey: 'tigr_pk_...', autoCapture: { error: false } }}>Local development
By default events go to tigr's hosted ingestion endpoint. A device or emulator
can't reach localhost, so for local testing point host at your machine's
LAN IP:
<TigrProvider config={{ apiKey: 'tigr_pk_...', host: 'http://192.168.1.3:4001' }}>Set host: '' (empty string) to run in console-only mode — events are
logged but nothing is sent. Omit host entirely to use the default tigr cloud.
API
useTigr() returns the client:
| Method | Description |
| ------ | ----------- |
| track(name, properties?) | Send a custom event. |
| identify(userId, traits?) | Tie events to a user. |
| setUser(userId, traits?) | Alias for identify. |
| reset() | Clear the current user (e.g. on logout). |
| flush() | Send everything queued right now. |
License
MIT © tigr
