Skip to main content
Glama
screen-tracking.md1.2 kB
--- title: Screen tracking for analytics description: Learn how to enable screen tracking for analytic when using Expo Router. hideTOC: true --- Unlike React Navigation, Expo Router always has access to a URL. This means screen tracking is as easy as the web. 1. Create a higher-order component that observes the currently selected URL 2. Track the URL in your analytics provider ```tsx app/_layout.tsx const pathname = usePathname(); const params = useGlobalSearchParams(); // Track the location in your analytics provider here. useEffect(() => { analytics.track({ pathname, params }); }, [pathname, params]); // Export all the children routes in the most basic way. return ; } ``` Now when the user changes routes, the analytics provider will be notified. ## Migrating from React Navigation React Navigation's [screen tracking guide](https://reactnavigation.org/docs/screen-tracking/) cannot make the same assumptions about the navigation state that Expo Router can. As a result, the implementation requires the use of `onReady` and `onStateChange` callbacks. Avoid using these methods if possible as the root `` is not directly exposed and allows cascading in Expo Router.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jaksm/expo-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server