How to Set up the tracking code (asynchronous) – Google Analytics Installation
BEFORE YOU BEGIN: If you’re already tracking your website using an older tracking snippet, first remove the older snippet. You can use a text or HTML editor on the file that contains the snippet and save it if you have customizations you want to add back in later. (Looking for the traditional snippet? See this article.)
Here’s how to add the asynchronous snippet to your site:
- Find the asynchronous snippet for your profile
The tracking code is profile-specific, so you can only access it from the Profile Settings screen for that profile. Go to Analytics Settings and click “Edit†next to the profile used for your site. In the Profile Settings page, click the “Check Status†link. You’ll see something similar to thecode snippet below, whereÂXXXXX-YYindicates the profile ID for your Analytics account.<script>  var _gaq = _gaq || [];  _gaq.push(['_setAccount', 'UA-XXXXX-X']);  _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);  })(); </script> - Copy and place the code snippet
Once you find the code snippet, copy and paste it into your web page, just before the closing</head>tag*. If your website uses templates to generate pages, enter it just before the closingÂ</head>tag in the file that contains theÂ<head>section. (Most websites re-use one file for common content, so it’s likely that you won’t have to place the code snippet on every single page of your website.)For the best performance across all browsers we suggest you position other scripts in your site in one of these ways:- before the tracking code snippet in the <head> section of your HTML
- after both the tracking code snippet and all page content (e.g. at the bottom of the HTML body)
- Verify and customize
Verify that your tracking code contains the correct web property ID for your profile (it should if you copied it from the Profile Settings screen). Double-check that the tracking snippet installed on your website matches the code shown in the profile. For more details on verifying your setup, see Verify your setup.Add any customizations back in using the asynchronous syntax. The Usage Guide and Migration Examples (English only) on Google Code provide many examples of customizations withasynchronous tracking.
*One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. It is customary to place JavaScript code in the <head> section, and we recommend placing the snippet at the bottom of the <head> section for best performance.
