Google Analytics Tracking Code Basics and Time Saving&nbspPlugins

The author's views are entirely his or her own (excluding the unlikely event of hypnosis) and may not always reflect the views of Moz.

The analytics ninja is not dead, but with Avinash talking more about SEO analytics and SEOs like Rand talking more about web analytics, 2010 has brought with it increased cross-pollination between analytics experts and SEOs.

This blog post is for the analytics driven, SEO savvy, search samurai looking to implement tracking code best practices and take advantage of some useful Google Analytics plugins.

The focus of this post is on Google Analytics, but many of the concepts are also applicable more generally, no matter what web analytics platform you're using.

Tracking Code Basics

Asynchronous Tracking Code - Even before the asynchronous tracking code was rolled out, I was a believer in putting the GA tracking code in the header, rather than before the closing body tag, which is where Google recommends placing the tracking code. With the announcement of asynchronous tracking code, which loads in conjunction with the page as opposed to sequentially, however, you can now have your cake and eat it too. You can get the benefit of your data not being compromised by slow page load times and also keep from getting push back from the developer that implements your tracking codes.

Expanding Goal Limitations - Without setting up goals, your GA account is a glorified hit counter. So it's imperative that you set up goal or eCommerce tracking (if not both). When setting up your GA goals in your analytics settings, you can either use the expanded goals, which allow you to track up to 20 different URLs or engagement metrics per profile. It's important to realize, however, that you can also set your goals up so you can track hundreds or even thousands of goals. All you have to do is set up a logical hierarchy where the root of your goal URLs trigger your goal events. For us at SEOmoz, this might mean we have a tool run goal event triggered with /goal/tool-run - yet we also have the added granularity down to the individual tool level should we ever want to see which tools are being run the most or to segment traffic based on visitors who ran a particular tool.

Custom Variables for Registered & Non-Registered - One of the most powerful aspects of GA is the ability to set custom variable. Custom variables can be set at any of three levels (visitor, session, & page). The Google Analytics help documentation is particularly great, but EpikOne also has a worthwhile description on how custom variables work. The most powerful of these is the visitor level custom variable which allows you to cookie a visitor across multiple sessions. At SEOmoz, we use this to track three different member types: free members, PRO members, & canceled members. We also use custom variables to cookie at the session level.

Campaign Tagging & SetAllowAnchor - From widgets to newsletters to signature links in personal e-mails, campaign links should be tagged using the GA URL builder, which gives you tracking parameters that includes multiple, including required _utm values for source, medium, & campaign. In action this looks something like this:

https://moz.com/?utm_source=newsletter&utm_medium=email&utm_campaign=march-6-2010
When tagging your campaigns be aware thatby default GA will only recognize tracking parameters if the string is kicked off by a question mark, which from an SEO standpoint can lead to diffusion of link juice and duplicate content issues. To avoid these issues, we you can kick off campaign parameters with the hash tag and modify your GA tracking code using the SetAllowAnchor attribute, so GA recognizes the hash tag as way to kick off a campaign tracking URLs. To do this, add -- pageTracker._setAllowAnchor(true); -- to your main GA tracking code between the var pageTracker and pageTracker attributes. Or, for additional documentation, read LunaMetrics' blog post on using SetAllowAnchor, but the code should look something like this:
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-0000000-1");
pageTracker._setAllowAnchor(true);
pageTracker._trackPageview();
} catch(err) {}

Tagging Email - One of the most important areas you can apply campaign tagging is e-mail. And though you can get fancy and create a filter that combines email sources you should not have to do this because your campaigns should be tagged to begin with. So definitely follow what the experts say about tagging email campaigns, but I am a huge fan of bucketing your reports by segment and grouping based on conversion goal. For example, at SEOmoz we're rolling out a number of e-mails ranging from a customer lifecycle welcome series to newsletters to follow up emails after PRO members cancel. Rather than doing one off tracking, our GA tracking is set up in a way that we can aggregate by visitor type. This allows management to quickly look at the all up numbers and see how e-mail is driving each goal area of the business: activation, retention, and re-activation.

And if you use a logical naming convention with your email tagging, such as the one shown below, your marketing team will be able to splice and dice using regular expressions to get a much more granular view of performance for each email format, type, or version:

Email Format: Which types of emails are doing best (i.e. newsletters, promotional emails, system notifications, etc.)

Performance by Email Type: Shows the breakdown of which email types have the greatest volume and/or the lowest click through rates. And thus, where you should place your testing and optimization energy. (i.e. emails sent 1 week after sign up, promos sent in December, etc.)

