Here is the problem:
When you setup a redirect like /page/my-example -> /node/123 , when you hit /node/123 core statistics will record 2 hits instead of 1

Also when core statistics is used with a caching solution like Boost, thousands of hits (internal traffic) are recorded making core statistics useless.

As a workaround i used the following code in statistics.module

function statistics_exit($destination = NULL) {
  global $user, $recent_activity;

  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
  if (variable_get('statistics_count_content_views', 0) && $destination == NULL && $_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']) {
    // We are counting content views.
    if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
      // A node has been viewed, so update the node's counters.
      db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1));
      // If we affected 0 rows, this is the first time viewing the node.
      if (!db_affected_rows()) {
        // We must create a new row to store counters for the new node.
        db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time());
      }
    }
  }
  if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
    // Log this page access.
    db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), ip_address(), $user->uid, session_id(), timer_read('page'), time());
  }
}

This works for me now but i would like a cleaner solution without the need to patch core modules.
NOTE: access_log is not affected by the code

Comments

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.