Track custom events

The track function in tracker is used to cover the custom events mostly in the context of eCommerce shops like cart_updated events etc. There are three parameters for this function:

Brevo.track(
  event_name, /*mandatory*/
  properties, /*optional*/
  event_data /*optional*/
)

We will define the parameters for the track function here:

AttributeDatatypeDescriptionValue
event_nameStringCorresponds to the name of your event.var event_name = "cart_updated"
propertiesJSON objectProperties defines the state of the visitor.var properties = {
"email": "[email protected]",
"FIRSTNAME": "John",
"LASTNAME": "doe",
}
event_dataJSON objectA JSON object in which you can pass information about the event.Contains id and data mentioned below

📘

Objects in event_data

Some optional attributes for event_data are:

  1. id: An id is the unique identifier of an event. It can identify an object in your cart and whenever an item is added it is reflected on your Brevo account.
  2. data: You can pass any information related to your events like the currency in which you bought the products in your cart.

An example for event_data JSON object is mentioned below.

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"  
            }  
        ]  
    }  
}