Tracking events allows you to measure the interactions between the visitors and the pages of a website. This information reveals design flaws and allow to improve the user experience and navigation of visitors.
Events are sent to AFS Analytics via the send command or automatically detected by activating the autotrack option.
This guide explains how to use the send command to send events to AFS Analytics.
Note: Categories, actions or types must be specified in English.
The use of the send command coupled to the call type event sends an event to AFS Analytics.
Here is the simplified syntax of the command:
aa('send', 'event', [category], [action], [label], [type], [url], [callback], [params]);
Required fields:
An empty string as a parameter tells analytics.js to use the default value.
Example of sending an event:
aa ('send', 'event', 'video', 'play', 'My video');
The same command with an object as argument:
aa ('send', {
HitType: 'event',
EventCategory: 'Video',
EventAction: 'play',
EventLabel: 'My video'
});
AFS Analytics version:
Function mycallback (a, b, c) {console.log (a, b, c); }
Aa ('send', {
HitType: 'event',
EventCategory: 'video',
EventAction: 'stop',
EventLabel: 'My video test',
EventType: "all",
EventUrl: 'http: //www.afsanalytics/mavideo.avi',
HitCallback: mycallback,
Params: {message: "this has been sent"}
});
Note: Do not confuse the hitType field with the type field.
In the following examples, you will find a version using autotrack and datasets. The examples work if the autotrack option is set to dataset or on".
If you have any doubts about setting the autotrack option, add the following line initializing autotrack in datase mode after the tracker is created.
aa('Set', 'autotrack', 'dataset');
data-[datasetprefix]-[name of the field]= ‘value of the field’
Note: datasetprefix is a variable defined with the default aa in analytics.js. It can be modified using the set option.
Example of initialization of the category field
data-aa-category=’click’
The datasets fields are those specific to AFS Analytics. That is to say hittype, category, action, label, url, callback,params;
In the datasets, only the category and label fields are mandatory. The action field may be recommended for certain types of events. Other fields are usually detected. By default the hitType field is set to event.
The Autotrack option detects the datasets of the a, div, button, iframe, form tags.
Example of using dataset in a youtube iframe.
<Iframe width = "480" height = "280" src = "https://www.youtube.com/embed/cnBtRh08ShQ?rel=0" frameborder = "0" data-aa-category = 'video' data-aa -action = 'start' data-aa-label = 'Advanced visitor tracking'> </ iframe>
With each click on the video, the event will be captured by AFS Analytics.
If the action field is empty, analytics.js will automatically detect the type of the click: inside or outbound. If the url field is not specified, it will be replaced by none.
aa{'send', 'event', 'click', 'inside', 'My click');
For an outbound click:
aa('send', 'event', 'click', 'outbound', 'My click');
<a href="https://afsanalytics.com" data-aa-hitType="event" data-aa-category="click" data-aa-label="my super click" >my super click</a>
Note: AFS Analytics will automatically detect the url, type and action fields if they are not defined in the datasets.
While sending a downloaded file, it is transmitted to analytics.js via the category Download. As the type field is not used, the value none is indicated, the URL field indicates the location of the file.
aa('send', 'event', 'download', 'successful', 'My file','none','http://mysite.com/mypdf.pdf');
With the autotrack option and the datasets, the url and type fields do not need to be filled in
<a href="http://mysite.com/myfile.pdf" data-aa-hitType="event" data-aa-category="download" data-aa-label="my super pdf file" data-aa-callback="mycallback" data-aa-params="{message:'test'}" >myfile.pdf</a>
Note: The passage of the callback function that will be called after sending the event to analytics.js. The URL doesn't need to be specified in the dataset, it is already within the a href tag.
AFS Analytics can detect events related to filling forms. If the events are sent correctly, AFS will calculate the average fill time and the dropout rate. The form category is reserved for the form.
The various steps of filling in a form are:
aa('send', 'event', 'form', 'open', 'My form');
2. Submitting the form: submit action
aa('send', 'event', 'form', 'submit', 'My form');
3. Submission results:
aa('send', 'event', 'form', 'successful', ‘My form’);
aa('send', 'event', 'form', 'failed', ‘My form’);
4. Closing the form: close
aa('send', 'event', 'form', 'close', 'My form');
In case the form is closed with a cancel button: cancel and close
aa('send', 'event', 'form', 'cancel', 'My form');
aa('send', 'event', 'form', 'close', 'My form');
or using the action: cancelandclose
aa('send', 'event', 'form', 'cancelandclose', 'My form');
If the open and close actions were correctly defined, the average viewing time of the window will be displayed on the dashboard.
The values of the type field associated with the form:
By adding the "type" parameter you can define the form type. The available options are:This section of the document will be added later.
The window event offers two actions: open and close.
1. Open the window: open
aa('send', 'event', 'window', 'open', 'My window');
2. Close with close
aa('send', 'event', 'window', 'close', 'My window');
If the actions open and close were correctly defined, the average time to view the window will be displayed on the dashboard.
Four actions are offered for the Window event: start, pause, resume, stop. The start action can be replaced by play, the library analytics.js accepts both possibilities.
1. The user starts playing the video:
aa('send', 'event', 'video', 'start', 'My video');
2. The user clicks the pause button.
aa('send', 'event', 'video', 'pause', 'My video');
3. The user resumes playback of the video
aa('send', 'event', 'video', 'resume', 'My video');
3. The video is finished or the user stops the video.
aa('send', 'event', 'video', 'stop', 'My video');
As mentioned above, the play action can be used as an alternative to the start action.
<iframe src="https://www.youtube.com/embed/cnBtRh08ShQ?rel=0" frameborder="0" data-aa-category='video' data-aa-action='play' data-aa-label='AFS Analytics vidéo'></iframe>
The alert event is very useful for sending custom alert messages to AFS Analytics. Many global companies use a dedicated AFS Analytics account to capture their site's bugs. This option, used by web agencies to ensure the reliability of the developed sites, allows for each alert to consult the form and the configuration of the visitor who generated the error.
Actions available for the Alert event:For the type of alert, it is possible to choose between warning, debug, error or fatal.
aa('send', 'event', 'alert', 'post', JavaScript routine error', 'fatal');
The campaign event is generated automatically by analytics.js using the utm parameters present in the query string of the page. Please refer to the "Measuring online marketing campaign performance" guide for more information.
The capture of sales and transactions related to e-commerce are described in the guide: "E-commerce Tracking"
AFS Analytics only accepts predefined "categories", "actions" and "types", here is a non-exhaustive list.
This guide taught you how to capture events with analytics.js. To continue your training, the following guides are recommended:
Measuring online marketing campaign performance.This guide was updated on January 28th, 2017 by AFS Analytics, Web Analytics.