Condition types for web extensions
In the context of a rule, a condition is evaluated after an event has occurred. All conditions must return true in order for the rule to continue processing. The exception is when users explicitly place conditions into an “exception” bucket, in which case all conditions within the bucket must return false for the rule to continue processing.
As an example, an extension could provide a “viewport contains” condition type wherein the user could specify a CSS selector. When the condition is evaluated on the client’s website, the extension would be able to find elements matching the CSS selector and return whether any of them are contained within the user’s viewport.
This document covers how to define condition types for a web extension in Adobe Experience Platform.
Condition 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 condition.
- A library module emitted within the tag runtime library to interpret the settings and evaluate a condition.
A condition-type library module has one goal: evaluate whether something is true or false. What it evaluates is up to you.
For example, if you wanted to evaluate whether the user is on the host example.com
, your module may look like this:
module.exports = function(settings) {
return document.location.hostname === 'example.com';
};
Now, consider a situation where you want to make the hostname configurable by the Adobe Experience Platform user. You may allow the user to input a hostname and then save the hostname to the settings object. The object might look something like this:
{
"hostname": "example.com"
}
In order to operate on the user-defined hostname, your module would need to change to this:
module.exports = function(settings) {
return document.location.hostname === settings.hostname;
};
Contextual event data
A second argument is passed to your module which contains contextual information regarding the event that fired the rule. It may be beneficial in certain cases and can be accessed as follows:
module.exports = function(settings, event) {
// event contains information regarding the event that fired the rule
};
The event
object must contain the following properties:
$type
youtube.play
.$rule
An object containing information about the currently executing rule. The object must contain the following sub-properties:
id
: The ID of the currently executing rule.name
: The name of the currently executing rule.
The extension providing the event type that triggered the rule may optionally add any other useful information to this event
object.