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 Adobe offers.
If an XDM field is not mapped for Adobe Analytics, it is automatically included as a context data variable. You can then using Processing rules to assign the context data variable to the desired Analytics variable.
While it is a best practice to map data to the correct XDM fields in the Datastream, this method achieves similar results.
Adobe Experience Platform Data Collection does not have a dedicated location to set context data variables. Use the custom code editor, following AppMeasurement syntax.
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";
"a."
. This prefix is reserved and used by Adobe. For example, do not use s.contextData["a.InstallEvent"]
.s.contextData["example"]
and s.contextData["EXAMPLE"]
are identical.Context data variables are discarded after processing rules run. If you do not have processing rules active that place values into variables, that data is permanently lost!
Processing rules immediately take effect once saved. They do not apply to historical data.
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");
When creating processing rules, you can assign context data variables to events.
// 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";