The new Brevo javascript tracking api not working

Hello,
Today (maybe yesterday depending on the timezone) Brevo introduced the V2 javascript tracking. I tried the example code in the documentation, so my code should work. But it does not work at all.


<script src="https://cdn.brevo.com/js/sdk-loader.js" async></script>
<script>
    // Version: 2.0
    window.Brevo = window.Brevo || [];
    Brevo.push([
        "init",
        {
        client_key: "xy",
        // Optional: Add other initialization options, see documentation
        }
    ]);

var event_name = "cart_updated";
var properties = {
	"email": "john.doe@email.com",
	"FIRSTNAME": "John",
	"LASTNAME": "doe"
}

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

Brevo.push([
  "track",
  {
      event_name, 	/* mandatory */
      properties,	/* optional */
      event_data	/* optional */
  }
]);
</script>

And I get:

sa.js?key=xy:117 POST https://in-automate.brevo.com/p 400 (Bad Request)

Hi @WmSzl , thanks for posting on this community.

You’re right, the doc available here was not correct, it will be updated quickly (if not done already): Track custom events

The way you should use the « track » function is the following:

Brevo.push([
  "track",
  event_name, 	/* mandatory */
  { JSON object for properties }, 	/* optional */
  { JSON object for event_date } 	/* optional */
  }
]);

Now it’s working thanks