Barion Pixel API reference

From Barion Documentation
Revision as of 10:13, 12 February 2019 by Nagyg (talk | contribs) (Figure 3)
Jump to navigation Jump to search

The Barion pixel is a snippet of JavaScript code that allows you to track visitor activity on your website. It works by loading a small library of functions which you can use whenever a site visitor takes an action that you want to track (called an event).

In order to implement the pixel, you will need:

  • access to your website's code base
  • your pixel's base code and associated IDs (barionPixelID)


The Barion pixel is a snippet of JavaScript code that loads a small library of functions you can use to track visitor activity on your website. It relies on Barion cookies. By default, the pixel will track URLs visited, domains visited, and the devices your visitors use. In addition, you can use the pixel's library of functions to track other events that are associated with webshop usage and ecommerce.

Base code

Before you can install the pixel, you will need your pixel's base code.

Figure 1


  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
   })(window, document, 'script', '', 'bat');
  // initialize the pixel
  bat('init', 'addBarionPixelId', 'barionPixelID');


  <img height="1" width="1" style="display:none" src="[Your ClientID goes here]&__ba_website_id=[Your WebsiteID goes here]&__ba_pixel_id=[Your Barion Pixel ID goes here]&ev=PageView&noscript=1"/>


When run, this code will download a library of functions which you can then use for tracking. It also automatically tracks a single PageView conversion by calling the bat() function each time it loads. We recommend that you leave this function call intact.

Installing The Pixel

To install the pixel, we highly recommend that you add its base code between the opening and closing <head> tags on every page where you will be tracking website visitor actions. Most developers add it to their website's persistent header, so it can be used on all pages, but it could be used before the closing body tag (</body>) as well.

Placing the code within your <head> tags reduces the chances of browsers or third-party code blocking the pixel's execution. It also executes the code sooner, increasing the chance that your visitors are tracked before they leave your page.

There are two ways to track conversions with the pixel:

  • standard events, which are visitor actions that we have defined and that you report by calling a pixel function
  • custom events, which are visitor actions that you have defined and that you report by calling a pixel function

Standard Events

Standard events are predefined visitor actions that correspond to common, conversion-related activities, such as searching for a product, viewing a product, or purchasing a product. Standard events support parameters, which allow you to include an object containing additional information about an event, such as product IDs, categories, and the number of products purchased.

In order to track an event the event needs to be fired, that is the corresponding event with its properties need to be added inside Your javascript or page. This can be seen on Figure 2 and Figure 3.

Figure 2

var contentViewProperties = {
    'id': 'My blog page',
    'contentType': 'Page',
    'name': 'Very cool product',
bat('track', 'contentView', contentViewProperties);

Figure 3


    // sample product data
    var addToCartPorperties = {
        'id': 'a',
        'contentType': 'Page',
        'name': 'a',
        'ean': 'a',
        'unitPrice': 1000,
        'totalItemPrice': 2000,
        'unit': 'kg',
        'currency': 'huf',
        'quantity': 2,   

    bat('track', 'addToCart', addToCartPorperties);


All standard events are tracked by calling the pixel's bat('track') function, with the event name, and a JSON object as its parameters (sometimes optional). For example, here's a function call to track when a visitor has completed a purchase event, with currency and value included as a parameter. (Figure 2)