Knowledge Base/Official Insight Help/Analysis (Reporting & Querying)

How do I add Google Analytics to my web site?

Justin Ruffell-Ward - Insight Support
posted this on December 12, 2010 20:10

Step 1 - Create Google Analytics account
Visit www.google.com/analytics to sign-up for a free account. Once you have successfully signed into your dashboard, you can ‘add a new profile’ to your account.

 

Step 2 - Add the Google Analytics tracking code to your site

Google retrieves its data by asking you to install a snippet of code into every page of the site you’d like to track. This ‘tracking code’ is provided to you during the process of adding the new site to your Analytics account. It will look something like this:

 

<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>

<script type="text/javascript">

try {

var pageTracker = _gat._getTracker("UA-3527014-3");

pageTracker._trackPageview();
} catch(err) {}</script>

 

As this requires you to add HTML code to your site, there are essentially two ways of achieving this as follows:

  • You can add an article component to your layout and set this to allow ‘raw HTML’.
  • Enter the code into a single article on your site – using the ‘view source’ option in the Document Editor – and then reference this in every layout.

Once you have successfully installed the ‘tracking code’, Google should start receiving data from your site after about 48-hours. Thereafter, the time lag will be drastically reduced to almost immediately.

 

Note: You’ll need to include the ‘tracking code; in every page you want to track, so this will mean applying the code to all layouts used for those pages.

 

Comments

User photo
Andy W

Google have improved there tracking code with the Google Analytics Asynchronous Tracking Code.  It's a snippet of JavaScript that loads the ga.js tracking code in the background while other scripts and content continue loading on your website pages.

One key difference between placements of the asynchronous tracking code and the traditional tracking snippet is the new asynchronous snippet is placed at the bottom of the <head> section of your HTML file or template. (The traditional snippet is placed at the bottom of your page, just before the closing </body> tag.)  This is because the asynchronous tracking snippet can execute without blocking other code or content.  So Google recommend placing it at the bottom of the <head> section for the best tracking results.

Is it currently possible to use the new tracking code and to also add it in the <head> section of templates?

<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>

 

Thanks


October 11, 2011 11:36