Context in edge extension modules
All library modules in edge extensions are provided a context
object when they are executed. This document covers the properties provided by the context
object and the role they play in library modules.
Adobe Request Context (arc)
The arc
property is an object that provides information about the event triggering the rule. The sections below cover the various sub-properties contained in this object.
event
The event
object represents the event that triggered the rule and contains the following values:
logger.log(context.arc.event);
xdm
data
request
Not to be confused with a request from the client device, request
is a slightly modified object that comes from Adobe Experience Platform Edge Network.
logger.log(context.arc.request)
The request
object has two top-level properties: body
and head
. The body
property contains Experience Data Model (XDM) information and can be inspected in Adobe Experience Platform Debugger when you navigate to Launch and select the Edge Trace tab.
ruleStash rulestash
ruleStash
is an object that will collect every result from action modules.
logger.log(context.arc.ruleStash);
Each extension has its own namespace. For example, if your extension has the name send-beacon
, all results from send-beacon
actions will be stored on the ruleStash['send-beacon']
namespace.
The namespace is unique for each extension, and has a value of undefined
at the beginning.
The namespace is overridden with the returned result from each action. For example, consider a transform
extension containing two actions: generate-fullname
and generate-fulladdress
. These two actions are then added to a rule.
If the result of the generate-fullname
action is Firstname Lastname
, then the rule stash will appear as follows after the action is completed:
{
transform: 'Firstname Lastname'
}
If the result of the generate-address
action is 3900 Adobe Way
, then the rule stash will appear as follows after the action is completed:
{
transform: '3900 Adobe Way'
}
Notice that “Firstname Lastname” no longer exists within the rule stash, because the generate-address
action overrode it with a new value.
If you want ruleStash
to store the results from both actions inside the transform
namespace, you can write your action module similar to the following example:
module.exports = (context) => {
let transformRuleStash = context.arc.ruleStash.transform;
if (!transformRuleStash) {
transformRuleStash = {};
}
transformRuleStash.fullName = 'Firstname Lastname';
return transformRuleStash;
}
The first time this action is executed, ruleStash
starts as undefined
and is therefore initialized as an empty object. The next time when the action is executed, it receives ruleStash
that was returned when the action was previously called. Using an object as ruleStash
allows you to add new data without losing data previously set by other actions from our extension.
Utilities
The utils
property represents an object that provides utilities specific to the tag runtime.
logger
The logger
utility allows you to log messages that will be shown during debugging sessions when using Adobe Experience Platform Debugger.
context.utils.logger.error('Error!');
The logger has the following methods, where message
is the message you want to log:
log(message)
info(message)
warn(message)
error(message)
debug(message)
verbose
logging is enabled within your browser console.fetch
This utility implements the Fetch API. You can use the function to make requests to third-party endpoints.
context.utils.fetch('http://example.com/movies.json')
.then(response => response.json())
getBuildInfo
This utility returns an object containing information about the build of the current tag runtime library.
logger.log(context.utils.getBuildInfo().turbineBuildDate);
The object contains the following values:
turbineVersion
turbineBuildDate
buildDate
environment
development
, staging
, and production.
The following is an example getBuildInfo
object to demonstrate the values it returns:
{
turbineVersion: "1.0.0",
turbineBuildDate: "2016-07-01T18:10:34Z",
buildDate: "2016-03-30T16:27:10Z",
environment: "development"
}
getExtensionSettings
This utility returns the settings
object that was last saved from the extension configuration view.
logger.log(context.utils.getExtensionSettings());
getSettings
This utility returns the settings
object that was last saved from the corresponding library module view.
logger.log(context.utils.getSettings());
getRule
This utility returns an object containing information about the rule that is triggering the module.
logger.log(context.utils.getRule());
The object will contain the following values:
id
name