I need to change default functionality of statistics module.

I want to count views of only published nodes by administration users too. I can't find any hook for this.

Now if administration user see unpublished node, counter is increased.

Is this possible without hacking a core?

  • If the nodes are unpublished, then they won't be viewed. This means that by default they won't be counted. Is there a specific use-case for this? Seems like the out-of-the-box functionality will be fine.
    – Chapabu
    Sep 5, 2012 at 10:53
  • @Chapabu Yes, but there is a lot of content administration users, I'll edit my question to be more specific
    – Codium
    Sep 5, 2012 at 11:05

1 Answer 1


The Statistics module doesn't use any hook because generally works when Drupal has not completed its bootstrap phase. (That is if caching pages is enabled.)

What you can do is creating a custom module that runs right after the Statistics module, and execute code similar to the following one.

function mymodule_exit() {
  global $user;

  $is_node = (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL);

  if (variable_get('statistics_count_content_views', 0) && $is_node) {
    $node = node_load(arg(1));
    if (!$node->status) {
        ->key(array('nid' => $node->nid))
          'daycount' => 1, 
          'totalcount' => 1, 
          'timestamp' => REQUEST_TIME,
        ->expression('daycount', 'daycount - 1')
        ->expression('totalcount', 'totalcount - 1')
  if (variable_get('statistics_enable_access_log', 0) && $is_node) {
    $node = node_load(arg(1));    
    if (!$node->status) {
        ->condition('title' => truncate_utf8(strip_tags(drupal_get_title()), 255))
        ->condition('path' => truncate_utf8($_GET['q'], 255))
        ->condition('url' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')
        ->condition('hostname' => ip_address())
        ->condition('uid' => $user->uid)
        ->condition('sid' => session_id()) 
        ->condition('timestamp' => REQUEST_TIME)

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.