This is an old revision of the document!


Google Analytics Power User Tips

Google Analytics is the best free traffic analysis software available. It can handle pretty much any sized website (at least within reason), and has a number of fairly advanced capabilities.

Basic Install

Basic Install is pretty well covered by Google's Docs. Be sure to use the new ga.js code, not the old urchin.js code. Make sure that the tracking code appears once, and only once, on all of your pages. Preferably at the very bottom, right above the closing </body> tag.

Once you get that done, login and start looking at your reports. Note that (annoyingly) any configuration changes you make to your reports (e.g. apply a new filter, change your default homepage filename, etc.) only affect data from that day onward. You can't go back and reprocess old data.

Tracking Terminology

Google Analytics has five tracking areas: Dashboard, Visitors, Traffic Sources, Content and Goals.

In most reports, Google Analytics tracks pretty much everything via Visits, which is one person being active on the site. They can be active as long as they want, but as soon as they are inactive for 30min or more, their visit ends. If they come back, they are counted as a new visit. They also offer Visitors; these are unique across the entire time period you're looking at. So if somebody visited on Monday, and then visited again on Wednesday, they'd have two visits but be one visitor.

Pageviews counts the number of individual pages that has been viewed; a reload of a page means that page is counted again. Unique Pageviews filters out reloads (so if you reload a page ten times, that's ten pageviews but one unique pageview). Unique Pageviews only count across visits, meaning if someone views a page, waits 30 minutes (and thus their 'visit' ends), and then views the same page again, that is two unique pageviews (one from the first visit and one from the second visit).

Tracking Goals

Each GA profile gives you up to four Goals that you can track. You don't have to insert any special code into your pages for these; GA matches your goals based on the URL of the page. In my opinion, the best thing to do is to write regular expression matches against the URL; this allows you a lot of flexibility you wouldn't have otherwise.

For example, WHMCS 3.4.1 has a checkout process that can end on either creditcard.php?invoiceid=XXXX OR order.php?step=6. So, you'd make your Goal URL (order.php\?step\=6)|(creditcard\.php\?invoiceid\=[\d]*), which would match either page. If you make your Goal URL a regular expression, you need to make your goal steps the same, e.g. order\.php$, which matches any URL that ends in order.php.

Filters

Filters are one of the most powerful features of GA. They let you include or exclude certain pages/subdirectories, and do search and replace operations on URLs (or other variables).

The most important (and most annoying) thing about filters is that they run when the original data is collected, and ONLY when the original data is collected. If you make a mistake, or you just want to go retroactively apply a new filter to your data, you can't.

Power User Tips

Using Filters instead of Default Page

GA lets you set a 'default page' in the profile settings (e.g. index.html or index.php). It then converts any root level (/) requests to the equivalent default page URL (e.g. /index.php), and displays those in its reports. The problem is that sometimes you might have those files redirected, or they otherwise can't be accessed at /index.php. You also can't set more than one page to be your 'default page'.

A better solution is to setup a filter, which renames index.php, home.php, and whatever else you want to /. Then all of your URLS are listed in GA as /, which is more useful. To do this, setup a 'Search & Replace' filter on the 'Request URI'. Search for index\.php and replace with / .

Tracking Email via Google Analytics

You can use the GA campaign feature to track marketing campaigns, including email.

Google Records Cached Hits

If a user loads your page out of the Google Search cache, your Google Analytics code WILL run, and you'll record a hit for that page. Generally, this is probably OK… I think a cached hit is still a 'hit' on your site. If you don't want this to happen, you can setup a filter to filter out the cached traffic.

Using _setVar() to track Logged In Users

GA has a 'user defined' segment, and you can pass your own variable into it and then segment your reports on that variable. To do this, call _setVar() in your code:

// any user with $isLoggedIn set to true will have the user defined GA variable
// set to 'logged-in'
pageTracker._setVar(<?= $isLoggedIn ? "'logged-in'": "'logged-out'"; ?>);
pageTracker._trackPageview();

There are a few things to keep in mind:

  • There is only one user defined variable. If you call _setVar() again, it will overwrite the existing variable. There is a way to set more than one, but it is a bit cumbersome.
  • The variable is stored in the cookie, and thus is passed on subsequent GA pageviews. This can be good (you don't have to set it again) or bad (the status of the variable changes and you forget to update it). Just keep it in mind.
  • It should also be noted this variable is passed across entire visits. So if you set a visitor to 'logged-in' status ( _setVar('logged-in'); ) on his visit today, and he comes back tomorrow, tomorrow's visit will still be tagged with 'logged-in', even though you didn't explicitly set it again. As before, this can be good or bad, depending on what you want to do.
  • NOTE: If you use _setVar() on every page load, it will break the bounce rate calculation in GA. This is because _setVar() records a secret second pageview every time it is called. I wrote up some code to fix this 'zero bounce rate' problem, so _setVar() is only called once and then the value is read out of the cookie.

Record Data in More than One Profile

If you want, you can record data for the same hit in more than one profile (using codes UA-XXXXXX-1 and UA-YYYYYY-1 in this example):

<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">
var firstTracker = _gat._getTracker("UA-XXXXXX-1");
firstTracker._initData();
firstTracker._trackPageview();
var secondTracker = _gat._getTracker("UA-YYYYYY-1");
secondTracker._initData();
secondTracker._trackPageview();
</script>

Tracking Named Pageviews

If you want, you can inject a pageview into the Google Analytics stats. This is done by calling _trackPageview() again, but with an argument. Generally, you'll want to do this in an onclick, or similar:

<a href="#" onclick="pageTracker._trackPageview('/pages/foobar');">click to track the foobar page</a>

Needless to say, the main google code should have loaded before you try to call this function, but if you're putting it in an onclick, odds are that it has.

Google Analytics Validation Doesn't Like 301/302 Redirects

GA doesn't seem to like 301/302 redirects when validating tracking codes. It's a fairly common technique to redirect startupcto.com to www.startupcto.com (or vice versa). If you tell GA that your tracking code is on startupcto.com, and that redirects to www.startupcto.com, GA will never validate that you have properly installed your tracking code. You must set your Website URL to the non-redirected domain, e.g. www.startupcto.com.

Tracking Subdomains

There are numerous ways to track sub-domains in Google Analytics, but I think this one is the best. The basic idea is using one profile for all sub-domains, and then creatign sub-profiles (with filters applied) for each sub-domain.

Google Analytics API

The full GA API is available.

Discussion

Eoin, Aug 13, 2009 12:11 PM

Hi David, interesting post.
You mention at the start not to have the tracking code on a page more than once and i've just noticed a page on my site where this has happened. Do you know if this would have been inflating my traffic statistics?

David Ordal, Aug 18, 2009 12:16 AM

Hi Eoin-

Yes, if you have the tracking code on your page twice with the same UA-XXXXXX-X number, than each time a user views a single page, it will be recorded twice (as two page views) in Google Analytics. You definitely want to have it only once.

David

Madoka, Mar 29, 2012 04:01 AM

You get a lot of respect from me for writing these hpelful articles.

marketing-tech/google-analytics/power-user-tips-and-tricks.1220303467.txt.gz · Last modified: Sep 1, 2008 09:11 PM by dordal
© 2005-10 David Ordal / DO IT, LLC. All Rights Reserved.