Event Tracking with AFS Analytics

Event Tracking with AFS Analytics

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.

Capturing events with the command SEND

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:
  • 1.category: This field defines the category of the event (eg video). The alternate field eventCategory is supported to ensure compatibility with Google Analytics.
  • 2.action: This field specifies the type of action attached to the category (eg play). The name eventAction for this field is supported for compatibility with Google Analytics.
  • 3.label: This field gives a title to the event (eg My holiday video). EventLabel is supported to ensure compatibility with Google Analytics.
Optional fields:
  • 4.type: This field defines the type or additional information about the event. Optional field.
  • 5.url: This field defines a location for the event. Optional field.
  • 6.callback: Return function to call after transmission of the event to AFS Analytics servers. The function returns three parameters. The hitType, the event object and the params object. This parameter can be a function or a string containing the name of the function. Optional field.
  • 7.params: An object defined in the calling function to return as parameters in the return function. Optional field.

An empty string as a parameter tells analytics.js to use the default value.

Example of sending an event:
The following function tells AFS Analytics that a visitor has started watching a video:

aa ('send', 'event', 'video', 'play', 'My video');
The same command with an object as argument:
This example uses fields that are compatible with Google Analytics.

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.

The "Autotrack" option and the "datasets"

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');

Set the the datasets

The syntax of dataset in an HTML tag is as follows:

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


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 tags detected by autotrack

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.

"Click" event for click detection.

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');

Click detection using Autotrack and dataset

<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.

The "Download" event for detecting downloaded files.

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');

Detection of downloads with Autotrack and dataset

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.

The "Form" event for forms.

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:
1. Opening the form: open action

aa('send', 'event', 'form', 'open', 'My form');
2. Submitting the form: submit action

aa('send', 'event', 'form', 'submit', 'My form');
3. Submission results:
  • a. In case of success: successful
    aa('send', 'event', 'form', 'successful', ‘My form’);
  • b. In case of failure: failed
    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:
    • Information
    • Setting
    • Signup
    • Login
    • Contact
    • Logout

    Capturing forms with Autotrack

    This section of the document will be added later.

    The "Window" event for windows.

    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.

    The "Video" event for the videos.

    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'); 

    Capture the playback of a YouTube video with Autotrack and datasets.

    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 for alerts and debugging

    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:
    • Post: Always true, the alert appears in the report grouping the alerts.
    • Email: The alert is sent by email to the email address defined in AFS Analytics.
    • SMS: The alert is transmitted by SMS.
    • EmailandSms: The alert is sent by SMS and EMAIL.

    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 for tracking ad campaigns.

    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.

    Events related to e-commerce.

    The capture of sales and transactions related to e-commerce are described in the guide: "E-commerce Tracking"

    The predefined options accepted by AFS Analytics.

    AFS Analytics only accepts predefined "categories", "actions" and "types", here is a non-exhaustive list.

    Categories of events:

    Click, download, form, video, window, alert, and navigation


    None, Open, Close, Outbound, Inside, Send, Submit, Cancel, Canceledclose, Successful, Failed, Start, End, Proceed, View, Post, Email, SMS, EmailAndSMS, Play, Pause, Resume


    None, Button, Link, Div, iframe, Page, Information, Alert, Setting, Signup, Login, Warning, Fatal, Debug, Error, Contact, Logout, Menu

    The Next Steps:

    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.
    Ecommerce Tracking.
    Events tracking with Autotrack.

    This guide was updated on January 28th, 2017 by AFS Analytics, Web Analytics.

    By AFS Website Analytics.

    Go Top

    AFS Analytics uses LiveDisplay Tachnology