Sending dynamic vars

Dynamic vars are additional information on the session that can be used to segment users.

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

Unlike custom vars, dynamic vars can be sent at any time during a session and do not require to send a pageview.

It is possible to save up to 40 distinct dynamic variables per pageview. If more are received, only the first 40 distinct keys will be kept.

If multiple dynamic variables using the same key are fired per pageview, only the last value associated with the key will be kept

Every dynamic variable being composed of a pair of key (max. 512 characters) and value (max. 255 characters string or integer from 0-4294967296). The key and value are truncated by the Tracking Tag before they are sent.

To define and send a dynamic var at once, use the trackDynamicVariable command:

<script type="text/javascript">
window._uxa = window._uxa || [];
window._uxa.push(["trackDynamicVariable", {key: my_key, value: my_value}]);
</script>

Allowed values are number or string — there are specific capabilities for each in the Contentsquare app:

  • For values of type number, you can use operators (more than, less than, etc.).
  • For values of type string, auto-completion and regular expressions are available.

Verifying the sending of dynamic vars

Section titled Verifying the sending of dynamic vars

Our Contentsquare Tracking Setup Assistant Chrome Extension displays each dynamic var sent.

If you can’t use our Chrome extension, use the _cs_debug cookie.

  1. From the browser console, run this command to create the cookie:

    document.cookie = "_cs_debug=compressionDisabled"
  2. Reload the page.

  3. In the Network tab, search for dvar, select the request, and check the value of the dv parameter.

To check the actual request that is sent for each dynamic vars package (several dynamic vars pushed at the same time bundled together in a single network request), follow GET requests sent to //c.contentsquare.net/dvar, with these parameters.

NameDescriptionType
dvDynamic vars (compressed)String
pidProject IDInteger
rA random digit to avoid request cachingInteger
uuUnique user IDString
pnPage number
(each pageview increments of 1)
Integer
snSession numberInteger