WebView Tracking Tag Web

To enable WebView tracking in your mobile app, you need to implement the Contentsquare Web Tracking Tag in every web page called in your mobile app for the WebView to communicate with our native SDK.

WebView tracking relies on:

The Web Tracking Tag is responsible for establishing communication with the SDK in the parent app. To set it up, you can follow the different implementation guidelines presented in The main Tracking Tag section.

The web tracking tag needs to be set in WebView mode in order to collect data and pass them to the main SDK that will send them to the dedicated Apps project. To do so, the following command must to be added before loading the tracking tag (or it will be ignored):

window._uxa.push(['setOption', 'isWebView', true]);

Choosing a WebView Data Collection Strategy

Section titled Choosing a WebView Data Collection Strategy

There are different options for collecting data, and the strategy that is best for you will depend on various factors.

Some questions to consider include:

  • Is the WebView page also visited by web browsers, or is it only used within a WebView context?
  • Are the same teams responsible for these pages in both contexts (on the website and within a mobile app webview), or do different teams work closely together and share a lot of code?
  • Does most of the tracking customization need to apply in both contexts (with little to no differences), such as session replay masking rules and event handling?

Depending on these questions, there are 2 main collection strategies that can be applied for WebViews:

  • Use the same tracker (Tag ID) for both browser and WebView contexts
  • Use a dedicated tracker (Tag ID) for pages created exclusively for WebViews (and/or pages used in both context but with different settings required).

Use the same tracker for Web & Webview contexts

Section titled Use the same tracker for Web & Webview contexts

For pages visited both in the browser and in WebViews, the same tracker can be used for both the Web and WebView use cases. To do so:

  • Load the Tag as when in the browser
  • Activate the isWebView option before the loading of the Web Tracking Tag

Here is a code snippet example:

<script type="text/javascript">
(function () {
window._uxa = window._uxa || [];
if (aConditionThatTellsYouWeAreInAWebview()) {
window._uxa.push(['setOption', 'isWebView', true]);
}
var mt = document.createElement("script");
mt.type = "text/javascript";
mt.async = true;
mt.src = "https://t.contentsquare.net/uxa/YOUR_TAG_ID.js";
document.getElementsByTagName("head")[0].appendChild(mt);
})();
</script>

Use a dedicated tracker for WebView context

Section titled Use a dedicated tracker for WebView context

For local pages, pages visited exclusively in WebView context and pages requiring different settings in WebView context, it is possible to use a dedicated tracker. Here is a code snippet example:

<script type="text/javascript">
(function () {
window._uxa = window._uxa || [];
window._uxa.push(["setOption", "isWebView", true]);
var mt = document.createElement("script");
mt.type = "text/javascript";
mt.async = true;
mt.src = "https://t.contentsquare.net/uxa/YOUR_TAG_ID.js";
document.getElementsByTagName("head")[0].appendChild(mt);
})();
</script>