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 WebView Tracking Tag is implemented in the web pages, the following Public API interface needs to be implemented to establish the JavaScript Bridge:

CsWebViewManager.injectEventTrackingInterface(@NonNull WebView webView) // to start tracking the specific WebView
CsWebViewManager.removeEventTrackingInterface(@NonNull WebView webView) // to stop tracking and detaching from the specific WebView

For a better synchronization call methods by following the Activity/Fragment lifecycle callbacks in a symmetrical way:

At the Activity level, call injectEventTrackingInterface on the onResume lifecycle method and removeEventTrackingInterface on the onDestroy lifecycle method. At the Fragment level, call injectEventTrackingInterface on the onViewCreated and removeEventTrackingInterface on the onDestroyView lifecycle method.

For the moment, there is no way of validating the implementation on the native side only.

Validating the implementation on the web side

Section titled Validating the implementation on the web side

Once you arrive on the screen with the tracked WebView, you should see an initial confirmation log message:

WebView detected and WebView tracking enabled on native side

Specific logs are then emitted for:

  • Page views fired by the WebView Tracking Tag in the same format as for screen views: Screenview - Screen name: {{page name given}} - Screen number: 11
  • Taps and swipes detected by the WebView Tracking Tag in the same format as for defaults taps and swipe but with the target matching an HTML DOM element value: Tap - Target: {Last view info: div:eq(0)} - Unresponsive: false

Going further: If you still have a doubt, you can look for logs by filtering on WebViewEventProcessor. Their presence will confirm that it is well implemented on both web and native sides.