The Custom Variable (CVar) template allows you to collect additional information on the page, user, or session sent within pageviews.
These instructions are to be used alongside the Contentsquare Tag Configurator article, which includes details on prerequisites, and Snippet creation.
Commonly used to
- Create mappings, instead of relying on URLs (especially if your website includes a datalayer)
How to use it
Note: This template should not be used on a Single Page Application or modal pop-ups where Artificial Pageviews are fired.
Once you have created your Snippet, use the steps below to configure this selected template and the chosen trigger.
Step 1: Complete the following fields
- Iterable Context (optional): Used to iterate through dataLayer arrays, for example, if you need to get a CVar from dataLayer[i].event. This can be left blank.
- Index number
- Key
- Value
-
Scope: select from the following scope
- Page (custom variables valid until page reload)
- Visit (custom variables valid for the whole session)
- nextPageOnly (custom variables valid until new pageview): selected by default
Defining a CVar
If the value you want to collect as a CVar is in a global object (like a data layer), you have two options:
- If the value is always inside a fixed location in the global object, simply pass that into the value field as is, using interpolation [link]. For example: ${window.utag.data.pageName}
- If, however, the value location within the object is not fixed, then you will need to fill in the iterable context [link] field as well.
For example, if you want to grab the pageName from the data layer, then set the fields below as follows:- Iterable context: values(window.dataLayer)[?pageName]
- Index: choose a number between 1 and 20
- Key: Page Name
- Value: ${.pageName}
For more details on defining CVARS, visit our technical documentation.
Step 2: Select a Trigger
Select a trigger and define the conditions that will fire the Snippet.
Available triggers