Web Tracking API

From Genesys Documentation
Jump to: navigation, search
This topic is part of the manual Journey JavaScript SDK for version Current of Altocloud.

Learn how to track user activity via an API.

About the Web Tracking API

The Web Tracking API lets you track what visitors do on your website. Tracking data is collected through a series of interactions occurring on your website such as pageviews, button clicks, and custom events. These interactions are grouped into visits and act as a container for the actions taken on your website by a specific visitor.

Visits do not have a predefined duration. Depending on your visitor, the visit may be a few seconds or a couple of hours long. A new visit will be created when the visitor has been idle for 30 minutes or more, but they all will be linked to the same visitor.

Obtain consent before tracking visitors

Important
To be compliant with GDPR requirements, consider if you need to obtain a visitor's consent before tracking their data. For more information on using Altocloud in a GDPR-compliant manner, see GDPR.


To implement tracking after receiving consent, modify the tracking snippet so that the `ac('init')` and `ac('pageview')` are only called if consent is given, as shown in the following example:

 (function(a,t,c,l,o,u,d){a['_genesysJourneySdk']=o;a[o]=a[o]||function(){
  (a[o].q=a[o].q||[]).push(arguments)},a[o].l=1*new Date();u=t.createElement(c),
  d=t.getElementsByTagName(c)[0];u.async=1;u.src=l;u.charset='utf-8';d.parentNode.insertBefore(u,d)
  })(window, document, 'script', 'https://apps.inindca.com/journey/sdk/js/web/v1/ac.js', 'ac');
if (consentGiven) {
// Call the ac('init') function to enable tracking  
  ac('init', 'a061a3fe-7a80-4b50-9d3b-df88c0f9efad', { region: 'use1' });
  ac('pageview');
}

You are responsible for setting the value for the `consentGiven` variable based on the visitor's choice.


Enable web tracking

To enable Web tracking on your website, initialize the Tracking SDK and then call the pageview method when a visitor navigates to a new page.

Stop tracking if a visitor revokes consent

If a visitor revokes consent at any point, invoke the destroy command to stop tracking and remove all cookies, as shown in the following example.

// to disable tracking and delete Altocloud cookies
ac('destroy');

Types of tracked data

The Journey JavaScript SDK lets you customize how you collect tracking data for your website. The most basic form of tracking is page view tracking. For page view tracking, Altocloud records each page a visitor visits. You can also use the Journey JavaScript SDK to record custom visitor activities such as button clicks. For more information see Track custom events, below.


Track pages viewed by your customers

The pageview method tracks the pages viewed by your visitors. To send a pageview, call the ac function and pass pageview as the first argument.

ac('pageview');
Important
By default, the Altocloud tracking snippet contains the ac function.

Track custom events

The record method allows you to track custom events, usually as a result of a person interacting with an element or control in your website, for example, the click of a button. The record method takes two parameters:

  • The name of the event to record as a string. Note: See Guidelines for custom event names below.
  • An (optional) key-value hash of properties for the event.
  • An (optional) callback function that will be invoked when the request is completed.
  • An (optional) callback timeout, in milliseconds, to configure how long to wait if the event is taking too long to complete. This is useful to capture events (such as file downloads) before navigating to a different page/URL, making sure the visitor is always redirected.
 
ac('record', 'section_opened');

You may also provide extra metadata with your custom event:

 
ac('record', 'button_clicked', {
  companyName: 'Acme Inc,',
  employees: '100-500'
});

The following code sample shows how to record a file downloaded and navigate to the file URL /files/pricing.pdf when the event is captured, or after 400 milliseconds:

 
ac('record', 'file.downloaded', {
  name: 'Pricing',
  fileType: 'pdf'
}, function () {
  navigateTo('/files/pricing.pdf');
}, 400);


Guidelines for custom event names

Important
Event names must be a maximum of 255 characters. You can use any combination of lowercase alphanumeric characters and an underscore. Keep event names short and descriptive.

The suggested format for custom event names is: object-delimiter-action, where object is the object that was interacted with, and action is the type of interaction that occurred.

Examples of custom event names include:

  • "detected_errors"
  • "section_failed"
  • "section_submitted"
  • "product_added"
  • "product_removed"
  • "address_selected"
Retrieved from "https://all.docs.genesys.com/ATC/Current/SDK/Web_tracking_API (2020-08-08 06:26:21)"