Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I've upgraded one primary page of a site to use the async version of the GA tracking code. Since the upgrade, number of visits has increased by 60%, avg. time on site has decreased by 40% and the bounce rate of the said page is now always zero. Pageviews are intact.

I suspect this has to do with using both the traditional and async snippets on the same profile.

Other than that, it's a pretty standard setup. Right before </body>*, I have this:

var _gaq = [['_setAccount', 'UA-XXXXXX-XX'], ['_trackPageview'], ['_setDomainName', 'domain.com'], ['_setAllowLinker', true], ['_setAllowHash', false], ['_setAllowAnchor', true]];
    (function (d, t) {
        var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.async = 1;
        g.src = ('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
        s.parentNode.insertBefore(g, s)
    } (document, 'script'));

Any other ideas, confirmations and suggestions?

*I know, it should go before </head>, will fix that in a new version.

share|improve this question

migrated from stackoverflow.com May 6 '11 at 13:31

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 2 down vote accepted

I notice that your calling _trackPageview before _setDomainName. That could cause some problems with the cookies. Try putting _trackPageview at the end of the command list and see if it solves the problem.

share|improve this answer
    
Nice catch! Forgot to mention this, but yeah, a consultant has also recommended to put _trackPageview at the end - Did that and I'll let you know of the effect after uploading the next version. –  Ronny May 5 '11 at 12:06
    
Thanks again Ewan and everyone else who noticed the commands order - The new version is up now, and this worked :-) –  Ronny May 31 '11 at 6:14

Yes, _setAccount has to be first (to define which account you send the data to) and _trackPageView or _trackEvent have to be last otherwise subsequent commands will not affect the request.

Also on a side-note AFAIK, the correct syntax is :

var _gaq = (['_setAccount', 'UA-XXXXXX-XX'], ['_trackPageview']);

with parentheses not

var _gaq = [['_setAccount', 'UA-XXXXXX-XX'], ['_trackPageview']];

with square brackets,

although your syntax seems to be working too (otherwise PageViews would not be counted at all).

share|improve this answer
    
Hey Antoine, thanks! Actually, I've based this optimized snippet on mathiasbynens.be/notes/async-analytics-snippet and it doesn't need parenthesis as this is a plain assignment, rather than a function invocation. –  Ronny May 7 '11 at 22:26

I would agree with what Ewan is saying, _trackPageview has to be the last of the arguments you call because the first arguments are rewriting the arguments or values that _trackPageview then sends to Google (or they are just adding arguments). So the additional or altered arguments need to be defined before you send them over to Google, otherwise you change them after they have already been sent and Google doesn't get noticed about it.

share|improve this answer

I had exactly the same problem when I added the async code to a site, it turns out I'd forgotten to remove the old code, so I had both the new and old code on every page. This was effectively recording two visits for every visitor, hence the traffic spike and the 0% bounce. I'd imagine you would have spotted that before posting here - but just in case, it might be worth another look at your page source.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.