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
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?
John Locke15,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.
Derek Hanson7,838 Points
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