How To Track and Count Number of Links in Google Analytics

Sometimes when we build web pages, we want to know how many visitors clicked on a link. It is somehow different from identifying how many visits did the page linked to have, because it can have multiple pages linking to it. By knowing how many clicks our links are getting, we know they are either a) prominently placed; or b) visually attractive and could therefore be attractive in leading visitors to our desired pages.

Implementing the link count/tracking in Google Analytics is pretty straightforward. We only need to call a few functions and set identifiers for each of our links.

As an illustration, let’s use Starstreet website’s Eat Drink Be section.

We have six links to track marked by orange outline:

* Register
* Contact Us
* Caffe Habitu
* Castello del Vino
* Choice Gallery

Each of them should be named with a unique identifier as specified in the brackets:

* Register (/eatdrinkbe/register)
* Contact Us (/eatdrinkbe/contactus)
* Caffe Habitu (/eatdrinkbe/caffehabitu)
* Castello del Vino (/eatdrinkbe/castellodelvino)
* Agnes b’s LIBRARIE GALERIE (/eatdrinkbe/agnesblibrariegalerie)
* Choice Gallery (/eatdrinkbe/choicegallery)

We shall then append Google Analytics code on each of them. For example, Register’s existing URL in the website is just <a id="reg" href="/register/">. We will then apply the following tracking code:

onClick="javascript: pageTracker._trackPageview(‘/eatdrinkbe/register’);"

So the resulting code should appear as:
<a href="" onClick="javascript: pageTracker._trackPageview(‘/eatdrinkbe/register’);">

You can then test the links by clicking on them (provided your network IP isn’t blocked by Google Analytics filters) and check back after about 2 days in the Content > Top Content section in the GA reports. You should see “/eatdrinkbe/register” as one of the “content” and the corresponding number of clicks.

Note: This code should be used in conjunction with the latest version of Google Analytics code. If you are using the urchin code, you should use


instead of

onClick="javascript: pageTracker._trackPageview(‘/eatdrinkbe/register’);