Version Number: Allows you to test subject lines and e-mail variants to see which versions are driving the most conversions, engagement, or retention. (i.e. subject line #1, subject line #2, etc.)

Vanity URLs - If you're running an offline campaign, such as a magazine ad, a business card run or a billboard creative, you're not going to want to use the long URL builder parameter. As WebShare's Corey Koberg shows in the below graphic, long URL parameters don't work for offline. So you'll likely be much better off measuring offline efforts with a short, easy to remember vanity URL, which, in order to keep your metrics from being skewed as a result of page load times, you'll want to implement using a 301 redirect, rather than using meta refresh.

Google Analytics Plugins

Though not on the list of must haves for the search samurai, I'm a sucker for a great browser plugin. And as ROI Revolution blogged about, there are a handful of browser plugins for GA that you might find are worth installing. Three plugins I use with varying degrees of regularity are:

Does a Page Have GA?
If you're checking a lot of pages on your site to see if they have tracking code installed or if you want quick, at a glance reference as to whether or not a page on another site has GA tracking code, Twistermc's GA? Firefox plugin is a great way to see if GA is installed without having to view the source code. The way it works it works is simple. If a page has GA installed, the bar chart that appears in the lower right hand corner of your browser is illuminated. If the page does not have GA installed, the bar chart is not illuminated.

Better Google Analytics:
Perhaps the most robust GA plugin of all is VKIs studios' greasemonkey script based plugin, which offers a number of bells an whistles, including page level social media data from sites like Digg, Reddit, StumbleUpon, and Delicious (see below),as well as added functionality such as a direct entry field to access your top content report from any other report, direct links to export to Google Docs, and a half dozen or so others.

Also, special thanks to David Booth at WebShare for his help with SEOmoz's implementation of Google Analytics and also for sharing several of the insights included in this post. For more info on GA and GWO, WebShare's Google sponsored Seminars for Success, which I attended last year, and which the SEOmoz marketing team will be attending here in Seattle on May 12-14th, are among the most educational and best valued around.

About SamNiccolls84 —
Sam Niccolls is an online marketer. He specializes in SEO, SEM, e-mail, and web analytics and currently works at SEOmoz as a traffic and conversion specialist.

I use WASP too. It shows all the analytics tools installed on a website (it tracks more than 150)It can also crawl your website to see if you forgot to tag certain pages.
Thumbs up to Stephane Hamel from immeria.net for developing this usefull tool.

Top of the pile of SEO knowledge that I don't have and must get around to is my own analytics. Granular data? Mine's monolithic!

I've read this piece twice and while none of it really makes much sense to me right now, I can tell that this post and the resources it points to are going to put a spike in my learning curve like it's pleased to see me. For something this good to fall into my laptop leaves me a bit speechless.

one thing worth mentioning is that many email marketers who use campaign-tracking make the mistake of hiding the tracking url by using the canonical url as the anchor text. While this might seem a good idea, it is actually not: Many email clients including Mozilla Thunderbird see this as a sign of phishing.

So, if you want to hide the tracking urls, you should use a picture (which should of course be attached to the email and not be loaded externally).

I've used analytics since I started, but very few clients have a handle on what they offer. For most, their understanding of SEO is how far up (or down) the SERPs they appear. I have about 20% who have an ongoing analytics reporting contract, but most just don't see it for the opportunity it offers.

Coming from a long career in offline marketing, SEO without measurement is like building race cars without knowing what track they are going on - desert racing or Indy? (note US example). sure they'll be powerful, but if you want to win you need to adapt to the track.

If clients have an ecommerce site they can see some figures, but even with the seemingly ubiquitous AWstats I've seen little awareness of the power of SEO combined with analysis.

The client's knowledge gaps are obvious - first one needs to explain personal search and the relative value of click-throughs vs position, bounces and even keywords. They just don't know they need to know, so it behoves us to educate them.

Great collection of tips, Sam. I'm actually in the middle of reading "Advanced Web Metrics with Google Analytics" by Brian Clifton, and it has some great advanced stuff as well. It's well worth a read to anyone wanting to dive deeper into GA customization, but word on the street is that there's a new edition coming out soon, so you may not want to but it just yet.

1. The SetAllowAnchor to change the tagging paramater in the URL from ? to #. That is a new one. I will be working that one in tomorrow.

2. The plugin you reference from VKIs studios....it looks great! I went to download it, but got an error message that it didn't work with FF v. 3.6.4 Bummer.

I spend a lot of time using the 'Service Provider' report under the Visitor Profiling. Being in a B2B business it helps with knowing which businesses are looking on our site; provided they're not on qwest business or comcast business..... Segmenting the businesses by Service Provider and then matching with content is very helpful in crafting messaging for direct contact or unique emails from sales reps.

Not sure I quite understood everything though, its most likely going to be one of those posts I'll come back to when I'm more into GA, (which I know I should be doing!). But for started already downloaded the GA pluggins so will see how that works.

analytics, tracking techniques and variations and reporting are some of the hardest things, imo, when executing a SEO campaign.

love the asynchronous part, as well as the custom variables and e-commerce tracking. actually, currently working on getting some bugs fixed with GA and some e-commerce software we implemented for a client where it shows all transactions as referrals from the root domain of our clients site. [went from site, to 3rd party cart, back to site and counts the transaction as a site referral, and no other metrics are given besides e-comm metrics. blast. i'll figure it out soon enough].

I am already use google analyatics and google adword tool for optimize my campaign but i have one problem with converion tracking tool as many customers visted my website and also they successfully reach or end with at last where my code resides for conversion happened but in conversion feild of mine still showing zero and i want to know why this happens can u plz reply me on my mail id or just mail me when u reply on my comment at (prem.tietian07@gmail.com).

Only other really useful function I'd add in is Event Tracking. This has some powerful uses, especially tracking user interaction.

I've found it really useful on sites where the user is taken to a 3rd party payment gateway. You can track the last action on your site which gives a total of people entering the payment gateway (eg on the 'buy button'), then of course put tracking (goal, adwords conversion) on the recipt page when the user returns - great for measuring checkout drop off and v.simple to implement.