Content viewing counter
steve-psngs - April 24, 2008 - 20:28
Is there anyway to do the following with "Content viewing counter" ?
1 - not add counts when it's myself (the admin) who is viewing a page ?
2 - rest the counters to zero ?
It seems illogical to show these counts (to myself only) & add a count each time I view something as the whole point is to be able to see how many people actually look at my site's content.

Okay, I had a look around &
Okay, I had a look around & found a few things, notably this :
Ignor administrator (user 1) hits
jsloan - June 8, 2006 - 16:13
There are no "settings" to do this. You would need to add some code to the statistics.module in the function statistics_exit(). Since the $user variable is available inside the function just adding something like this just after the global declarations would work.
if ($user->uid == 1) {
return;
};
which would logically stop counting admin views, so I tried it but it didn't do anything.
From the same thread (http://drupal.org/node/67974) I alos tried this to rest all the counters to zero :
So if you have access to your mysql database (phpMyAdmin) you could run this statement to reset everything to 0TRUNCATE accesslog
which I did & it ran fine but nothing changed on my site, even though I emptied the cache, the counts stayed the same.
Perhaps these functions are different in 6 ?
Anyone any ideas on how to do this ?
found this one & it works in
found this one & it works in 6.2 :
function statistics_exit() {
global $user, $recent_activity;
drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
if (variable_get('statistics_count_content_views', 0)) {
// 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.
// exclude admin & node author
$nid = arg(1);
$node = node_load($nid);
$node_author = $node->uid;
if (!user_access('administer nodes') && $user->uid!=$node_author) {
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(), $_SERVER['REMOTE_ADDR'], $user->uid, session_id(), timer_read('page'), time());
}
}
http://drupal.org/node/129971
now all I need is to get the counters reset to zero.
I did try disabling counter hits & accesss log counts & as above, tried the Truncate command in the sql, but no matter what, the previous counts stayed.
Well at least now they have stopped counting my use.