contextData
Context data variables let you define custom variables on each page that processing rules can read. Instead of explicitly assigning values to Analytics variables in your code, you can send data in context data variables. Processing rules then take context data variable values and pass them into respective Analytics variables. See Processing rules in the Admin user guide.
Context data variables are helpful for development teams to collect data in named elements instead of numbered variables. For example, instead of requesting development teams assign the page’s author to eVar10
, you can request they assign it to s.contextData["author"]
instead. An Analytics administrator in your organization can then create processing rules to map context data variables into analytics variables for reporting. Development teams would ultimately only worry about context data variables instead of the many page variables that ÃÛ¶¹ÊÓƵ offers.
Context data variables using the Web SDK
If using the XDM object, all fields that don’t map to an ÃÛ¶¹ÊÓƵ Analytics variable are automatically included as a context data variable. You can also explicity set context data using the XDM object. You can then use Processing rules to assign the context data variable to the desired Analytics variable. See Mapping other XDM fields to Analytics variables for more information.
If using the data object, all context data variables reside within data.__adobe.analytics.contextData
as key-value pairs:
alloy("sendEvent", {
"data": {
"__adobe": {
"analytics": {
"contextData": {
"example_variable": "Example value",
"second_example": "Another value"
}
}
}
}
});
The Processing rules interface would show c.example_variable
and c.second_example
in applicable drop-down menus.
Context data variables using the ÃÛ¶¹ÊÓƵ Analytics extension
ÃÛ¶¹ÊÓƵ Experience Platform Data Collection does not have a dedicated location to set context data variables. Use the custom code editor, following AppMeasurement syntax.
s.contextData in AppMeasurement and the Analytics extension custom code editor
The s.contextData
variable does not directly take a value. Instead, set properties of this variable to a string.
// Assign the example_variable property a value
s.contextData["example_variable"] = "Example value";
- Valid context data variables contain only alpha-numeric characters, underscores, and periods. ÃÛ¶¹ÊÓƵ does not guarantee data collection in processing rules if you include other characters, such as hyphens.
- Do not start context data variables with
"a."
. This prefix is reserved and used by ÃÛ¶¹ÊÓƵ. For example, do not uses.contextData["a.InstallEvent"]
. - Context data variables are not case-sensitive. The variables
s.contextData["example"]
ands.contextData["EXAMPLE"]
are identical. - A single key cannot contain more than one value. If you want to use context data variables for multi-value variables, concatenate all values using a delimiter (typically a comma) and pass it into either a list prop or a list variable using processing rules.
Use processing rules to populate analytics variables
- Update your implementation to set context data variable names and values.
- Log in to ÃÛ¶¹ÊÓƵ Analytics and go to Admin > Report Suites.
- Select the desired report suite, then go to Edit Settings > General > Processing Rules.
- Create a processing rule that sets an Analytics variable to the context data variable value.
- Save changes.
Processing rules immediately take effect once saved. They do not apply to historical data.
Send context data in a link tracking call
Include the context data variable as a property of contextData
in s.linkTrackVars
:
s.contextData["example_variable"] = "Example value";
s.linkTrackVars = "contextData.example_variable";
s.tl(true,"o","Example context data link");
Increment events using context data variables
When creating processing rules, you can assign context data variables to events.
- If a context data variable contains any kind of text, the event increments by one.
- If a context data variable contains an integer, the event increments by that integer amount.
// Assigning this context data variable to an event increments it by one
s.contextData["example_text"] = "Text value";
// Assigning this context data variable to an event increments it by four
s.contextData["example_number"] = "4";