How to Track Internal Links in Google Analytics using Asynchronous Tracking

Josh Chambers, Former Viget

Article Category: #Strategy

Posted on

NOTE: If you are using the standard tracking method (ga.js), please see the post entitled How to Track Internal Links in Google Analytics. This post is intended for Asynchronous Tracking. 

What do you do if you want to track how often a link on your site is clicked? How do you see those links in Google Analytics (GA)? What filters and profiles should you create to accurately track this information? Hopefully, I can accurately answer these questions -- some of them in this post, some in the future. *Warning* if you don't care about web analytics, reading this post may produce seizures and a strong desire to fall asleep on the job.

First, why in the world would you want to track internal links? Isn't that stupid idea?

  • If I click the "go here now" link on my site, and it takes me to another page on my site ( www.example/go_here_now.html ), why do I need to track the link? Wouldn't I just check the navigation path report for /go_here_now.html? Yes, you could do that. But what if you have multiple links on Page 1 that link to Page 2? How do you know what links brought someone from Page 1 to Page 2? Was it the blue link? Or the green button? The navigation path simply tells you what page people came from and to, it doesn't tell you exactly how they got from page to page

Second, which method of link tagging should you use?

  • _trackPageview or utm?
  • If you don't know the difference, read this bullet. If you do, skip to the next bullet.
    • The _trackPageview JavaScript creates a fake pageview. This method is most commonly used to track outgoing links or downloads. The _trackPageview attribute is placed within the <a> tag and looks like this: onClick="javascript: pageTracker._trackPageview('/example/blue-link'). The /example/blue-link becomes a new pageview and it is tracked in GA as a new pageview - so it will increase your pageview count. These fake pageviews will now show up in your "content" reports. More information.
    • The utm method involves telling GA what the campaign name is (you define this), the source (typcially something like Google), and the medium (typically something like PPC) - as well as a few other options. This method is most commonly used in tracking PPC campaigns (as Google AdWords does this automatically), email campaigns, and other external campaigns that link back to your site. Epikone has a great post on this, and here's some additional Google info.
  • I recommend using the _trackPageview method.
    • If you choose to tag your links with utm, it erases all referral information. In other words, if someone arrived at your site via a Google organic search; but they then clicked on an internal link that had the utm tagging, you lose the insight that the visitor originally came from the Google organic search (the source and medium). Instead, you see the new source and medium information that you manually entered. For me, that's not a good option. I need to know where the visitor came from as much as I need to know what internal links they're clicking on. Again, check out Epikone's post.
    • Because _trackPageview creates a new pageview, you can use custom filters to include and exclude those pageviews from GA profiles (more on that below). Also, you don't lose any referral information.

Now then, to answer the questions I began this post with...

Step 1: Proper GA tracking script placement.

  • Usually, when we're not using _trackPageview, we recommend placing your GA tracking script just before the close of your <body> tag. We do this so that if GA is loading slowly (which rarely happens), your whole page can load before GA kicks in and it won't have to wait up for a slow GA server. However, in this method we're tagging links within the <body> tag, so GA needs to kick in before those tagged links load on the page. The GA tracking script should be placed after the opening of the <body>  tag, and before your tagged links, to ensure your tagged links load after the GA tracking script. Make sense?

Step 2: Add the _trackPageview variable to your links.

  • Add the snippet onclick="_gaq.push(['_trackPageview', '/outgoing/']);" to your links. Once done, your link should look like this:
  • <a href="" onclick="_gaq.push(['_trackPageview', '/outgoing/']);"

Step 3: Define your URL structure. Be as Type A as possible.

  • In order to use this tool effectively, you will want to quickly find and filter in/out and all of your manually-created pageviews. I recommend using at least two subdirectories when deciding how to name your new "pages." For example: internal-links/blue-link. Even better: internal-links/homepage/blue-link. The reason? If you're trying to quickly find and filter your manually tagged internal links, having a generic base directory like "internal-links" makes your life a lot easier. Creating each link with only one subdirectory like /blue-link and /pink-link and /red-button means you would have to search for each of those URLs manually -- boorrrrrring.

Step 4 (OPTIONAL): Create a filter to exclude your new pageviews from your regular profile.

  • Create a custom filter:
    • Filter Type: Custom filter
    • Check the "Exclude" radio button
    • Filter Field: Request URI
    • Filter Pattern: ^/internal-links/homepage.*
    • Case Sensetive: No

Step 5 (OPTIONAL): Create a new profile to include only your new links.

  • Create a new profile. Again, be Type A with your naming system
  • Create a filter. From the dropwdown menu, select the "Include traffic only to a subdirectory"
  • Enter the two base directories of your newly created pageviewinto the "Subdirectory". Using our example of /internal-links/homepage/blue-link, we would enter this into the "Subdirectory" field
    • ^/internal-links/homepage/

Step 6: Test it

  • After 24 hours, view your new profile to see if everything was implemented properly.
  • If you didn't create a new profile, view your "Top Content" report and search for "internal-links" or whatever nomenclature you chose to use. 
  • If it's not working, check to ensure you've copied the _trackPageview code exactly as is and check to ensure your filters are implemented properly if you're using them. If you're stuck, feel free to drop a comment and we'll get back to you.

There you have it! I'll write another post on how to use these pageviews for goal tracking, but in the meantime please don't hesitate to ask questions if this was confusing, and please let me know if I'm off base.

I'm going to go get some exercise or head hurts, and I've fulfilled my nerd quota for the week.

Check out Part 2: How to Track Internal Links as Goals in Google Analytics

Check out How to Track Internal Links using the standard GA script

Related Articles