Theresa Arzadon-Labajo

Drupal Hit Counter for Views not Nodes

Posted by Theresa Arzadon-Labajo (tarzadon) on Feb 03 2011
Tech Stuff >> Drupal
Make sure that the Statistics Module is enable.
Then configure statistics via administer > reports > access log settings  (admin/reports/settings)
Make sure the "Enable access log" checkbox is checked off.
Configure "" to however long you want to keep track of the page views.  I set mine to "Never"
"Count content views:" counts Nodes, not Views.  So this setting doesn't help.

In my view, I have Node:Title "output field as a link" going to another View. (xxx/yyy/[nid])

Since, the actual node will never get accessed, I need to manually search the accesslog table in the database and look for the "xxx/yyy/[nid]" paths.

I copied the views-view-fields.tpl.php template and renamed it to views-view-fields--myview.tpl.php

$fields['title']->content outputs an href, so I needed to extract the link from the href:
      $link_title = preg_replace('/(.*?)<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $fields['title']->content);

Then I contructed my query:
$sql = "select count(*) as number from accesslog where path=\"".$link_title."\"";

Then I used db_query and db_result to display the result as the number of views to those Views.

Last changed: Feb 27 2020 at 3:38 PM

Back