Twitter and Facebook badges have become ubiquitous. You put them on each page of your site (at least most do), and you want people to follow you on Twitter and like you on Facebook. But how do you know if they are? If you’re using Google Analytics, it’s a piece of cake, even though it’s a bit of a hack.
Caveat: You can also track these clicks in Google Analytics using event tracking. Those in favor of that method say it’s better because creating virtual pageviews inflates the pageviews in your reports. However, I’ll show you how to filter these pageviews out of your analytics. The main reason people track pageviews is for ads; other than that, it’s a pretty junk metric in most cases. More importantly, I don’t like using events because you can’t set up an event as a goal (why, Google, whyyy?), and I like tracking these clickthroughs as micro conversions for websites alongside its other goals. I’ve done both and switched back to the virtual pageviews method, thankyouverymuch. But I’m open to hear salient arguments for why event tracking is better. (You won’t convince me, but you might have some luck with our readers. :))
Just Do It
Step 1: Come up with the structure for your virtual pageview. I like to start all of my virtual pageviews with /virtual/. This would be like the top-level directory. I’ve learned (the hard way, of course) that this makes it super easy to create an advanced segment for all your virtual pageviews. Then I break my pageviews into three categories: outbound, forms, and downloads and use that as the subdirectory of sorts. That’s just my personal preference. So in the case of tracking a link to a client’s Twitter page, for example, I’d use /virtual/outbound/. Then I use the name of the site as the last part of the page URI (or file if it’s a download or form if it’s a form). So my page would live out its virtual days as /virtual/outbound/twitter. If it were a “real” page, its actual Web address would be http://www.blueglass.com/virtual/outbound/twitter. (I use lower case to avoid URLs in cAmEl case. Haateit.)
Step 2: Find out if you’re using the traditional or asynchronous code on your site. To follow the path of least resistance, I just look at the source code in the browser to see if the tracking code has var pageTracker or var _gaq.push in it. If it uses the pageTracker code you have the traditional tracking code in place (old school). The asynchronous uses the push method for page tracking. (You should be migrating to the asynchronous, by the way.)
Step 3: Add the following script to the link you want to track. I’ll use Facebook this time: Traditional: <a href=”http://www.facebook.com/BlueGlassInc” onClick=”pageTracker._trackPageview(‘/virtual/outbound/facebook’);”>Facebook</a> Asynchronous: <a href=”http://www.facebook.com/BlueGlassInc” onClick=”_gaq.push(['_trackPageview', '/virtual/outbound/facebook']);”>Facebook</a> Note: If your pages have extensions (.html, .aspx, etc.), you may want to add the extensions to the end to keep the formatting consistent. This is purely a style preference if you’re given to fits of OCD. :)
Step 4: Get ready to add your goal. To do this, you have to have admin rights to the Google Analytics account. If you do, log in and click the Edit link to the far right of the profile you want to add your goal to.
Step 6: I’m not going to go through each setting as most are self-explanatory. So jumping ahead, since your goal is to register a pageview, you’ll choose the URL Destination option under Goal Type. Under Match Type, you have three options: Exact, Head, Regular Expression. I never use exact match because if any parameters are appended to your URL — from an RSS feed or social media or whatever — your goal won’t register. I usually use the Head Match option, which just means the URI has to contain whatever you put in there.
[Tip: You could always put this in the filter at the bottom of your content report to make sure the right page comes up if you're creating a goal for a real page.]
If my goal conversion (or a step in the goal funnel) could be one of two or more pages I use the Regular Expression Match option, but that’s outside the scope of this post. I’ll cover more sophisticated goal tracking in another blog post. In this case I’d just enter /virtual/outbound/facebook. I didn’t associate a goal value with this goal.
Step 7: After you’ve had adequate time to gather some data, go into your analytics and check out your goals. You can look at your isolated goal tracking metrics under the Goals section or look at them in the context of other reports — most of the Visitors reports and all of Traffic Sources but none of the Content reports. Or you could create a segment that looks at, let’s just say, all visits that include a conversion for any of your social media follow goals. (Of course, you don’t know for sure they actually clicked the Follow or Like buttons when they get to your profile page, but this is Google Analtyics we’re talking about, not God.) You would set that up this way:
Ninja Analytics Secret: If you want to see goal conversion rates for your landing pages, go to Visitors > Map Overlay and choose Landing Page from the Dimension drop-down. (It’s just to the right of the Detail Level options and above the report tabs.) This will replace the Countries with your landing pages. Then you can see conversions for each of your landing pages. Pretty sneaky, eh? If you have an ecommerce site, this is also the only way I know of to get revenue for each of your landing pages.
Step 8: If you want to filter your virtual pageviews out of your reports, create an advanced segment that filters those out. The easiest way would be to just click this link, and it will apply the one I created to your default profile. Well, it opens up the window with all the settings pre-loaded; all you have to do is it apply it to the profiles you create virtual pageviews for. You can also modify it however you want.) Then you’ll just want to choose your segment from the Advanced Segments drop-down, and your reports will be scrubbed of those virtual pageviews.