Context in edge extension modules

NOTE
Adobe Experience Platform Launch has been rebranded as a suite of data collection technologies in Adobe Experience Platform. Several terminology changes have rolled out across the product documentation as a result. Please refer to the following document for a consolidated reference of the terminology changes.

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);
Property
Description
xdm
The XDM object of the event.
data
The custom data layer.

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.

NOTE
Be careful to always return the full extension rule stash when using this strategy. If you instead only return a value, it will overwrite any other properties you may have set.

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:

Method
Description
log(message)
Logs a message to the console.
info(message)
Logs an informational message to the console.
warn(message)
Logs a warning message to the console.
error(message)
Logs an error message to the console.
debug(message)
Logs a debug message to the console. This is visible only when 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:

Property
Description
turbineVersion
The Turbine version used inside the current library.
turbineBuildDate
The ISO 8601 date when the version of Turbine used inside the container was built.
buildDate
The ISO 8601 date when the current library was built.
environment
The environment for which this library was built. Possible values include 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:

Property
Description
id
The rule ID.
name
The rule name.
recommendation-more-help
12b4e4a9-5028-4d88-8ce6-64a580811743