Getting started with the boxalino tracking in Google Tag Manager

If you want to integrate the boxalino tracking in your Google Tag Manager account, create a new tag and add the following HTML-Code, making sure, that you replace your account and domain names (marked bold in the example below):

<script type=”text/javascript”>
var _bxq = _bxq || [];
        _bxq.push(['setAccount', 'your-account-name']);
        _bxq.push(['setCookieDomain', 'example.com']);
        _bxq.push(['trackPageView']);
if (typeof google_tag_params != "undefined" && typeof google_tag_params.ecomm_prodid != "undefined") {
        _bxq.push(['trackProductView', google_tag_params.ecomm_prodid]);
}
if($("#googleAnalytics").length > 0) {
    var jsCode = $("#googleAnalytics").text();
    var jsCodeByLine = jsCode.split("\n"),
        product = [],
        transaction = "",
        tmp = "";

    $.each(jsCodeByLine, function (index, value) {
        if (value.indexOf("ecommerce:addItem") != -1) {
            tmp = value.match(/(addItem",)(.*)\)/);
            tmp = JSON.parse(tmp[2]);
            product.push({product: tmp.sku, quantity: tmp.quantity, price: tmp.price});
        }

        if (value.indexOf("ecommerce:addTransaction") != -1) {
            tmp = value.match(/(addTransaction",)(.*)\)/);
            transaction = JSON.parse(tmp[2]);
        }
    });
    if(product.length > 0 && typeof transaction.revenue != "undefined" && typeof transaction.currencyCode != "undefined" && typeof transaction.id != "undefined") {
        _bxq.push([
            'trackPurchase',
            transaction.revenue,
            transaction.currencyCode,
            product,
            transaction.id
        ]);
    }
}
        (function(){
            var s = document.createElement('script');                         
            s.async = 1;
            s.src = '//cdn.bx-cloud.com/frontend/rc/js/ba.min.js';
            document.getElementsByTagName('head')[0].appendChild(s);
        })();       
</script>

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk