I need to track all clicks by a user (even with no JavaScript enabled. What is the best hook_ function to use to track these requests so I may log them?

  • You cannot track all clicks from a website. If you want to track everywhere a user clicks their mouse on a page, this can be done with Javascript. If you want to track what pages a user views on their journey, you can check out a range of analytic tools that will help you with this (Google Analytics and StatCounter are two examples). – tigertrussell Oct 14 '13 at 21:17
  • Hook functions provide a way for experienced developers to modify the behavior of the Drupal Core or any Contributed Modules. For instance, if I have a "bread" module, which allows my users to bake bread, I could add a "hook_put_bread_in_oven()" function to my bread.api.php file. Then, the "Burnt Bread" module comes along and modifies the "Bread" module to burn all of my bread. In order to do this, it needs to turn the oven up to 500 degrees when I put the bread in. So burnt_bread_put_bread_in_oven() is written and its body sets oven_temp to 500. – tigertrussell Oct 14 '13 at 21:21
  • I know that about JavaScript, hence my "even with no JavaScript enables" comment. I just need to log user clicks and not modify anything. – vintorg Oct 14 '13 at 21:24
  • You sound as if you think I didn't read your question fully. The answer to your question exactly how you asked it is simply "you cannot." I was trying to suggest alternatives that might work for you. – tigertrussell Oct 14 '13 at 21:27
  • To log a click that doesn't make a server side request, you'll need to use Javascript. Clicks that make a request to the server can be logged server side. – David Thomas Oct 14 '13 at 21:37

You can use Google Analytics Event Tracking module to track mouse click and other events. This module provides a hook where you can track click events.

From module page:

Event Tracking is a way to track user interaction with out registering a page view.

This module allows an interface for Google Analytics event tracking capabilities. It provides a hook for other modules or "glue code" and also has some handy drush commands.


Looks like hook_exit() is what I want. It is called after cached and non-cached page requests, everything is loaded, and cleanup happens. This seems like the right place to make a logging call.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.