Track Webviews
In order to enable WebView tracking, two steps are required:
- Inject the Contentsquare Tracking Tag in WebView mode in the web pages loaded in your app’s WebViews. For more information on this step, refer to 📚 Mobile Apps WebView Tracking Documentation.
- Call the following API, which will inject our JavaScript Bridge into your WebViews, to connect the Tag and the SDK:
// Start tracking the given WKWebViewContentsquare.register(webView: WKWebView)
// Stop tracking the given WKWebViewContentsquare.unregister(webView: WKWebView)
// Start tracking the given WKWebView[Contentsquare registerWithWebView:(WKWebView * _Nonnull)];
// Stop tracking the given WKWebView[Contentsquare unregisterWithWebView:(WKWebView * _Nonnull)];
Validate WebView tracking
Section titled Validate WebView trackingOn the native side
Section titled On the native sideOnce you open the screen with the tracked WebView in your app, you should see the following log:
CSLIB ℹ️ Info: WebView tracking enabled on native side for page: [URL]. Waiting for Web Tracking Tag messages…
Once the web page is loaded in the WebView, you should see the following log:
CSLIB ℹ️ Info: WebView navigated to new page: [URL]. Waiting for Web Tracking Tag messages…
On the Web side
Section titled On the Web sideOnce the Web Tracking tag is detected in the web page, you should see the following log:
CSLIB ℹ️ Info: Web Tracking Tag is detected on page: [URL]
Validating Pageview and Gestures tracking
Section titled Validating Pageview and Gestures tracking- Page views sent through the Web Tracking Tag are displayed the same way as native screen views:
CSLIB ℹ️ Info: Screenview - Screen name: "{{page name given}}" - Screen number: 11
- Taps and swipes detected by the Web Tracking Tag are also displayed the same way as taps and swipe on native elements, but the end of the target contains HTML DOM elements:
CSLIB ℹ️ Info: Tap - Target: ...>UIViewControllerWrapperView:eq(0)>UIView:eq(0)>WKWebView:eq(0)|webview|img#picture-holder