Skip to main content

WebView Tracker

Early Release

The Snowplow WebView Tracker allows you to track Snowplow events from Web views in mobile hybrid apps. The current tracker version is 0.2.0.

Hybrid apps are mobile apps that in addition to a native interface, provide part of the UI through an embedded Web view. Snowplow events are tracked from both the native code (e.g. written in Swift or Kotlin) as well as the Web view (in JavaScript). Our goal is to have both events tracked from the native code as well as the Web view, share the same session and appear as tracked with the same tracker.

The WebView tracker should be integrated in Web apps used in Web views within native mobile apps. The tracker provides APIs to track Snowplow events. It forwards the events to the native app code to be tracked by the Snowplow mobile trackers (iOS, Android tracker, or React Native). The diagram below shows the interaction of the WebView and mobile trackers in hybrid apps.

Installationโ€‹

You may choose to install the tracker as an npm package or by loading it through an HTML script tag.

To install the WebView tracker in your JavaScript or TypeScript app, add the npm package:

npm install --save @snowplow/webview-tracker

You will then be able to use the functions provided by the WebView tracker as follows:

import { trackSelfDescribingEvent } from '@snowplow/webview-tracker';

In addition, you will need to install the iOS or Android tracker in your native code and configure and initialize a tracker (see the mobile tracker docs). Afterwards, you will be able to subscribe to and track the events from the WebView tracker in a Web view by calling Snowplow.subscribeToWebViewEvents(webView).

Using the trackerโ€‹

To track events, simply call their corresponding functions given the event data:

trackSelfDescribingEvent({
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1',
data: {
targetUrl: 'http://a-target-url.com'
}
}
});

Accelerator guideโ€‹

For a step-by-step guide on how to instrument hybrid apps and model the mobile data, please visit the Mobile & Hybrid App Analytics accelerator.

Was this page helpful?