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:
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, we recommend that you call methods by following the Activity/Fragment lifecycle callbacks in a symmetrical way:
- At the Activity level, call
injectEventTrackingInterface
on theonCreate
lifecycle method andremoveEventTrackingInterface
on theonDestroy
lifecycle method. - At the Fragment level, call
injectEventTrackingInterface
on theonViewCreated
lifecycle method andremoveEventTrackingInterface
on theonDestroyView
lifecycle method.
Validate WebView tracking
Section titled Validate WebView trackingFor 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 sideOnce 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.