I have created a views in grid settings. I have displayed 5 columns and 4 rows n this view. Over all i have 20 items present in this view. In each item i have a link field. This view is very similar to http://www.amazon.com/ (What Other Customers Are Looking At Right Now). Now i would like to track the number of clicks on each link. The result should contain the user who clicked it or how many number of times it has been clicked. I am struck with this please some one help me to find a solution. By the way I am using D7.


This link might help you. http://activelamp.com/blog/add-and-track-any-link-google-analytics

  • Thanks a lot :)But how is this possible to keep track of all the clicks made on the link?? i mean who clicked it or how many it has been clicked???
    – user4081
    Dec 8 '11 at 8:38
  • The linked page is not anymore available. This answer is now not helpful.
    – apaderno
    Feb 1 '15 at 16:17

In Drupal 6, you can use/enable the statistics module to get access to how many times a node has been viewed, so if your link is to a node, you can get sort of what you want from that. I preface this with "in drupal 6" because I am not that fluent yet in Drupal 7, but I am confident it is similar there. As to the user that last clicked it, hmmm, I don't think drupal keeps track of that outside of the logs, but, if you needed that information, it's a pretty simple database table of nid and uid. Getting that info back into views...another story :)

  • But my link points to an external site. That too i am using D7. I am not sure how it gota work.
    – user4081
    Dec 8 '11 at 8:39

If your link lead to some nodes, (this is the kind of tracking we are generally intested in), you can override hook_view().

  • Thanks for your reply. Actually my link leads to an external site. Say it leads to amazon.com. My link has no relation with my site.
    – user4081
    Dec 8 '11 at 9:42
  • 1
    then you do need to install a google style link tracker package. what they do is put a bit of js in your html that wraps all your anchors in some code that is sent to them every time they are clicked and keeps track. you would then have to get that information back from them and so forth as it is out of drupal's scope. check out "google webmaster tools" as a next step if any of this sounds promising.
    – Jimajamma
    Dec 8 '11 at 16:26

Activate Google Analytics on your website. You can then use virtual page views or events tracking to track click on your view's links. You will need to add a few lines of custom JavaScript for this. The code could looks like

  Drupal.behaviors.funkyTracking = {
    attach: function(context, settings) {
      var uid = settings.funkyTracking.uid || Drupal.settings.funkyTracking.uid;
      $('#you-view-id', context).once('funky-tracking').delegate('.field-content a', 'click', function(event){
        var url = this.href;
        _gaq.push(['_trackEvent', 'ViewsLinks', 'click', url, uid]);
        setTimeout(function() {window.location = url;}, 100);
        return false;

The code use JavaScript settings passed from your module or theme to JavaScript through drupal_add_js():

global $user;
drupal_add_js(array('funkyTracking' => array('uid' => $user->uid)), 'setting');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy