-
Notifications
You must be signed in to change notification settings - Fork 5
Writing a Validation Function
An Assurance Validation Plugin is a single JavaScript function with the intent to validate one thing and one thing only. You can write JavaScript functions to validate your client configuration, event conditions, tests and use cases.
Validation functions will be passed an array of Assurance events. These events may be a subset of all the events in a session. In order to write a validation it will help to get familiar with the Assurance Event Definition and the data your client sends in the payload.
function validateEvents(events) {
console.log(events);
return {
message: 'PASSED!',
events: [],
result: 'matched'
};
}
It is recommended you start in the Validation Editor. There you can test your function with events from a session and debug and troubleshoot by logging to your browser's developer console.
In addition to events, validations can receive an optional argument that can be configured in the Assurance UI Validation Settings.
A validation function is expected to return an object that contains the following:
| Key | Type | Description |
|---|---|---|
message |
String | The validation message to display. |
events |
Array | An array of event uuids to be reported as matched or not matched. |
result |
'matched', 'not matched', 'unknown' | This is the validation result and is expected to be one of the enumerated strings. |
To assist you in writing validators, a number of global tools and libraries are available to help select, filter, and match events.
Currently this includes JOI and the Assurance Toolkit. In the future, assertion helper functions and other libraries will be added!
The global tools and libraries can be found under the global griffon variable.
The Assurance Toolkit is a simple library to help Assurance Plugin Developers build plugins.
The toolkit is found in the griffon.toolkit global variable. There you can find the core functions and schemas.
If you were validating an AEP v5 SDK Mobile client session and you wanted to find all track events your code might look something like the following:
function (events) {
const analyticsTrackEvents = events.filter(event => event.payload.ACPExtensionEventType === 'com.adobe.eventtype.generic.track');
...
}
With the toolkit it becomes a little easier to filter the same events
function (events) {
const { toolkit } = window.griffon;
const toolkitEvents = toolkit.match(toolkit['aep-mobile'].genericTrack.matcher, events);
...
}