Skip to content

Analytics

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

Raw

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 property page with the Mobile type and the Flutter SDK selected
Create property page with the Mobile type and the Flutter SDK selected

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.

  1. In your project, open Apps and click Add app.
  2. Choose your platform, such as Android, Apple, Flutter, or React Native.
  3. 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

Bash
flutter pub add appwrite

Start tracking

Install tracking screen confirming that a screen_view event was received from the app
Install tracking screen confirming that a screen_view event was received from the app

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

Screens card on a Mobile property with the top screens, next to the Humans vs bots card
Screens card on a Mobile property with the top screens, next to the Humans vs bots card

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.

Dart
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

Push notifications card with pushes received and opened for each message, next to the Installs card
Push notifications card with pushes received and opened for each message, next to the Installs card

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

EventWhen it's sentExtra data
first_openThe first time the app runs after an installNone
app_updatedThe first time the app runs after an updatepreviousVersion and version props
app_backgroundedThe app moves to the backgroundThe seconds the app was in the foreground
app_foregroundedThe app returns to the foregroundNone
screen_viewA 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

Technology card on the Platforms tab, splitting traffic between iOS and Android
Technology card on the Platforms tab, splitting traffic between iOS and Android

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.