Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

What is the right way to install google analytics? Async? Traditional? both?

Could someone with experience please shed some light on what is the best practice when installing google analytics tracking code?

Are there any cases where you would want to install both async tracking code and traditional? I'm taking a course on coursera in which they installed both the traditional and async code on the same .html file. Why would this be necessary?

Thank you.

2 Answers

John Locke
John Locke
15,479 Points


I don't think it is necessary to have the code twice. I always use async, and I never seem to have a problem with that method.

Thanks John. That's what I though but on this class on coursera (Stanford's Startup Engineering) Im taking the professor put both the traditional and the async code and I can't figure out why.

Here's the link to the example I'm speaking about incase somebody can figure out why it was done this way:


Thanks again John!

John Locke
John Locke
15,479 Points

They might have included both methods, but leave it up to the developer to use one or the other.

Thanks. I found this if anybody ever encounters any issues with this:

"The tricky part is that if you only use analytics.js and don't also use ga.js, the Analytics Admin page won't say 'Tracking Installed'. This is a bug on Google's end in terms of their documentation. You can debug your setup with this Google link: Verify your web tracking setup, though things should work if you followed the above instructions."

Derek Hanson
Derek Hanson
7,838 Points

Hi Sebastian,

After looking at the mentioned code for Google Analytics this isn't the async versus the traditional tracking. The code is actually split in half of an async code. The top to initialize the tracking and bottom to trigger events. The first and second half both need to be wrapped into their own script tags to work properly and may look like two different codes. The first half is trigger analytics so that your web analytics will load without slowing page time load. Then if you have other analytics events you want to track you can post it at the end of the page.

You should use ga.js as it is actually the current and flexible tracking code. To use the old one I believe is to say that it is more of a legacy code and if you operating the old tracking code you should upgrade. With that being said there is no reason to have both.

Hope this helps

Derek Hanson