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.

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

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,
country: headers["HTTP_CF_IPCOUNTRY"],
language: headers["Accept-Language"],
channel: query_params.utm_medium,

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.