Install New Google Analytics Tracking Code
Brief overview of Google Analytics tracking code and how to set it up properly
Google Analytics (GA) is a web analytics tool that works based on the page tagging method. To set up Google Analytics on your website, you need to tag individual web page with the tracking code (written in Javascript). When a tagged web page is open in the web browser, the tracking code is triggered and begins to collect web traffic data. The tracking code, thus, is the center of Google Analytics. Properly installing it on your site will be the first essential step in using this application.
Google Analytics tracking code changes over time
Like everything else, Google Analytics has changed over time, and so has the tracking code. The latest version of the tracking code is the asynchronous tracking code. Before that, we had the traditional tracking code, and even before that we had the Urchin tracking code.
If you have just started using Google Analytics, you will most likely use the latest asynchronous version. However, if you inherit the website from ex- web designer/employee, it’s possible your site was tagged with the traditional tracking code. If you’re not clear, continue reading to see where you can find the tracking code in the new Google Analytics interface, what tracking code your site is using, whether it’s easy to switch to the latest version and how to set it up.
Google Analytics tracking code versions and how to use
| Asynchronous tracking code | Traditional/legacy tracking code |
|---|---|
|
<script type=”text/javascript”> |
<script type=”text/javascript”> |
| Install asynchronous tracking code | Install traditional/legacy tracking code |
|
In the new Google Analytics interface, the tracking code can be found by clicking on the “Settings” (gear wheel) icon located at the top right of the orange bar. Copy and paste the tracking code to right above the closing head tag </head> in all web pages that you want to track |
Copy and paste the tracking code to right above the closing body tag </body> in all web pages that you want to track |
| Track event and pageview with asynchronous code | Track event and pageview with traditional/legacy code |
|
Track event |
Track event |
Should you switch to the latest tracking code?
As you can tell from above, the asynchronous and legacy tracking codes are coded differently. As a result, the javascript onclick event to track event and track pageview are also different. Thus, although it’s recommended to use the latest and greatest tracking code by switching to the asynchronous version, you need to make sure you’ll have time to update all onclick events accordingly. If you forget updating the onclicks, your event and pageview tracking will no longer work.
Also, the recommended place to put the asynchronous tracking code is above the closing </head> tag (not above the closing </body> tag as in the legacy version), this means that when switching, you’ll need to move the tracking from the bottom of the page to the top of the page. Depending on how your site is set up, this may require the permission/right to access the page template header and footer. Many times, it’s not as easy as it sounds.
Google has a wealth of information on its website. Here is the details on how to set up the tracking code (asynchronous), if you want more information.
Hope this is helpful!
One Response to 'Install New Google Analytics Tracking Code'
Subscribe to comments with RSS or TrackBack to 'Install New Google Analytics Tracking Code'.
-
Kenny Lam
29 Dec 11 at 10:03 pm
Question, feedback or comment? Use the following form.
If you have a general suggestion, question, or comment not related to this post, please use the Contact us form.



Thanks for pointing out the difference between the new and old Google analytics tracker. My site is using the old tracker and I tried to tag my links as with the new one, so it didn’t work. Now I know why.
Cheers!