0
votes

I am trying to track a custom PHP based donation form data using analytics.js and ecommerce.js from Google Analytics

Here is my Output

`
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-xxxxxxxx-x', 'auto');
    ga('send', 'pageview');
    ga('require', 'displayfeatures');
    ga('require', 'ecommerce', 'ecommerce.js');

    function trackEcommerce() {
    this._addTrans = addTrans;
    this._addItem = addItems;
    this._trackTrans = trackTrans;
    }
    function addTrans(orderID,store,total,tax,shipping,city,state,country) {
    ga('ecommerce:addTransaction', {
        '120573112734': orderID,
        'Donation': store,
        '10.00': total,
        '': tax,
        '': shipping,
        'test',: city,
        'test': state,
        'test': country
    });
    }
    function addItems(orderID,sku,product,variation,price,qty) {
    ga('ecommerce:addItem', {
        '120573112734': orderID,
        'Donate': sku,
        'Donation': product,
        'none': variation,
        '1.00': price,
        '1': qty
    });
    }
    function trackTrans() {
        ga('ecommerce:send');
    }
    var pageTracker = new trackEcommerce();
`

I am not sure why this data is not being captured in Google Analytics E-commerce section, While I can see the stats on my Thank You page in Google Analytics

Please help If I am not doing it correctly. Thanks Again.

1
it takes 24 hours for data to finish processing how long did you wait?DaImTo
I did some transaction last day Now I am again looking at it, It's Not there :( While My other products on same domain from Woo-Commarece are coming as usual and in real-time.Shiva

1 Answers

1
votes

Your objects have the values as the name instead of the actual property name.

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-xxxxxxxx-x', 'auto');
ga('send', 'pageview');
ga('require', 'displayfeatures');
ga('require', 'ecommerce', 'ecommerce.js');

// Note the different names on the object properties? 
ga('ecommerce:addTransaction', {
    'orderID': '120573112734',
    'store': 'Donation',
    'total': '10.00',
    'tax': '',
    'shipping': '',
    'city': 'test',
    'state': 'test',
    'country': 'test'
});
ga('ecommerce:addItem', {
    'orderID': '120573112734',
    'sku': 'Donate',
    'product': 'Donation',
    'variation': 'none',
    'price': '1.00',
    'qty': '1'
});
ga('ecommerce:send');