Tracking Links Within Your Site With Google Analytics

December 19, 2008 | Jonathan Weber

“I have this banner I’m putting on my homepage to promote a particular product. How do I tell how many people clicked on that banner to get to the product page?”

People ask me this kind of question, or variations thereof, all the time. It’s all about understanding how often some particular link on your site is getting clicked, or differentiating between two or more different links to the same page.

Sometimes people ask if they should use campaign codes to track these kinds of links. That’s the right instinct, but I recommend against using campaign codes. The reason is simple: if a visitor clicks a link with campaign codes, they’ll overwrite the visitor’s previous referral information — that is, how they actually got to your site in the first place.

OK, so campaign codes are out. What to do?

The answer is simple, and related to the way campaign codes work. You’ll recall that “query parameters” are those things after a question mark (?) in a URL. The great part about them is, if your web server doesn’t recognize them, it just ignores them. So for example, this URL:

http://www.example.com/mypage.html

is identical to this one, as far as my web server is concerned:

http://www.example.com/mypage.html?from=banner

They’ll both take me to the same page. Here’s a real-life example you might be familiar with, the top menu from Facebook:

facebook

Both the logo and the “Home” link take you to your home page, but the URLs are slightly different:

http://www.facebook.com/home.php?ref=logo

http://www.facebook.com/home.php?ref=home

They’re using the “ref” query parameter to see which place you clicked. It’s the same with the “Profile” link and your name.

So the URLs go to the same pages, as far as the visitor is concerned. But if I’m using Google Analytics and take a look at the Top Content report, I’ll see separate listings. And whatever the query parameter is that I’m using (“from” in this case), I can easily use the “contains/excludes” filter at the bottom to find those page views.

page views

Best practices

If you use this method, you’ll notice that the pageviews for the page in question are disaggregated according to the query parameter you used. This is great — it’s exactly what we’re after. But if you want the total pageviews for that page, you have to do some addition.

The best thing to do would be to have two profiles, one where you take the query parameter into account to disaggregate those links, and another where you strip the query parameter away to easily see total pageviews to each page, irrespective of which link someone clicked to get there.

Google Analytics lets you easily strip away query parameters you don’t want. In the profile settings, just enter in whatever query parameters you’d like to take out.

exclude

This will give you a profile with the aggregated pageviews, without your query parameter.