Introducing a new way to review your PRs.

Read the announcement

appwrite / sdk-for-react-native

[READ ONLY] Official Appwrite React Native SDK 💙 ⚛︎

View on GitHub

24 documents · Updated Nov 18, 2026

docs / analytics-tracking

Analytics tracking

Analytics tracking gives an application one SDK path to record views and product events against an analytics property. Applications can send events directly with Analytics.createEvent or use Tracking to add app lifecycle, screen, install, update, and push telemetry while keeping tracking failures separate from the host app. This page is part of Application and integration services; Application management and installations covers app resources, while OAuth, analytics, and push integration covers the related service APIs.

Event submission

The Analytics service is the low-level event interface. It sends a required property, event name, and URL or screen identifier, plus optional context that helps analytics interpret the event.

The object form is the preferred integration shape:

await analytics.createEvent({
    propertyId: 'property-id',
    name: 'checkout_completed',
    url: 'app://ios/checkout',
    engagementTime: 12,
    props: ['plan', 'pro'],
    interactive: true,
});

The main inputs are:

InputPurpose
propertyIdSelects the analytics property that receives the event.
nameIdentifies the event. pageview and screen_view count as views; other names count as custom events.
urlIdentifies the page or app screen.
domain, referrer, screenWidth, sessionHash, scrollDepthAdds page, device, session, or engagement context when available.
engagementTimeReports engagement time in seconds.
propsSends custom string values as alternating key and value entries.
userId, ip, userAgentOverrides derived visitor data. These fields require API-key authentication with the analytics.write scope.
interactiveMarks whether the event is a user interaction that ends a bounce.

propertyId, name, and url are required. The service returns a promise for the accepted event response. Missing required inputs or a rejected request raise an AppwriteException, so direct callers can handle the failure as part of their request flow.

References: src/…/analytics.ts• L5-45 src/…/analytics.ts• L175-272

Automatic tracking

The Tracking helper is the application-facing layer for common telemetry. It receives an Analytics service and a property ID, then supplies a base URL for events that do not provide their own URL.

start() enables app lifecycle tracking and checks install state. It reports first_open once for a new native install and reports app_updated when the saved app version changes. These install events are not sent on the web. A failed install or update event remains pending for a later app start, while a send failure is logged instead of being passed to the host app.

The default lifecycle events are:

EventMeaning
app_foregroundedThe app becomes active after being in the background.
app_backgroundedThe app enters the background. Its engagementTime reports foreground time since the last resume.
first_openThe first recorded launch of a native installation.
app_updatedThe first launch after the recorded app version changes, with previousVersion and version.

Lifecycle tracking is enabled once per Tracking instance. Applications can stop it with disableAutoLifecycleEvents() when the helper should no longer listen for app state changes.

References: src/…/analytics-tracking.ts• L105-157 src/…/analytics-tracking.ts• L159-249 src/…/analytics-tracking.ts• L251-298

Manual event tracking

Tracking.track() provides a best-effort API for custom product telemetry. It accepts an event name and optional properties, URL, engagement time, and interaction flag, then converts property values to the flat string format expected by the analytics event service.

The helper supplies a platform-safe default URL: the current web origin on the web, or an app:// URL on native platforms. A caller can set a different base URL when constructing Tracking or resolve a particular event URL relative to that base.

Tracking failures are swallowed after a warning. This keeps analytics loss from interrupting the user flow or surfacing an exception through the application event path.

References: src/…/analytics-tracking.ts• L28-42 src/…/analytics-tracking.ts• L301-340

Screen tracking

Screen tracking records a screen_view event with the screen name in both the event properties and the event URL path. screenView() supports an optional screen class and custom properties for applications that report screens directly.

React Navigation applications can use trackNavigation() to connect route changes to the same event stream. The helper reports the initial route and later reports only when the selected screen name changes. Applications can provide a screen-name mapper to skip or rename routes, and can keep their own navigation callbacks through the helper options.

References: src/…/analytics-tracking.ts• L44-47 src/…/analytics-tracking.ts• L342-355 src/…/analytics-tracking.ts• L384-425

Push event tracking

Push tracking links notification delivery with user action. Applications call pushReceived() from their push handler and call pushOpened() when the user taps the notification.

Both helpers can attach a message ID and campaign name. A received event is non-interactive, while an opened event is interactive. Delivery is best effort because the operating system may not run application code when a notification arrives while the app is closed.

References: src/…/analytics-tracking.ts• L49-53 src/…/analytics-tracking.ts• L357-380

Tracking flow

The tracking flow combines application events with shared context before the Analytics service submits one event request.

flowchart LR
    A[Application action] --> B{Tracking helper}
    B -->|lifecycle, install, screen, push, or custom event| C[Event name and context]
    C --> D[Analytics.createEvent]
    D --> E[Analytics property]
    D -->|accepted| F[Resolved response]
    D -->|rejected| G[Handled tracking failure]

Direct Analytics.createEvent calls expose the service response to the application. Tracking calls send in the background and treats failure as telemetry loss rather than an application error.

References: src/…/analytics.ts• L30-45 src/…/analytics-tracking.ts• L301-340

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the event property names and flat props contract aligned between Tracking and Analytics.createEvent.
  • Preserve the distinction between interactive user events and non-interactive lifecycle, push-received, and background events.
  • Keep install marker and pending-event behavior aligned with version changes so retries do not lose or duplicate the install state decision.
  • Keep route-name filtering and callback order aligned with the React Navigation integration contract.

Important failure modes

TriggerConsequenceGuard
propertyId, name, or url is missingThe Analytics service rejects the request with an AppwriteException.Supply all three required event inputs.
A tracking request is rejected or the network failsDirect callers receive a rejected promise; Tracking logs the failure and continues the app flow.Handle direct service errors and use Tracking for best-effort telemetry.
A notification arrives while the app is not runningThe app may not execute pushReceived(), so receipt data is absent.Treat push receipt tracking as best effort and track pushOpened() when the app handles the tap.
A native app has no native cookie moduleNative install and update events cannot use the app version or session state.Use the native SDK module for install/update tracking; do not expect these events in web or Expo Go contexts.

Key files

FileWhy to read it
src/…/analytics.tsDefines the event contract, required inputs, optional telemetry context, and accepted response path.
src/…/analytics-tracking.tsDefines automatic lifecycle, install, screen, push, and manual tracking behavior for applications.