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:

  1. 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-YY indicates 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>
  2. 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)
  3. 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.

Post By Gishore J Kallarackal (2,121 Posts)

Gishore J Kallarackal is the founder of techgurulive. The purpose of this site is to share information about free resources that techies can use for reference. You can follow me on the social web, subscribe to the RSS Feed or sign up for the email newsletter for your daily dose of tech tips & tutorials. You can content me via @twitter or e-mail.

Website: → Techgurulive

Connect