Getting started with REST Implementation

Tracker implementation by REST API is used by mobile applications on the server-side. You will have to use email addresses to call every user.

We are going the mention the endpoints for the events tracking in this document using the REST API. Like the Javascript(JS) implementation, the REST API allows you to track the events but JS allows you more functionality like:

  1. The Javascript tracker tracks the page views for you and it is an automated process while in Restful implementation you will have to run the events yourself.
  2. We won't be able to track the users who clicked on your emails.
  3. For Restful implementation, you will have to pass email to the call because this would identify the users.

Authentication

The Restful implementation requires an ma-key to authenticate which you can get from your Brevo account.

<script type="text/javascript">
(function() {
    window.sib = {
        equeue: [],
        client_key: "xx44x0iexxxjlk5xx44jrx8o"
    };
    /* OPTIONAL: email for identify request*/
    // window.sib.email_id = '[email protected]';
    window.sendinblue = {};
    for (var j = ['track', 'identify', 'trackLink', 'page'], i = 0; i < j.length; i++) {
    (function(k) {
        window.sendinblue[k] = function() {
            var arg = Array.prototype.slice.call(arguments);
            (window.sib[k] || function() {
                    var t = {};
                    t[k] = arg;
                    window.sib.equeue.push(t);
                })(arg[0], arg[1], arg[2], arg[3]);
            };
        })(j[i]);
    }
    var n = document.createElement("script"),
        i = document.getElementsByTagName("script")[0];
    n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page();
})();
</script>

You can find the below script in the Automation menu in your Brevo account under Javascript (JS) Tracker. The client_key mentioned in the Javascript code is your ma-key.

Frequently asked questions (FAQ)

When are new contacts created in my database?

We create new contacts in your database in two cases:

  • If you call the identify method with a valid email address.
  • If the contact enters a workflow (regardless of the event triggering the workflow).

The automation tracker does not recreate contacts which are already deleted by the platform as the deletion is permanent.

What are webhooks?

A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST.
You can create a webhook in your marketing automation scenario workflow by providing a unique web url. We will send a post request every time, your users reach webhook action node.

What are JS/API attributes?

These are user properties which can be sent via identify call. For e.g. in the following identify call, name, country, state are attributes.

sendinblue.identify('[email protected]', {
  'name': 'James Clear',
  'id': '10001',
  'mobile' : '+12025550153',
  'plan' : 'Diamond',
  'location' : 'San Francisco'
});

What are JS/API events?

These are custom track events which you can sent to us for various actions that your users take. e.g. following track event calls will create two events product_purchased and file_download.

sendinblue.track('product_purchased', {
  'plan': 'silver',
  'amount': '100'
});

What is the difference between Identify & Track events?

Identify call is used to let us know your customer by sending us unique customer Id, email Id and optional parameters like name, country etc.

sendinblue.identify('[email protected]', {
  'name': 'James Clear',
  'id': '10001',
  'mobile' : '+12025550153',
  'plan' : 'Diamond',
  'location' : 'San Francisco'
});

Track events are used to track specific actions taken by your users like product purchase, file download etc. You can use track function to let us know the actions taken by users.

A sample track event, when a user purchased any product can be called like this:

sendinblue.track('product_purchased', {
  'plan': 'silver',
  'amount': '100'
});

Errors

In case of an error occurs, the body will contain a code and a message field. The code field should be used to catch the error in your code while the message is there only to help the developer with debugging (its content may change over time).

HTTP response codes

A few HTTP response codes are mentioned below in the table.

Response codeDescription
204Successful request
400Bad request
401Authentication needed
403Permission denied
405Method not allowed