My favorites | English | Sign in

Google Analytics

Tracking Site Activity

The latest version of the Analytics tracking code offers an improved way to track website visitors with Google Analytics. It takes advantage of browser support for asynchronous JavaScript to enhance the speed in which the tracking code is loaded. With the latest version of the tracking code, you can also place the Analytics snippet higher in the page without delaying subsequent content from rendering.

Although asynchronous tracking uses a different Analytics snippet and a different syntax for tracking calls than the traditional snippet, it supports the exact same tracking customizations as the traditional snippet. In fact, the asynchronous tracking syntax is also more flexible than the traditional snippet. For more details, see the Usage Guide.

Use the Tracking Snippet to Track Your Website

The Analytics snippet is a small piece of JavaScript code that you paste into your pages. It activates Google Analytics tracking by inserting ga.js into the page. To use this on your pages, copy the code snippet below, replacing UA-XXXXX-X with your web property ID. Paste this snippet into your website template page so that it appears before the closing </head> tag.

If you need to do more than basic page tracking, see the tracking reference for a list of methods available in the API and see the Usage Guide for details on using the asynchronous syntax. For step-by-step instructions on setting up tracking, see the Help Center article on setting up tracking.

<script type="text/javascript">

 
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>

The snippet above represents the minimum configuration needed to track a page asynchronously. It uses _setAccount to set the page's web property ID and then calls _trackPageview to send the tracking data back to the Google Analytics servers.

Important: If you are updating your pages from the traditional snippet to the latest, asynchronous version, you should remove the existing tracking snippet first. We do not recommend using both snippets together on the same page. For migration instructions, see Migrating to Async.

Back to Top