Track custom events

The track() function is what you need to use in order to collect any custom event you wish such as a cart updated event, order proceeded, item bookmarked, etc.

This function can accept 3 kinds of entries:

  • Event name [required]
  • Properties [optional]
  • Event data [optional]
sendinblue.track(
  event_name, /*mandatory*/
  properties, /*optional*/
  event_data /*optional*/
)

We will go over the 3 entries outlined above:

1. Event name

The event_name field corresponds to the name you want to give to your event (ex. "cart_updated" or "order proceeded")

Example:

var event_name = "cart_updated"

2. Properties

properties is a JSON object that describes the state of the visitor such as their email, age, gender, and location.

💡It's common to pass on the user/visitor attributes (first name, last name, etc.) to the properties object to update the corresponding contact's attributes on Sendinblue.

Example:

var properties = {
    "email": "[email protected]",
    "FIRSTNAME": "Thomas",
    "LASTNAME": "Bianchi",
}

📘

Properties and Contacts attributes

As you may notice, there is some similarity between Contacts attributes and the information you can pass onto the Properties object. Indeed:

3. Event data

event_data is a JSON object in which you can pass on information about a transaction. It is composed of two optional entries:

  • id (optional): It is the unique identifier of the event. For instance, it can be the unique identifier of the cart object on your website, so that every time the user adds an object to their cart it's reflected on Sendinblue.
  • data (optional): Here you can pass on any information related to your transaction. For instance, the details of all the products in the cart of your client.

Example:
In the case of a visitor who purchased 2 Black shoes and 1 White shirt, the event data object would be the following:

var event_data = {
    "id": "cart:1234",
    "data": {
        "total": 280,
        "currency": "USD",
        "url": "www.example.com",
        "items": [{
                "name": "Black shoes",
                "price": 90,
                "quantity": 2,
                "url": "www.example.com/black-shoes",
                "image": "www.example.com/black-shoes.jpg"
            },
            {
                "name": "White shirt",
                "price": 100,
                "quantity": 1,
                "url": "www.example.com/shirt",
                "image": "www.example.com/shirt.jpg"
            }
        ]
    }
}