3 common Google Analytics tracking scenarios

Posted by
Posted in
Online Marketing, Google Analytics and Website Traffic
Share this post

There’s a whole lot of conflicting and confusing information out there when it comes to tracking your visitors with Google Analytics. To help you understand, here are 3 common scenarios you may encounter –

1. I want to track across a domain and its sub-domain(s)

For example, if you wanted to track information on your main website and online store – e.g. http://www.ireckon.com and http://store.ireckon.com

To track both your main website and store you would need to include the following code in the < HEAD > of both your domain (http://www.ireckon.com) and sub-domain (http://store.ireckon.com):

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'ireckon.com']);
_gaq.push(['_addIgnoredRef', 'ireckon.com']);


_addIgnoredRef is used to avoid self-referrals, and is essential for sub-domain tracking.

Where’s the period (.)?

You might notice that various documentation suggests using a period in front of your domain name, i.e. .ireckon.com. However, this leading period is known to cause cookie resets, which is bad news for sub-domain tracking.

A good rule of thumb to consider is to only use a leading period if you’re tracking across multiple-level sub-domains, e.g. new.store.ireckon.com. For a simple sub-domain like store.ireckon.com, you’re far better off using the method above with no period (or ‘dot’) before your domain name.

For more information on this topic, check out this fantastic article from Roir Evolution.

2. I want to track between my domain and a sub-directory
on an external domain

For example, if you wanted to track traffic between your main website and a blog or shop hosted by an external provider – e.g. http://www.ireckon.com and http://www.blogger.com/ireckonblog

To achieve this, you’d need to post the following code in the < HEAD > section of your website (e.g. http://www.ireckon.com):

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', 'ireckon.com']);

Then, in your < BODY > where any links to the external website occur, you should include the following onclick code:

< a href="www.blogger.com/ireckonblog" onclick="_gaq.push(['_link', 'www.blogger.com/ireckonblog']); return false;">View Ireckon's Blog< /a >
< form name="f" method="post" onsubmit="_gaq.push(['_linkByPost', this]);" >

Then, in the < HEAD > of your sub-directory page (e.g. http://www.blogger.com/ireckonblog), include the following:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);

3. I want to track a single sub-directory

For example, if you only have access to the sub-directory of a larger website, e.g. http://www.blogger.com/ireckonblog/, and want to track it independently.

In this instance, you’re not tracking the relationship between the main website and blog (like above), you’re tracking the blog independently.

Of course, you don’t want to track all the information coming through http://www.blogger.com/ – you only care about the information relevant to your blog (i.e. the sub-directory /ireckonblog/).

To achieve this, first set a Cookie Path Function in your code, which goes in the < HEAD > of your page:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setCookiePath', '/ireckonblog/']);

Then, you’ll need to set up a predefined filter in your Google Analytics settings to include only traffic to a subdirectory. You can find instructions on how to do this here.

Cookies? Aren’t they something you eat?

Cookies are files which are stored on your users’ computer. They hold data specific to that client and your website, which allows the server to deliver a page tailored to a particular user, or the page itself can contain some script which is aware of the data in the cookie and so is able to carry information from one visit to the website (or related site) to the next.

What about tracking a single sub-directory on my own domain?

If you want to track a single sub-directory that exists on your own domain (e.g. www.ireckon.com/ireckonblog/), you can use the same steps as above, but you’ll also need to make sure that Analytics tracking is disabled for the root path of your website.

Related Post

How can I increase Sales for my Small Business website with Conversion Optimisation?

Read now


  1. Hi, useful article. I want to do something similar to your second and third option: I’d like to track traffic from my sub-directory on an external URL and for this to be included in my own Google Analytics stats for mydomian.com as if it was part of my site.
    I’m a bit confused as to what code snippet I put on my site and what snippet I put on the sub-directory (i.e. when to use setDomainName and when to use setCookiePath). Can you help?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>