Technical DocWebView Tracking Tag

WebView Tracking Tag Doc

Use this document to enable WebView tracking in your mobile app. You'll need to implement the Contentsquare WebView JavaScript Tracking Tag in the web pages called in your mobile app to build a JavaScript Bridge between your WebView content and the native SDK.

Get Started

The WebView JavaScript Tracking Tag is responsible to establish communication with the SDK in the parent app.

To set up, you just need to add the following lines of code on every page that will be called in a WebView of your app, either at the end of the body marker, or via a TMS.

<script type="text/javascript">
(function() {
   var mt = document.createElement("script"); mt.type = "text/javascript"; mt.async = true;
   mt.src = "//";

This code creates a function which will add an asynchronous call to a script and then execute the function. This is a way to avoid other elements loading being blocked on the page. This reduces the impact of the tag on the page's performances.


Even though Contentsquare only collects usage data on your app, the SDK will consider every new user to be opted-out. To start tracking, the SDK Opt-in API must be called.

You are responsible for creating the UI asking the user for his consent and allowing him to manage his privacy settings and then calling the appropriate Contentsquare following functions (opt-in or opt-out).

If for some reason you think that securing user consent is not required for your app, discuss it during the Implementation process with your main contact.


Opt-in command is compatible with iOS SDK >= 4.13.0 and Android SDK >= 4.10.0

Use the Opt-in API to get user consent. Calling this API will generate a user ID and initiate tracking.

window.cs_wvt = window.cs_wvt || [];


Opt-in command is compatible with iOS SDK >= 4.13.0 and Android SDK >= 4.10.0

Permanently breaking the link and stopping all data collection.

When this API is called, tracking stops immediately, all settings are reset (Session number, Page number...) and all files and directory regarding to Contentsquare are deleted. This means that the user ID is deleted. The SDK will never track and collect any data from the user's phone unless the Opt-in API is called again.

window.cs_wvt = window.cs_wvt || [];

Track Pageviews

Contentsquare aggregates user behavior and engagement at the screen/page level. To do so, it is required to track page transitions by calling a dedicated command. When the command is called, the WebView Tracking Tag logs a pageview event that identifies the new page with the Page Title provided.

window.cs_wvt = window.cs_wvt || [];
window.cs_wvt.push(['trackPageview', 'My Custom Page Title']) // triggers a pageview event with "My Custom Page Title" as the page title

Track Transactions

Opt-in command is compatible with iOS SDK >= 4.13.0 and Android SDK >= 4.10.0

To associate a user's session with their potential purchases (and corresponding revenue), you must send the transaction via a dedicated API. For each transaction, we send:

  • price (mandatory)
  • currency (mandatory)
  • transaction ID (optional)
window.cs_wvt = window.cs_wvt || [];
window.cs_wvt.push(['trackTransaction', { value: 1000, currency: 'EUR', id: 'my-transaction-id'}]) 
// value is a float
// currency is a string that must be inferior to 10 characters
// id is a string or null

Each transaction must only be sent once. A common mistake is to trigger the sending when the confirmation screen is displayed. This leads to triggering the transaction each time the user puts the app in background and then in foreground on the confirmation screen.


The currency is conforming to the ISO 4217 standard. The currency must be passed as an "alphanumeric code".

If the currency passed doesn't match the supported currencies, the SDK will send a currency value of -1. It will be processed as the default currency of the project.

Track Dynamic Variables

Opt-in command is compatible with iOS SDK >= 4.13.0 and Android SDK >= 4.10.0

General principles


Dynamic variables are additional information on the session that can be used to segment sessions.

For example, they can include information on the A/B Test variations displayed to the current user.


On the server side
  • It is possible to save up to 40 distinct dynamic variable keys per screenview. If more are received, only the first 40 keys will be kept.
  • If you are using the same key twice on the same screenview, the last value associated with the key will be recorded.
On the SDK side
  • Every dynamic variable is composed of a pair of key (max. 50 characters) and value (max. 255 characters string or number of type Long between 0 and 2^32 -1). In case these maximums length are reached, the SDK will automatically trim the exceeding characters.
  • If key or value are empty, the SDK will instead send the literal string "cs-empty".

Defining dynamic variables

To define and send a dynamic variable, directly use the key and String/Long value once a first screenview has been triggered:

window.cs_wvt = window.cs_wvt || [];
window.cs_wvt.push(['trackDynamicVariable', { key: 'my-string-dvar', value: 'my-awesome-string-value' }]);
// key is a string
// value is either a string or an integer

Type of the value — The value can be either a whole number or a string. For each case, available features won't be the same in the Contentsquare app:

  • for whole numbers, you will be able to do some algebra. Example: sessions with dynamic variable key = "numberOfFriends" and value >= 10
  • for strings, auto-completion and Regular Expression will be available. Example: sessions with dynamic variable key = "accountType" and value = "Premium"

Collected data

Once communication is established, the tag will start tracking the following events and pass them over to the SDK:

  • pageviews manually triggered (with the dedicated command)
  • transactions manually triggered (with the dedicated command)
  • dynamic variables manually triggered (with the dedicated command)
  • gestures automatically detected: tap, long press, swipes (with finger direction)
  • HTML DOM when a snapshot of the screen is triggered by the SDK (see section on Enable Snapshot Mode in the iOS/Android SDK docs).

Conflict with Contentsquare Web Tracking Tag

If the pages called in your app's WebViews are also part of your main website and you are using the main Web Tracking Tag, please ensure that:

  • when the page is loaded in your app's webView: only the WebView Tracking Tag is loaded (and not the main Web Tracking Tag)
  • when the page is NOT loaded in your app's webView: only the main Web Tracking Tag is loaded (and not the WebView Tracking Tag)


1.3.0 - 2022.05.17

Versions 1.1.0 and 1.2.0 were not deployed

1.0.0 - 2021.01.19

  • Initial release

See iOS SDK Documentation section on WebView tracking

See Android SDK Documentation section on WebView tracking