Track a mobile app
Add Appwrite Analytics to an Android, Apple, Flutter, or React Native app. Track installs, updates, screen views, push notifications, time in the app, and your own events.
5 min read
The Android, Apple, Flutter, and React Native SDKs each include a Tracking class. One call to start() records installs, updates, and when the app goes to the background and comes back. Connect Tracking to your navigation to record screen views, and call it from your push handler to see which notifications people open.
Before you start

Create a Mobile property and copy its property ID, which the Console shows next to the property name.
Register the app in the same project. The SDK sends your app's platform and package name or bundle ID with every request, and Appwrite rejects events from a platform with no app in the project with a 403 general_unknown_origin error.
- In your project, open Apps and click Add app.
- Choose your platform, such as Android, Apple, Flutter, or React Native.
- Enter the package name or bundle ID, and finish the wizard.
Register each target separately, such as Android and iOS. To accept events only from your own app, also add its origin to the property's allowed origins.
Install the SDK
flutter pub add appwriteAdd the SDK to app/build.gradle.kts.
dependencies { implementation("io.appwrite:sdk-for-android:31.4.0")}In Xcode, select File > Add Package Dependencies, enter the package URL, and add the Appwrite library to your app target.
https://github.com/appwrite/sdk-for-applenpx expo install react-native-appwrite expo-file-system react-native-url-polyfillImport react-native-url-polyfill/auto once, before any other SDK code runs.
Start tracking

Create one Tracking instance for the whole app with your endpoint, project ID, and property ID, and call start() when the app launches. On Android, create it in your Application class and register that class in AndroidManifest.xml with android:name=".MyApp" on the <application> element. In React Native, pass the package name or bundle ID registered under Apps to setPlatform().
import 'package:appwrite/appwrite.dart';
final client = Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') .setProject('<PROJECT_ID>');
final tracking = Tracking(Analytics(client), '<PROPERTY_ID>');
void main() { tracking.start(); runApp(const MyApp());}start() sends first_open after an install and app_updated after an update, and turns on the lifecycle events that measure time in the app. See Install, lifecycle, and screen events. Run the app. Within a few seconds, the install page shows Event received, and the events appear on the property's dashboard.
Track screen views

Send a screen_view each time a screen opens. Connect Tracking to your navigation, as shown below, so new screens are tracked with no extra code.
MaterialApp( navigatorObservers: [TrackingObserver(tracking)], routes: { '/': (context) => const HomeScreen(), '/product': (context) => const ProductScreen(), },);Each screen view records the screen name as the page path, so the Screens card shows product as /product. A screen_view counts as a view, the same as a pageview on the web. Screen views add to Screen views and Screens/session, and the first and last views of a session set its entry and exit screens.
To track a screen that isn't part of your navigation, such as a tab or a sheet, call screenView() directly.
In a React Native app that uses Expo Router, call tracking.screenView(pathname) when the value of usePathname() changes.
Flutter route names
TrackingObserver reads each route's RouteSettings.name and skips routes without a name, such as most dialogs and bottom sheets. Give each MaterialPageRoute a name.
Navigator.push( context, MaterialPageRoute( settings: const RouteSettings(name: '/settings'), builder: (context) => const SettingsScreen(), ),);To name screens another way, pass a nameExtractor to TrackingObserver. Return null from it to skip a route.
Track push notifications

Call pushReceived() when a notification arrives and pushOpened() when someone taps it. Pass the Appwrite Messaging message ID, and the Push notifications card lists each message with how many were received and opened.
tracking.pushReceived(messageId: '<MESSAGE_ID>');tracking.pushOpened(messageId: '<MESSAGE_ID>');For a push sent from another service, pass campaign instead of messageId.
push_opened starts a session, but push_received doesn't, because a push can arrive while the app is closed. On iOS, and on Android while the app isn't running, notification code may not run when a push arrives, so Received can be lower than the number of pushes delivered.
Track custom events
Send your own events with the screen they belong to as url, so each event is recorded under that path.
tracking.event( 'add_to_cart', url: '/product', props: {'product': 'canvas-backpack'},);Prop values can be any type and are stored as text. For naming and limits, see Track custom events.
Install, lifecycle, and screen events
| Event | When it's sent | Extra data |
|---|---|---|
first_open | The first time the app runs after an install | None |
app_updated | The first time the app runs after an update | previousVersion and version props |
app_backgrounded | The app moves to the background | The seconds the app was in the foreground |
app_foregrounded | The app returns to the foreground | None |
screen_view | A screen opens, from your navigation or screenView() | screen prop, and an optional screenClass prop |
To spot installs and updates, each SDK keeps a small marker with the app's version on the device. It holds no identifier. Reinstalling the app, or clearing its data, counts as a new install.
Event URLs

Analytics records every event against a URL. In an app, Tracking uses app:// and the platform name, such as app://android or app://ios, so a screen view of product on Android is recorded as app://android/product. The platform becomes the hostname, which the Platforms tab of the Technology card uses to split your traffic. Events without a screen, such as first_open and the lifecycle events, are recorded under /.
To record events under your own base URL, pass url to the Tracking constructor. In React Native, pass it in the options object, such as { url: 'https://example.com' }. On Flutter web and React Native web, Tracking uses the page's origin.
Errors
Tracking never throws and never interrupts your app. When an event fails, it's dropped, except first_open and app_updated, which are sent again on the next launch. To check your setup, call createEvent on the Analytics service once and print the error.
A 403 general_unknown_origin error names the package or bundle ID that needs an app under Apps. A 404 analytics_property_not_found error means the property ID is wrong or Tracking is off in the property's settings.
Was this page helpful?
Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.