Google Tag Manager

Variables

Constants

{{Makaira Tracking ID}} is provided by Makaira Support

Data Layer Variables (DLV)

{{DLV - addedToCart}} Object: Product added to the shopping cart with fields `sku`,`name`, `price` (unit price), `category` (category title) and `quantity`.
{{DLV - totalCartValue}} Float: Total basket value in the current currency
{{DLV - order}} Object: An order with the fields id, revenue, subtotal, tax, shippingtotal, discounttotal and products (purchased products - respectively `name`, `price` (unit price), `category` (category title) and `quantity` as well as `sku`)
{{DLV - pageType}} String: type of page - either `product` (product detail page) or `category` (category page) or `searchresults` (search results page)
{{DLV - pageType}} String: type of page - either `product` (product detail page) or `category` (category page) or `searchresults` (search results page)
{{DLV - category}} String: category name of the current category (on category page)
{{DLV - search}} Object: Search `searchTerm` (search term) `resultCount` (number of search results)
{{DLV - experiments}} Array of Objects: `experiment` (Experiment ID) `variation` (Experiment Variation)
(Can be read 1:1 from the Makaira API response (key: `experiments`) and passed to GTM)

Tags

Makaira Tracking - Base Tag

Type: Custom HTML
Trigger: All Pages

<script type="text/javascript">
  var _paq = window._paq || [];
  
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="https://piwik.makaira.io/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {{Makaira Tracking ID}}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>

Makaira Tracking - AddToCart

Type: Custom HTML
Trigger:  addToCart - Custom Event

<script type="text/javascript">
(function() {
  console.log('3PT - Piwik - AddToCart Tag');
  if (typeof window._paq  === 'object') {
    var product = {{DLV - addedToCart}}
    _paq.push(["addEcommerceItem",product.sku,product.name,product.category,product.price,product.quantity])
    _paq.push(["trackEcommerceCartUpdate",{{DLV - totalCartValue}}]);
  }
})();  
</script>

Makaira Tracking - Purchase

Type: Custom HTML
Trigger: Pages witj thank-you-URL or Custom Event - Purchase 

<script type="text/javascript">
(function() {  
  if (typeof window._paq  === 'object') {
    var order = {{DLV - order}};
    var order_items = order.products;
    for(var i = 0; i < order_items.length; i++){
      _paq.push(["addEcommerceItem", order_items[i].sku, order_items[i].name, order_items[i].category, order_items[i].price, order_items[i].quantity]);
    }
    _paq.push(["trackEcommerceOrder", order.id, order.revenue, order.subtotal, order.tax, order.shippingtotal, order.discounttotal]);  
    _paq.push(["trackPageView"]);
  }
})();  
</script>

Makaira Tracking - Category, Product Detail

Type: Custom HTML
Trigger: Pages with detail URL pattern and category URL pattern or ProductDetailView & ProductImpression - Custom Events

<script type="text/javascript">
(function() {
  var trackView = false;
  var arg1, arg2, arg3;
    
  if (typeof window._paq  === 'object') {
    switch ({{DLV - pageType}}) {
      case ('category'):
        var cat = {{DLV - category}};
        arg1 = false;
        arg2 = false;
        arg3 = cat;
        trackView = true;
        break;
    
      case ('product'):
        var prod = {{DLV - product}};
        arg1 = prod.sku;
        arg2 = prod.name;
        arg3 = prod.brand;
        trackView = true;
        break;
    }
    if (trackView) {
      _paq.push(['setEcommerceView', arg1, arg2, arg3]);
      _paq.push(['trackPageView']);
    }
  }
})();  
</script>

Site Search Tag

Type: Custom HTML
Trigger: Pages with search page URL pattern or SearchResultView - Custom Event

<script type="text/javascript">
(function() {
  var trackView = false;
  var arg1, arg2, arg3;
  
  if (typeof window._paq  === 'object') {    
    switch ({{DLV - pageType}}) {
      case ('searchresults'):
        arg1 = {{DLV - search.searchTerm}};
        arg2 = false;
        arg3 = {{DLV - search.resultCount}};
        trackView = true;
        break;
    }
    if (trackView) {
      _paq.push(['deleteCustomVariables', 'page']);
      _paq.push(['trackSiteSearch', arg1, arg2, arg3]);
      _paq.push(['trackPageView']);
    }
  }
})();  
</script>

Makaira Tracking - A/B-Testing

Type: Custom HTML
Trigger: All Pages

<script type="text/javascript">
(function() {  
  if (typeof window._paq  === 'object') {
    var experiments = {{DLV - experiments}};
    for(var i = 0; i < experiments.length; i++){
    	_paq.push(['trackEvent', 'abtesting', experiments[i].experiment, experiments[i].variation]);
    }
  }
})();  
</script>