Sending custom vars
General principles
Section titled General principlesCustom vars are additional information on the page, the user or the session, sent along with pageviews.
They generally include datalayer information, such as:
- Page type,
- Product category,
- If the user is signed in or not,
- The number of items in the cart
This information enables visitor segmentation or page grouping, for which the URL would not be enough.
Limits
Section titled LimitsEach custom var is composed of a key (max. 512 characters) and value (max. 255 characters).
You are limited to 20 custom vars per project.
You can update up to 20 cvars on the same page.
Each custom var holds a unique index, strictly comprised between 1 and 20. Custom vars with indexes outside this range are not sent. Indexes are available for users to select within Contentsquare.
Use a consistent index for a given custom var within a project — for instance, if the “page template” is collected with an index of 3, use the slot 3 for this information on every page of the website.
Saving a custom variable creates a URI-encoded cookie which contains a stringified JSON of the stored information. This string may contain all URI allowed characters ↗.
Defining custom vars
Section titled Defining custom varsTo define a custom var, use the setCustomVariable
command:
This means that you have to add an array to the _uxa
object, containing:
-
index
is a integer > 0 and <= 20 -
name
is a string of 512 characters max (if longer the Tag will truncate it) -
value
is a string of 255 characters max (if longer the Tag will truncate it) -
scope
(optional) defines the custom var scope and behavior- No
scope
specified (default):- In scopes
visit
andpage
.
- In scopes
2
orvisit
:- In scope
visit
.
- In scope
3
orpage
:- In scope
page
. - Deleted after a Natural pageview.
- In scope
4
ornextPageOnly
:- In scope
nextPageOnly
. - Deleted after a Natural pageview, or an Artificial pageview with the next
trackPageview
command.
- In scope
- No
Once defined, custom vars are sent automatically with the next pageview (natural or artificial).
Defining a custom var with an index that already exists overrides its name and value.
Examples
Section titled ExamplesDefining a custom var in scope visit
at index 5
with name cname
and value cvalue
.
Defining a custom var in scopes visit
and page
at index 6
with name cname
and value cvalue
.
Defining a custom var with the scope nextPageOnly
.
Delete custom var command
Section titled Delete custom var command- A custom var can be deleted by calling the command with an empty string value. The index parameter must match the custom var to delete.
- Custom vars with scope
nextPageOnly
are automatically deleted when the next natural or artificial page view is sent.
Examples
Section titled ExamplesDeleting the custom var of name cname
.
Deleting custom var of name cname
from scope visit
.
Deleting custom var of name cname
from both scopes page
and visit
with an empty scope
value.
Verifying the sending of custom vars
Section titled Verifying the sending of custom varsTo verify that custom vars have been sent, check the cvarp
parameter of the corresponding pageview.