Track which screens people view, automatically with Expo Router or with one call anywhere else.
Enable analytics: { screens: true } first (see Analytics setup). Views feed the dashboard's Screen Usage card.
Expo Router
Add the hook to your root layout. It tracks every route change: pushes, replaces, back gestures and deep links.
import { Slot } from "expo-router";
import { useNativeNotifyScreenTracking } from "native-notify";
export default function RootLayout() {
useNativeNotifyScreenTracking();
return <Slot />;
}
Any other navigator
Call trackScreen(name) wherever you know the active screen:
import { trackScreen } from "native-notify";
trackScreen("Home");
trackScreen("Settings");
trackScreen(`/products/${productId}`);
With React Navigation, call it from onReady and onStateChange:
import { useRef } from "react";
import { NavigationContainer, useNavigationContainerRef } from "@react-navigation/native";
import { trackScreen } from "native-notify";
export default function App() {
const navigationRef = useNavigationContainerRef();
const routeNameRef = useRef();
return (
<NavigationContainer
ref={navigationRef}
onReady={() => {
// The first screen: onStateChange does not fire for it.
routeNameRef.current = navigationRef.getCurrentRoute()?.name;
if (routeNameRef.current) trackScreen(routeNameRef.current);
}}
onStateChange={() => {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.getCurrentRoute()?.name;
if (currentRouteName && previousRouteName !== currentRouteName) {
trackScreen(currentRouteName);
}
routeNameRef.current = currentRouteName;
}}
>
{/* your navigators */}
</NavigationContainer>
);
}
For any other navigator, useNativeNotifyScreenTracking() takes a reader function and reports whenever the name it returns changes on a re-render (native-notify v5.2+):
useNativeNotifyScreenTracking(() => currentRouteName);
Screen names
Names are trimmed to 120 characters and become the ranking rows, so keep them short and stable. If the list grows long, use /products/[id] rather than /products/123.
How reporting works
- Views are batched and sent about two seconds later, or at once when a tracked session ends (with
sessionson). - The same screen twice in a row counts once.
- Unique views count distinct devices: the stable
deviceIdwhen it's on, otherwise the Expo push token. - Reporting is best-effort and never blocks navigation.