Screens and events
What counts as a screen view, how to rename screens, and the calls for events, signed-in people and what opened the app.
The React Native package counts screens on its own once Analytics is in place. This page covers what counts as a view, how to rename screens, and the calls for events, signed-in people and what opened the app. Swift apps has the same calls for the Swift package.
What counts as a screen view
A view counts when the focused screen changes. The same screen twice in a row counts once, and going back to a screen counts it again, as the back button does on the web. Coming back from the background counts no view.
- Expo Router sends the route's pattern, such as
/product/[id], never the filled address, so IDs never leave the phone. Groups such as(tabs)drop out of the path. - React Navigation sends the focused screen's name, never its params. Tabs, stacks, drawers and modals all count.
- Anything else sends the name you give each screen.
Rename screens
With React Navigation, pass screenName to send another name. It gets the focused route.
<Analytics site="YOUR_SITE_ID" app="com.acme.app" screenName={(route) => 'Shop/' + route.name} />If Analytics sits outside NavigationContainer, pass the container's ref as container.
Name screens yourself
Without Expo Router or React Navigation, call useScreen in each screen component. It sends a view when the screen mounts.
import { useScreen } from '@ultanimus/react-native'
function Checkout() {
useScreen('Checkout')
return <CheckoutForm />
}screen('Checkout') does the same from outside a component, such as a navigation listener.
Send an event
import { track } from '@ultanimus/react-native'
track('add_to_cart', { sku: 'lamp', quantity: 2 })Property values are strings, numbers or booleans. Custom events covers naming and properties, and the same events work in goals and funnels.
Signed-in users
Pass your own ID for the signed-in person, or null when nobody is. They then count as one visitor across days and devices, on the web and in the app.
<Analytics site="YOUR_SITE_ID" user={session?.userId ?? null} />Or call identify(account.id) where your app learns who signed in, and identify(null) on sign out. Use an ID from your database, never an email address or a name. Signed-in users explains what is stored.
What opened the app
A link that opens the app with utm_source, utm_medium, utm_campaign or ref in its address names the visit's source, as it does on a web page. For anything else that opens the app, such as a notification, call opened before the next screen shows.
import { opened } from '@ultanimus/react-native'
opened({ source: 'push', campaign: 'black-friday' })A visit with neither shows as Direct. Installs from the App Store and Google Play carry no source yet.