Track events & screens
Triggers set in the Mobile app tab react to three things: an event, a screen and app launch. Your app reports the first two with track and screen. App launch needs no call.
Events and screen names stay on the device. track and screen exist to start surveys, not to collect analytics, and nothing they receive is uploaded.
Events
Section titled “Events”Call track where something happens that a survey could follow.
Responsly.shared.track("purchase_completed", properties: ["value": 49.9, "category": "books"])Responsly.track("purchase_completed", mapOf("value" to 49.9, "category" to "books"))Responsly.track('purchase_completed', { value: 49.9, category: 'books' })Responsly.track('purchase_completed', properties: {'value': 49.9, 'category': 'books'});ResponslySDK.Track("level_completed", new Dictionary<string, object> { { "level", 12 }, { "stars", 3 } });Each call does two things:
- Adds one to the count of that event name on this device.
- Checks the event triggers of every survey in the configuration.
An event trigger matches when all of these are true:
| Trigger setting | Rule |
|---|---|
| Event name | Equal to the name you pass. Case-sensitive: Purchase_Completed does not match purchase_completed. |
| From occurrence no. | The count of this event, including the current call, has reached the number. With 3, the third call and every later one match. |
| Property conditions | Every condition is true for the properties of this call. |
Things to know:
- The count is kept per install and survives restarts. It goes up on every call, whether or not the conditions match.
resetclears it. - Property values are strings, numbers, booleans or dates, the same types as user attributes. They are used for this one check and are not stored.
- A condition on a property you did not pass is false for “equals”, “contains” and the comparisons, and true for “does not equal”, “does not contain” and “does not exist”. The rules are in Targeting.
- If an event has no properties, pass an empty map.
Screens
Section titled “Screens”Call screen whenever the visible screen changes.
Responsly.shared.screen("Checkout")Responsly.screen("Checkout")Responsly.screen('Checkout')Responsly.screen('Checkout');ResponslySDK.Screen("MainMenu");Each call sets the current screen and checks screen triggers. A screen trigger matches when its name equals the name you pass (case-sensitive).
Report every screen, not only the ones that have a survey. When a survey has a delay, the SDK shows it only if the user is still on the screen that triggered it. It knows the user left because you reported the next screen.
App launch
Section titled “App launch”The app launch trigger needs no call. It is checked once per app process, as soon as the configuration is available after initialize. Returning from the background is not a launch.
Automatic screen tracking
Section titled “Automatic screen tracking”There is no automatic tracking on iOS. Report the screen where it appears.
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) Responsly.shared.screen("Checkout")}CheckoutView() .onAppear { Responsly.shared.screen("Checkout") }There is no automatic tracking on Android. Report the screen where it appears.
override fun onResume() { super.onResume() Responsly.screen("Checkout")}navController.addOnDestinationChangedListener { _, destination, _ -> destination.route?.let { Responsly.screen(it) }}React Navigation. createNavigationTracker reports the active route name every time it changes. Pass it the navigation ref and connect its two handlers to NavigationContainer.
import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native'import { createNavigationTracker } from '@responsly/react-native-sdk'
const navigationRef = createNavigationContainerRef()const tracker = createNavigationTracker(navigationRef)
export default function App() { return ( <NavigationContainer ref={navigationRef} onReady={tracker.onReady} onStateChange={tracker.onStateChange} > {/* navigators */} </NavigationContainer> )}The screen name is the route name, for example Checkout for <Stack.Screen name="Checkout" … />.
A single component. useResponslyScreen(name) calls screen(name) when the component mounts and whenever name changes.
import { useResponslyScreen } from '@responsly/react-native-sdk'
function CheckoutScreen() { useResponslyScreen('Checkout') return <CheckoutForm />}Expo Router. There is no NavigationContainer to attach to. Feed the current path to the hook in the root layout. Screen names are then paths such as /checkout.
import { Stack, usePathname } from 'expo-router'import { useResponslyScreen } from '@responsly/react-native-sdk'
export default function RootLayout() { useResponslyScreen(usePathname()) return <Stack />}ResponslyNavigatorObserver calls screen with the route’s settings.name on push, pop and replace, so the current screen stays correct when the user goes back.
MaterialApp( navigatorObservers: [ResponslyNavigatorObserver()], routes: { '/': (context) => const HomePage(), '/checkout': (context) => const CheckoutPage(), },);Routes without a name are skipped. Name the ones you push by hand:
Navigator.of(context).push( MaterialPageRoute( settings: const RouteSettings(name: 'Checkout'), builder: (context) => const CheckoutPage(), ),);Router packages accept the same observer, for example GoRouter(observers: [ResponslyNavigatorObserver()], …). The screen name is whatever your router sets as settings.name. Run once with the debug log level to see the names it produces.
There is no navigation stack to observe. Report scenes, and call Screen from your own UI code for menus and panels.
// needs: using UnityEngine.SceneManagement;SceneManager.sceneLoaded += (scene, mode) => ResponslySDK.Screen(scene.name);Timing
Section titled “Timing”trackandscreenare safe beforeinitializeand from any thread.- Calls made before the configuration has been downloaded are queued and checked, in order, once it arrives. The queue holds 50 calls; older ones are dropped. Event counts go up immediately either way.
- One call can match several surveys. The SDK shows the first eligible one and reports the others to
surveyNotShown. Only one survey is on screen at a time. - A matching trigger is the start, not the end: audience, frequency, schedule and sampling are checked next. See Targeting.
Reuse your analytics events
Section titled “Reuse your analytics events”If the app already calls an analytics SDK, send the same events to Responsly from the same helper. See Integrations.