Action types for edge extensions
In a tag rule, an action is something that is performed after the rule conditions have passed evaluation. Action types are provided by extensions, and their effects are entirely defined by the extension author.
As an example, an extension could provide a “show support chat” action type which could display a support chat dialog to help users who may be struggling while checking out.
This document covers how to define action types for an edge extension in Adobe Experience Platform.
Action types typically consist of the following:
- A view shown within the Experience Platform UI and Data Collection UI that allows users to modify settings for the action.
- A library module emitted within the tag runtime library to interpret the settings and perform an action.
For example, a module to forward some data to a third-party party endpoint may look like this.
module.exports = (context) {
const { arc, utils } = context;
const { fetch } = utils;
const { event: { xdm } } = arc;
return fetch('http://someendpoint.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(xdm)
})
};
If you want to make the endpoint configurable by the user, and allow the input and persistence of an endpoint to the settings object within the module, the object would look similar to this.
{
"endpoint": "http://someendpoint.com"
}
In order to operate on the user-defined endpoint, your module would need to change to the following example.
module.exports = (context) {
const { arc, utils } = context;
const { fetch } = utils;
const { event: { xdm } } = arc;
const { endpoint } = settings;
return fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(xdm)
})
};
Action result
The result returned by an action module can be anything. If the action needs to execute an asynchronous task, you can return a promise that returns the result you want once it resolves.
The action result is stored inside a ruleStash
key that is made available to all modules through the context
parameter (context.arc.ruleStash
). You can learn more about ruleStash
here.