Hybrid mobile and web apps
This feature is available since v4. To use the Web plugin, you will need v6.1+ of the iOS or Android tracker.
Hybrid apps are mobile apps that in addition to a native interface, provide part of the UI through an embedded WebView. Snowplow events are tracked from both the native code (e.g., written in Swift or Kotlin) as well as the WebView (in JavaScript). Our goal is to have both events tracked from the native code as well as the WebView share the same session and appear as tracked with the same tracker.
Event forwarding
We recommend using the Web tracker (v4.3+) to forward all Web events to the mobile tracker.
Implement the Snowplow iOS or Android tracker.
Implement the Snowplow Web/JavaScript tracker in the WebView in your app. Make sure to include the WebView plugin.
Subscribe to WebView event messages.
- iOS
- Android (Kotlin)
- Android (Java)
// Pass in a WKWebViewConfiguration
Snowplow.subscribeToWebViewEvents(with: webView.configuration)// Pass in a WebView object
Snowplow.subscribeToWebViewEvents(webView);// Pass in a WebView object
Snowplow.subscribeToWebViewEvents(webView);Track events as usual.
The Web tracker will automatically intercept all web events and forward them to the mobile tracker. The forwarded events will have the tracker version from Web, e.g. "js-4.1.0", but will otherwise be tracked like the mobile events. They may contain additional information not present in the native mobile events, such as a browser useragent string or URL, or Web context entities e.g. the WebPage entity.
The forwarded events are filtered out of the Web tracker event queue so that they are not tracked twice.
The WebView plugin uses the Snowplow WebView tracker as a dependency.
WebView Tracker
If you don't want to implement a Web tracker in your WebView, you can use the Snowplow WebView tracker directly. This could be suitable if you only want to track a small number of events from the WebView. We recommend event forwarding for most use cases.
Implement the Snowplow iOS or Android tracker.
Implement the Snowplow WebView tracker in the WebView in your app.
Subscribe to WebView event messages.
- iOS
- Android (Kotlin)
- Android (Java)
// Pass in a WKWebViewConfiguration
Snowplow.subscribeToWebViewEvents(with: webView.configuration)// Pass in a WebView object
Snowplow.subscribeToWebViewEvents(webView);// Pass in a WebView object
Snowplow.subscribeToWebViewEvents(webView);Manually track WebView events.
All event types can be tracked with WebView tracker v0.3.0+, but it requires more work than using the event forwarding.