Table of Contents

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:

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.

Set the campaign cookie timeout using setCookieTimeout()

You may want to set the campaign cookie timeout to something short (such as seven days) rather than the standard six months. For more, see the article on old campaign data appearing in new reports.

Google Analytics API

The full GA API is available.