Track link clicks

trackLink() is the function used to track clicks on links on your website. A small duration of timeout is kept so the event logs can be generated or the page would change before the method is called. The function is something like this with link and properties as attributes.

Brevo.trackLink(
    link, /*mandatory*/
    properties /*optional*/
);

The attributes are mentioned below in a table.

AttributeDatatypeDescriptionValue
linkDOM elementIt is the DOM element that you want to trackdocument.getElementById('download_casestudy_a');
propertiesJSON objectIt is a JSON object where you can pass properties that describe click context or the visitors statepage title, last name, first name etc.

📘

Implement trackLink after the tag

trackLink() needs you to pass the DOM elements which should have been loaded before. Therefore it's better to implement trackLink() after the <body> tag while making sure that your DOM elements are already loaded.

Example:

An example is given below where you want to track if visitors downloaded a pdf file. If link is the DOM element you want to track clicks on, then your code would look like:

var link = document.getElementById('download_casestudy_a');

var properties = {
  'casestudy': 'A'
}

Brevo.trackLink(link, properties);