Event plugin
This plugin is aimed to handle automatically event type tag.
As soon as the user interact with the page (click, touch), the event plugin will see if the element matches the attributes rules and then, send the tag automatically.
Initialization
event plugin needs to be declared to be taken into account by autoData.
autoData.init({
plugins: {
eventTracker: {
// your configuration here
attributePrefix: '',
trigger: '',
attributes: []
// if not set, default configuration is applied
}
}
});
All elements are optional, so event plugin can be declared empty.
autoData.init({
plugins: {
eventTracker: {}
}
});
attributePrefix (optional)
Attribute prefix used to parse attributes of interacted DOM element.
trigger (optional)
Attribute used for DOM selection by the plugin.
attributes (optional)
Set of attributes that should be collected on the trigger element in order to build the tag.
Default configuration
This default configuration is applied if all or part of elements are not set.
{
attributePrefix: 'data-event-',
trigger: 'obj',
attributes: ['act', 'desc', 'val']
}
Targeted DOM element have to carry data attributes, at least trigger attribute
<ANY data-event-obj="interacted object"
data-event-act="action"
data-event-desc="description"
data-event-val="value"/>
Trigger attribute is required to send tag.
If DOM element doesn't have some awaited data attributes, they aren't added to the tag.
Custom configuration example
{
attributePrefix: 'my-prefix-',
trigger: 'trigger',
attributes: ['val1', 'val2', 'val3','val4','val5']
}
<!-- One event -->
<ANY my-prefix-trigger="trigger_val1"
my-prefix-val1="val1"
my-prefix-val4="val4"/>
<!-- Another event -->
<ANY my-prefix-trigger="trigger_val2"
my-prefix-val2="val1"
my-prefix-val3="val4"
my-prefix-val5="val5"/>
Default object sent to the parser
{
event: 'click',
obj: 'interacted object',
act: 'action',
desc: 'description',
val: 'value'
}
Note : prefix is not used to define each key.
Tips
Event name override
By default, an event key with "click" value is added to tag to handle it in tag collector.
It can be overridden by using dedicated data attribute.
<ANY data-event-event="custom_event"
data-event-obj="interacted object"
data-event-act="action"
data-event-desc="description"
data-event-val="value"/>
Camelized attributes
Every attribute that is picked-up will be camelized by default, please look at the following example :
<ANY data-event-obj="interacted object"
data-event-custom-action-attribute="action"
data-event-val="value"/>
Result
{
obj: 'interacted object',
customActionAttribute: 'action',
val: 'value'
}
Manual tracking
If an event cannot be tracked automatically using data attributes, it can be handled by using a dedicated function from autodata API. See autoData.sendEvent