Plugins
The Ketch Smart Tag allows extending functionality by registering plugins. The plugin is a function that receives an instance of the Ketch Tag and the configuration of the plugin.
Plugin registration
To register a plugin, call ketch
with the registerPlugin
parameter, passing in the plugin function.
function myPlugin(host, _config) {
//host - is the reference to the Ketch Tag
//_config - is a JSON object containing all the neccessary information to configure the Ketch Smart Tag
}
ketch('registerPlugin', myPlugin);
Event scopes
The plugin architecture allows for the following scopes of event subscription within the Ketch Smart Tag:
method | description |
---|---|
on | to handle every occurrence of an event |
once | to handle just a single occurrence of an event |
off | to stop handling events |
example:
function myPlugin(host, _config) {
// Receive every consent change notification
host.on('consent', consent => {
console.log('consent changed to: ', consent);
});
// Receive only initial configuration get
host.once('geoip', geoip => {
console.log(geoip);
});
}
ketch('registerPlugin', myPlugin);
Events
The following are the events currently supports by the Ketch Smart Tag plugin architecture:
-
consent
The consent event is emitted whenever consent is resolved, either by loading from local storage, remote storage or by prompting the user.
The argument to the event is a consent object, where the keys are the purposes and the value is a boolean denoting whether the user has consented to the purpose.
{ analytics: true, marketing: false, ... }
-
environment
The environment event is emitted whenever the environment is resolved from configuration.
{ "code": "production", "hash": "8013869916755790322", "pattern": "Lio=" }
-
geoip
The geoip event is emitted whenever the location has been resolved from the IP address.
{ "city":"San Francisco", "continentCode":"NA", "continentName":"NA", "countryCode":"CA", "countryName":"United States", "ip":"98.22.154.141", "latitude":37.773972, "longitude":-122.431297, "regionCode":"CA", "regionName":"California", "zip":"94016" }
-
identities
The identities event is emitted whenever the identities collected about the user have changed.
{ "swb_axonic":"2fa52c03-f46b-4e63-a5b1-5ff68a69e41c", ... }
-
jurisdiction
The jurisdiction event is emitted whenever the jurisdiction of the user has resolved or changed. The event argument will be the code of the jurisdiction the visitor is found to be in.
-
regionInfo
The regionInfo event is emitted whenever the region information about the user has resolved or changed. The event argument will be the ISO-3166 country code the visitor is found to be in.
-
willShowExperience
The willShowExperience event is emitted when an experience is shown to the user. The event argument will be one of the following experience type codes:
code description experiences.consent consent experience will be shown experiences.preference preference management center experience will be shown -
hideExperience
The hideExperience event is emitted when an experience is hidden from the user. The event argument will be one of the following reasons the experience was hidden:
argument description setConsent experience was closed due to consent being set invokeRight experience was closed due to a right being invoked close experience was closed willNotShow it was determined an experience would not be shown (e.g. the users consent has already been collected)
Updated about 2 months ago