Clear History

Tracking Events

The trackers create data on user actions at specific points in time. For example:

  • First start of the app after installation
  • App goes to foreground or background
  • App screen is viewed

A number of tracking events are available out of the box. These include, but aren’t limited to:

  • Screen views
  • App lifecycle events
  • Installation events

All of these events are enriched with automated session tracking and other device information.

Screen View Tracking

Screen views are events tracked when the user views a screen within the application. In most cases, the trackers automatically track screen view events. If not tracked automatically, you can still track screen view events manually in your app.

Automatic screen view tracking is enabled by default. It supports UIKit views that are tracked as they appear.

Automatic tracking is not yet available for SwiftUI views. If using SwiftUI in your application, you can track screen view events manually as the views appear using the onAppear callback:

YourView {
    ...
}
.onAppear {
    let event = ScreenView(name: "home", screenId: UUID())
    Snowplow.defaultTracker()?.track(event)
}

Automatic screen view tracking is enabled by default. It tracks events as Activity instances are resumed in their lifecycle.

The React Native tracker does not yet provide an automated solution to track React Native views. You can track the screen views manually in the useLocation hooks in React Router as follows:

import React from "react";
import {
  Switch,
  useLocation
} from "react-router-dom";

const useLocationChange = () => {
    const location = useLocation();
    React.useEffect(() => {
        tracker.trackScreenViewEvent({
            id: uuidv4(), // generate a UUID v4 string
            name: 'home',
            type: 'full',
            transitionType: 'none'
        });
    }, [location]);
};

function App() {
  useLocationChange();
  return <Switch>...</Switch>;
}

The tracker can automatically track view events when currently active pages change through the Navigator API.

To activate this feature, one has to register a SnowplowObserver retrieved from the tracker instance using tracker.getObserver(). The retrieved observer can be added to navigatorObservers in MaterialApp:

MaterialApp(
  navigatorObservers: [
    tracker.getObserver()
  ],
  ...
);

If using the Router API with the MaterialApp.router constructor, add the observer to the observers of your Navigator instance, e.g.:

Navigator(
  observers: [tracker.getObserver()],
  ...
);

Learn more about screen view autotracking in the Flutter tracker here.

App Lifecycle Tracking

Application lifecycle state can be captured automatically in some trackers. Once enabled, the tracker will automatically track a Background event when the app is moved to background and a Foreground event when the app moves back to foreground (becomes visible in the screen). The tracker also attaches a LifecycleEntity to all the events tracked by the tracker reporting if the app was visible (foreground state) when the event was tracked.

Enable the lifecycleAutotracking flag in TrackerConfiguration that is passed to the Snowplow.createTracker() call:

let trackerConfig = TrackerConfiguration()
    .lifecycleAutotracking(true)

Enable the lifecycleAutotracking flag in TrackerConfiguration that is passed to the Snowplow.createTracker() call:

TrackerConfiguration trackerConfig = new TrackerConfiguration()
    .lifecycleAutotracking(true);

Enable the lifecycleAutotracking flag in trackerConfig that is passed to the Snowplow.createTracker() call:

const tracker = createTracker(
    'ns',
    {
      endpoint: 'https://...',
    },
    {
        trackerConfig: {
            lifecycleAutotracking: true,
        },
    },
);

The Flutter tracker does not yet support automatic tracking of the application lifecycle.

Installation Tracking

It tracks an install event which occurs the first time an application is opened.

The installation autotracking is enabled by default.

The installation autotracking is enabled by default.

The installation autotracking is enabled by default.

The Flutter tracker does not yet support automatic tracking of app installation.

Custom Event Tracking

Additionally, the tracker enables tracking events with custom structure – called self-describing events. Self-describing events are based around “self-describing” (self-referential) JSONs, which are a specific kind of JSON schema. A unique schema can be designed for each type of event that you want to track. This allows you to track the specific things that are important to you, in a way that is defined by you.

A self-describing JSON has two keys, schema and data. The schema value should point to a valid self-describing JSON schema. They are called self-describing because the schema will specify the fields allowed in the data value. Read more about how schemas are used with Snowplow here.

let schema = "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1"
let data = ["targetUrl": "http://a-target-url.com"]
let event = SelfDescribing(schema: schema, payload: data)       
tracker.track(event)
String schema = "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1";
Map data = new HashMap();
data.put("targetUrl", "http://a-target-url.com");
SelfDescribingJson sdj = new SelfDescribingJson(schema, data);
SelfDescribing event = new SelfDescribing(sdj);
tracker.track(event);
tracker.trackSelfDescribingEvent({
    schema: 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1',
    data: {
        targetUrl: 'http://a-target-url.com'
    }
});
tracker.track(SelfDescribing(
    schema: 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1',
    data: {
        'targetUrl': 'http://a-target-url.com'
    }
));