I have a content type "song" and created a view on it. Using Views 3 exposed filter, people can search with different criteria.

enter image description here

With Google Analytics, I can collect some rough statistics. But I do not want anonymous statistics. I would like to collect and report the criteria by the login user/roles.

I can put a PHP code into my view so that every time someone interacts with this view, the PHP code will collect the criteria from the URL and save to a table.

Is there a better way?


I've got an interim solution:

  1. Write a custom module that uses hook_form_alter to update the exposed filter form. See link.
  2. Install Views Watchdog
  3. Create a view that reports on these watchdog entries. I can use PHP to parse the watchdog's location field to get my reports better.

If you have a better alternatives, please let me know.

  • Are you using a google analytics module? It allows tons of options and you can tweak it to fit your requirements.
    – Ash U
    Commented Mar 22, 2017 at 0:23
  • When you say 'I can put PHP code into my view' do you mean using PHP Filter? Commented Mar 22, 2017 at 3:05
  • Yes, PHP filter. To expand further, I'm thinking that whenever some interacts this view, it'll runs some PHP to read the URL and save to a table. Then I can write something to report from those data. I just thought there is a neater way to do this
    – xelat
    Commented Mar 22, 2017 at 3:21
  • @Ash Upadhayay, yes, I'm already using the google analytics module but it can only capture anonymous data
    – xelat
    Commented Mar 22, 2017 at 3:22

1 Answer 1


You can use GA Push module:

GA Push offers an API to enqueue informations that are sent GA servers, and three submodules to track browser events (using jQuery), form validation errors and log exceptions.

Instead of saving the data in your custom table you can just send it to Google Analytics.

Collect your data in your PHP code and send it like this:

      $push = array(
        'eventCategory' => $category,
        'eventAction'   => $action.
        'eventLabel'    => $label,
        'eventValue'    => $value,

You may hook on the form submit instead of adding PHP code to the view.

  • Google Analytics requires data to remain anonymous. So while this is good method, it prevents me send any usernames.
    – xelat
    Commented Mar 22, 2017 at 1:15
  • That's true if oyu send any user identifiers, but you can send data without any user id adn have the data aggregated. What GA doesn't allow is to track user activity and link with their id or any other data that can identify the individual user. But you can aggregate data withuot problem. If you need data linked to each individual user then yes, you need to save the data in your database.
    – sanzante
    Commented Mar 22, 2017 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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