Track Link Clicks In Drupal

Posted on October 02, 2015 - 4 Minute Read

You might be wondering why you would need to track the number of times a link is clicked in Drupal, when this can be done using Google Analytics and the Google Analytics Module. However, by default this just groups all outbound link clicks as "Outbound links". Also (as far as I can tell), this doesn't tell you on what specific page the user clicked that particular link on.

Screen Shot 2015 10 02 at 2 18 35 PM

So, if you have an outbound link on multiple pages, you can't see what page the user was on when they clicked it. Luckily Drupal's Link Click Count is a simple solution for tracking both internal and external link clicks. It also ensures that each link (internal or external) will be tracked individually. This means that if you have two nodes that reference the same link, you can see the link click counts for each link individually. This is perfect for A/B testing.

In this tutorial I'll show you how to set up link tracking, and how to view the results.

Screen Shot 2015 10 02 at 7 40 12 PM

First we'll need to install and enable Link Click Count and its dependencies.

Screen Shot 2015 10 02 at 7 02 55 PM

Now that the module and its dependencies are installed, let's configure the configure out set up. For this tutorial I'm going to use the default Article content type as an example.

  1. Add a new link field at admin/structure/types/manage/article/fields. In this case I'm creating a field for any resources an author might add to a post, similar to how my blog is set up. Screen Shot 2015 10 02 at 7 06 29 PM
  2. At the bottom of the settings page for the new field (in my case at admin/structure/types/manage/article/fields/field_resources ) configure the following settings.

    1. Select Save the clicks happened on this link. Screen Shot 2015 10 02 at 7 07 41 PM 0
    2. (Optional) set Number of values to UNLIMITED. Screen Shot 2015 10 02 at 7 07 56 PM 0
  3. ​Save.
  4. Now go to this display settings for your content type (in my case at admin/structure/types/manage/article/display ) and set your link field's format to Counts the click happened on this link. Screen Shot 2015 10 02 at 7 21 09 PM 0
  5. Save.

Add Some Test Content

Now that we've configured Link Click Count let's test it by adding some content. Add some external and internal links and click on them.

Now we need to be able to track the links that we've created. By default Link Click Count creates a view that displays this data, and also allows for date filtering. This is especially helpful if you want to gather metrics during a campaign. The default view only has one flaw in my opinion, and that is the fact that anyone who can see published content can see this page. To fix that do the following.

  1. Navigate to view at admin/structure/views/view/link_click_count_stats/edit/page
  2. Under PAGE SETTINGS > Access: configure the following.

    1. Set Access restrictions to Role Screen Shot 2015 10 02 at 7 35 49 PM
    2. Select the Role to administrator (or any custom admin role you've created) Screen Shot 2015 10 02 at 7 35 57 PM
  3. Save.

To view the link click counts just go to the view page at /link-click-count-stats.

Conclusion and Use Cases

Google Analytics and the Google Analytics Module track outbound links, but they don't provide you with enough detail to out of the box. With the Link Click Count module you can easily track the number of clicks on internal or external links associated with a link field. This is perfect for A/B testing, monitoring the success of advertisements or gathering data on user engagement.

Categorized In:Tagged In:

Learn Ruby on Rails For Free

I created Rails Code Along to help teach you how to build, test, troubleshoot, and launch a REAL production Rails application. This course is free, and does not require you to sign up.

Learn Ruby on Rails For Free

Let's Connect