Dynamic Variables (DVARs) allow you to collect additional information on the session for further filtering and segmentation. It can be used to flag almost any type of user behavior, or page layout.
These instructions should be used alongside the Contentsquare Tag Configurator article, which includes details on prerequisites and Snippet creation.
Commonly used to
- Segment and compare user sessions in your analysis.
- A/B testing: for when you have binary or multiple values of something, such as an AB test or a multivariate test, where the experiment name remains the same while the test and controls change name.
How to use the template
Once you have created your snippet, use the steps below to configure this selected template and the chosen trigger.
Step 1: Complete the following template fields
- Iterable context: Enter the iterable context you wish to collect (optional)
- Key
- Value
- Type: Select your value type (String or Integer)
Defining a DVar
DVars consist of a key-value pair where the values can be either a string, or a number (integer). These options offer different filtering capabilities inside the Contentsquare platform:
- For values of type number, you can use operators (more, less than, etc)
- For values of type string, autocompletion and regular expressions are available
If the value you want to collect as a DVar is stored in a global object (such as a dataLayer array), you have two options:
1) If the value is inside a fixed location in the global object, simply pass that into the value field as is, using interpolation.
- For example, to grab the email from window.utag.data.customer_email, simply pass that into the ‘Value’ field as is, using interpolation: ${window.utag.data.customer_email}
2) If, however, the value location within the object is not fixed, as is the case in a GTM dataLayer, then you will need to fill in the iterable context field as well.
- For example, if you want to grab the visitor’s country (assuming this value exists in your dataLayer) from your dataLayer, then set the fields below as follows:
- Iterable context: values(window.dataLayer)[?country]
- Value: ${$.country}
Step 2: Select a Trigger
Select a trigger and define the conditions that will fire the Snippet.
Available Triggers
- After Pageview
- Before Pageview
- Element Becomes Visible
- Element Click or Tap
- Element Exists
- Element Insertion
- Element Removal
- Form Submit
- Hash Change
- History Change
- Mouseover
Template and trigger guidelines
- You can pass up to 20 DVARs per page view. However, note that if you pass more than 1 DVar with the same ‘Key’ value per pageview, all but the last one will be overwritten, and only the last one will remain in the system.
- If you are using one of the following triggers - Element Click or Tap, Element Exists, Element Insertion, Element Becomes Visible or Mouseover - you can actually pass the target element's text into your DV value, by putting the following expression into the ‘Value’ field:
- Value: ${element.textContent}
- For example, if you are using the Element Becomes Visible trigger and your target is an error message that appears under a form field (when a visitor fails to submit it) and your error text is "Please fill out your first and last name". Therefore, the resulting DVAR will be:
- Key: Validation error
- Value: Please fill out your first and last name
- Behavior exception for interpolation: If Interpolated values are undefined at runtime, the template will retry for 20 times each 100ms (2 seconds in total) and then quit.