Track Webviews

To enable WebView tracking, it is required to build a JavaScript Bridge between the content of the WebView and the native SDK. To do so, you will have to implement the Contentsquare WebView JavaScript Tracking Tag in the web pages called in your app WebViews.

For more information, refer to 📚 Mobile Apps WebView Tracking Documentation.

Once the Web Tracking Tag is implemented in the web pages, the following native API needs to be called to establish the JavaScript Bridge:

// Start tracking the given WKWebView
Contentsquare.register(webView: WKWebView)
// Stop tracking the given WKWebView
Contentsquare.unregister(webView: WKWebView)

At the UIViewController level, call the register method above in the viewWillAppear method. And unregister the WebViews in the view controllers viewWillDisappear method.

Validating the implementation on the native side

Section titled Validating the implementation on the native side

Once you arrive on the screen with the tracked WebView, 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…

Validating the implementation on the Web side

Section titled Validating the implementation on the Web side

Once 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 on the Web side

Section titled Validating Pageview and Gestures tracking on the Web side
  • Page views fired by the Web Tracking Tag in the same format as for screen views:
CSLIB ℹ️ Info: Screenview - Screen name: "{{page name given}}" - Screen number: 11
  • Taps and swipes detected by the Web Tracking Tag in the same format as for defaults taps and swipe but with the end of the target containing HTML DOM elements values:
CSLIB ℹ️ Info: Tap - Target: ...>UIViewControllerWrapperView:eq(0)>UIView:eq(0)>WKWebView:eq(0)|webview|img#picture-holder