/**
* Automatic screen tracking for React Navigation (v5+ / v6+).
*
* The simplest integration — just spread onto your NavigationContainer:
*
* ```tsx
* import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
* import { datalyrScreenTracking } from '@datalyr/react-native';
*
* const navigationRef = useNavigationContainerRef();
* const screenTracking = datalyrScreenTracking(navigationRef);
*
*
* ```
*
* Note: If you enable automatic screen tracking, avoid also calling
* `Datalyr.screen()` / `datalyr.screen()` manually for the same screens,
* as this will produce duplicate events.
*
* For Expo Router (file-based routing), automatic tracking is not needed.
* Use the `datalyr.screen()` method in your layout files instead.
*/
/** Minimal subset of React Navigation's NavigationContainerRef that we need. */
export interface NavigationContainerRef {
getCurrentRoute(): {
name: string;
params?: Record;
} | undefined;
}
export interface ScreenTrackingConfig {
/**
* Transform the route name before tracking.
* Useful for cleaning up or grouping screen names.
* @example (name) => name.replace('Screen', '')
*/
transformScreenName?: (routeName: string) => string;
/**
* Filter which screens should be tracked.
* Return false to skip tracking for a given screen.
* @example (name) => !['Loading', 'Splash'].includes(name)
*/
shouldTrackScreen?: (routeName: string) => boolean;
/**
* Extract additional properties from the route to include in the screen event.
* @example (name, params) => ({ product_id: params?.productId })
*/
extractProperties?: (routeName: string, params?: Record) => Record;
}
/**
* Create `onReady` and `onStateChange` callbacks that automatically
* fire screen events through the Datalyr SDK whenever the active
* React Navigation route changes.
*
* @param navigationRef A React Navigation `NavigationContainerRef`
* (from `useNavigationContainerRef()` or
* `createNavigationContainerRef()`).
* @param trackScreen The function that records a screen event.
* Pass `datalyr.screen.bind(datalyr)` or the
* Datalyr static class's `Datalyr.screen`.
* If omitted, the default singleton is used.
* @param config Optional filtering / transform config.
*/
export declare function createScreenTrackingListeners(navigationRef: NavigationContainerRef, trackScreen: (screenName: string, properties?: Record) => Promise, config?: ScreenTrackingConfig): {
onReady: () => void;
onStateChange: () => void;
};
/**
* Auto-wire screen tracking to the default Datalyr singleton.
* This is the recommended API for most users.
*
* ```tsx
* const navigationRef = useNavigationContainerRef();
* const screenTracking = datalyrScreenTracking(navigationRef);
*
*
* ```
*
* @param navigationRef React Navigation container ref
* @param config Optional screen name transforms and filters
*/
export declare function datalyrScreenTracking(navigationRef: NavigationContainerRef, config?: ScreenTrackingConfig): {
onReady: () => void;
onStateChange: () => void;
};