anna
anna

Reputation: 1011

Asynchronous Google analytics not working although I can see Real Time

I'm not getting any events through and I'm not sure why not.

As the reseller who we have asked to implement this script also has their own Google analytics script on their page there are two UA codes but I didn't think that this should be a problem but I'm not sure if some of the code is conflicting.

Here is the code in full:

function CaraConfig() {

    _gaq.push(['_setAccount', 'UA-30022982-26'],      //The GA account id (supplied by E-Tale)
        ['_setDomainName', 'none'],                             // the main page domain name
        ['_setAllowLinker', true],                                   // enables domain linking
        ['_setCampNameKey', 'etale'],                                 //tells us that this has come from us
        ['_setAllowHash', false],                                   //set to false so the cookie can be read
        ['_trackPageview']);
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39258562-1']);
// Recommended value by Google doc and has to before the trackPageView
_gaq.push(['_setSiteSpeedSampleRate', 5]);

_gaq.push(['_trackPageview']);


(function() {
    var ga = document.createElement('script'); 
    ga.type = 'text/javascript'; 
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s);
})(); 
    var _gaq = _gaq || [];


function CaraGetWidgetDescription(manufacturerWidget) {
    CaraConfig();
    _gaq.push(['_setCustomVar', 1, 'Widget Impression ID E-tale', String(manufacturerWidget)]);
}


function CaraAddToBasket(productName, sku) {

    CaraConfig();
    _gaq.push(['_trackEvent', String(productName), 'AddToBasket', String(sku)]);
}

function CaraBeginTransaction(orderNo, totalPrice) {

    CaraConfig();
    _gaq.push(['_addTrans', String(orderNo), "", CaraPriceFix(String(totalPrice)), "", "0.00", "", "", ""]);
}

function CaraAddTransactionItem(orderNo, sku, productName, productCategory, productPrice, quantity) {

    CaraConfig();
    _gaq.push(['_addItem',
        String(orderNo),
        String(sku),
        String(productName),
        String(productCategory),
        CaraPriceFix(String(productPrice)),
        String(quantity)]);
}

function CaraEndTransaction() {

    CaraConfig();
    _gaq.push(['_trackTrans']);
}

function CaraPriceFix(price) {

    var fixedPrice = price;

    var pLength = price.length;
    var comma = price.indexOf(",") + 1;
    var period = price.indexOf(".") + 1;

    //comma is in the price
    if (comma != 0) {
        //if the comma is not at a 2-decimal point position
        //i.e true for 1,200
        if ((pLength - comma) > 2) {
            fixedPrice = fixedPrice.replace(",", "");
        }
    }
    //period is in the price
    if (period != 0) {
        //if the period is not at a 2-decimal point position
        //i.e true for 1.200
        if ((pLength - period) > 2) {
            fixedPrice = fixedPrice.replace(".", "");
        }
    }
    return fixedPrice;
}

Edit:

I updated my code 4 days ago and since then I have been able to see Real Time events but still cannot see any actual reporting which seems odd. I know there's a lag but 4 days seems a bit much.

Upvotes: 0

Views: 249

Answers (1)

Fabio Phms
Fabio Phms

Reputation: 10204

This version of Google Analytics is deprecated; Consider migrating to the latest version.

For using two accounts on the same page you should use multiple trackers, as an example:

_gaq.push(
   ['_setAccount', 'UA-XXXXX-1'],
   ['_trackPageview'],
   ['b._setAccount', 'UA-XXXXX-2'],
   ['b._trackPageview']
);

All the commands from second tracker should be named with a prefix.

More details at Introduction to ga.js (Legacy) / One Push, Multiple Commands

Upvotes: 1

Related Questions