Tracking links within your site with Google Analytics


“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:

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

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:


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

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 pageviews.


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.


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

Jonathan Weber is our Data Evangelist, focusing on bringing the strategic value of data analysis to our customers. He spreads the principles of analytics through our training seminars and even wrote a book on Google Analytics & Tag Manager. Before he caught the analytics bug, he worked in information architecture. Away from the computer, you can find him as a flower farmer and plant geek.

  • Have you thought about the consequences regarding SEO? A searchengine spider sees 2 URL’s with the same content on them. People can link to both URL’s and the pagerank will be divided. The solution is to do some user-agent cloaking to check whether a searchengine’s spider visits the site: show them the URL’s without the extra parameter. And if they land on a page with the extra parameter, do a 301 redirect to the URL without the extra parameter.

  • Yeah, I agree…the SEO implications of this would not be good since you would be creating duplicate content throughout your site. I would probably only give this advice to people that are testing things with paid traffic and have them robots.txt out any pages with query parameters.

  • It is one of the great limitations of Google Analytics that one cannot make use of parameters within a profile (well, except the onsite search one). One always has to create new profiles whenever a new question arises, although this is thankfully less true since GA made custom segmentation available.

  • What are your thoughts on launching a page view through an onclick event instead? You still need a seperate profile to view the information but at least you keep things nice and neat for search engines.

  • Steve — using an onclick event would be a nice solution that keeps the link tidy for search engines, but passes the information you want to GA. Of course, the downside is that you have to maintain the code for the onclick events, but if you’re already tagging the links with query parameters to differentiate them anyway, it’s not significantly more effort.

  • I need to get with the program and explore Google analytics more.

  • We had ill-advisably used the “source/medium/campaign” tracking variables for our homepage site links. This had in fact overwrote the previous referral info as suggested in this article. We are now going back and creating a unique variable and will use the filter concept in analytics to understand content popularity and/or impact. Found this to be very helpful. Thanks!

  • Lukas

    I did it exactly like this post suggests for a while. The seo issues are not that hard if you use canonical tags, but the difficult addition and constant switching between at least two necessary profiles made me drop it altogether though. We use event tracking now. That keeps the urls clean. It has a downside too though: it is much harder for example to compare the paths of users that arrived at a page via a banner on the homepage with the path of those that came there via another path.

    In any case: you can do it the way lunametrics describes. But you have to be really careful with your profile setup and use canonical tags. If a lot of unexperienced users use your google analytics, it may be better to keep the URL reports clean by using event tracking.

    Btw: the event tracking was a recommendation of avinash kaushik.

  • You can also instruct Google Bot to ignore the ref parameter using Webmaster Tools which would remove the need for canonicalisation or complex onClick events

  • Although the post is a bit old, for others like me finding this article, here is the solution. Enhanced Link Attribution in Google Analytics. Link below.

  • Gloria Matherne

    I learned this article, its so impressive and helpful.
    Crack Software | Full Version Software

  • this is valuable posting!
    Software Crack | Download Free Software

  • Melisa Quillen

    useful information for tracking links. Thanks!
    software portable | free serial key

  • I am very Thankful for this useful and informative post…!!!
    free serial key | free software downloads

  • William M. Howard

    ver nice and easy guideline…thanks!!!
    free software download sites

  • thanks a bundle
    latest software

  • thanks a lot for giving information
    latest software

  • Thanks a lot
    Latest Software

  • This is what i used. Its the easiest way to track clicks on links

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187