Skip to main content

Context Attributes

Attributes are used to pass meta-data about the user and/or the request. They can be used later in the Web Console to create segments or audiences. They can be set using the attribute() or attributes() methods, before or after the context is ready.

One of the most useful and commonly used attributes, is the user_agent attribute which, when passed to the SDK, will be split up into multiple attributes that can be used to target specific browsers or devices in the Web Console. You can read more about how this works in the Segments section of the Dashboard Settings docs.

context.attribute("user_agent", navigator.userAgent);

context.attributes({
customer_time:
user.created > new Date().getTime() - 24 * 60 * 60 * 1000
? "new_customer"
: "returning_customer",
user_type: user.isInternal ? "internal" : "normal",
url: location.toString(),
user_agent: navigator.userAgent,
referrer: document.referrer,
screenName,
pageName,
country: headers["HTTP_CF_IPCOUNTRY"],
language: headers["Accept-Language"],
channel: query_params.utm_medium,
});
caution

You should create audiences with the same attributes as those in the Web Console. By default it will not enforce these conditions, but if for some reason the treatment() method is called for a user that doesn’t meet the correct criteria, the Web Console will warn you about it.