The Custom Variable (CVar) template allows you to collect additional information on the page, user, or session of your visitors.
These instructions should 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 or another global object with this information)
How to use it
Note
Currently, 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 to a value from dataLayer[i].event. This can be left blank if not applicable.
- Index number: A number from 1 to 20. Make sure to assign an index not already used by other CVARs on your website.
- Key: the key value
- Value: The value. Could be a fixed string or a value from a dataLayer, for example.
-
Scope: Select from the following scope
- nextPageOnly (value persists until next pageview (unless overwritten). The default and recommended setting.
- Page (value persists until next page reload (unless overwritten)).
- Visit (value persists throughout the entire session (unless overwritten)).
Defining a CVar
If the value you want to collect as a CVar is in a global object (like a dataLayer), 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. 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 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