Hello,

I've just enabled the statistics module to give my paying subscribers an idea of how many hits their pages, articles, events, etc are getting.

What I want is to exclude myself (role=admin) from the counter, since I'm always zipping around the site, tweaking, checking broken links, cutting & pasting, etc.

I don't want my activity to be logged.

Has anyone else done this, or any tips on where to start?

Thanks,
Tyswan.

Comments

tyswan’s picture

Actually I found some other useful threads (after I'd solved this problem of course) if anyone is interested

About statistics : do not show administrator browsing

Statistics filter module

My solution (which also excludes reads by the author/owner of the node) is to modify the statistics module, and insert a few lines in the statistics_exit function:

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());
  }
}

--
tys

BLUE MOUNTAINS health & harmony
www.health-harmony.com.au

building an alternative health & spirituality community in the Blue Mountains

Chippe’s picture

Thank you so much for your solution. But I wonder how to stop users from "faking" hits. Ive noticed that I can get many hits by just access a blog entry and then go back and click on it again.

tyswan’s picture

My stats aren't public, so the only person the node-owner is cheating them is themselves. I ask them to login before viewing their statistics so they don't skew the result. If they are counting their own views, then they're only messing up the usefulness of the statistics to them, not anyone else (except me, I guess).

If you use the stats to have "top hits" page, well, that's different. I'm not sure what you can do then (maybe look at their IP address to restrict one hit per session? but that sounds complex.)

--
tys

BLUE MOUNTAINS health & harmony
www.health-harmony.com.au

building an alternative health & spirituality community in the Blue Mountains

Chippe’s picture

I see.. faking your own stats :-)

It's top hits that I want. I guess it could be done with cookies.
I'll search about it..

/Chippe

vipconsult’s picture

The above code doesn't seem to work.
I am using Drupal 5 and after modifying the statistic module it still logs the Admin browsing.

www.vip-consult.co.uk

Chippe’s picture

it works if you put it in correct.

tyswan’s picture

Haven't tried it with v 5.0. It was written for 4.7

I'm upgrading my site in the next couple of weeks, so I'll see if it still works for me.

Perhaps try some of the other links (although these seem also for 4.7....)

Cheers,

tys

--
BLUE MOUNTAINS health & harmony
www.health-harmony.com.au

building an alternative health & spirituality community in the Blue Mountains

mariagwyn’s picture

If you get this working for 5, I am interested. I am especially interested if I can put it in the template.php file rather than modify the module itself. Helps with upgrades.

Thanks,
maria

summit’s picture

Very interested. Is there a solution for Drupal 5 to not show the superadmin (first user)?
Greetings,
Martijn

Chippe’s picture

Maybe I wasn't clear earlier but it works with Drupal 5.

faux_at’s picture

Hi!
For those who do not want to modify their original files, I have written a tiny module: http://e-faux.com/node/45.

Regards,
Manuel Faux

Chippe’s picture

Works perfect on my Drupal 6 site. Thank you for sharing!

cp_webmaster’s picture

Manuel,
This is just what I am looking for, but we need to still be using 5.x. Anyone try this in 5.x?

ETA: I tried it in 5.x and no go. Bummer!

Wolfflow’s picture

Hi faux_at , I'm afraid but it did not work on my Site.
After installed noadmincount ver.1.1 result: blankpage.
I heve Drupal 6.2 installed and following modules:

  • chaptcha
  • codefilter
  • dhtlm_menu
  • extlink
  • faq
  • image
  • jquery_plugin
  • logintoboggan
  • poormanscron
  • switchtheme
  • tagadelic
  • userprotect
  • views

It can good be that the module conflict with one of Them. Any hint?
Cheers

There is nothing better then Drupal. Please contribute
Wofflow's Blog

Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.

dave reid’s picture

There is also the Statistics Advanced module that also provides this functionality.

Wolfflow’s picture

Love It. Thanks

Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.

summit’s picture

Hi,
Is there also a drupal 5 version in the making please?

greetings,
Martijn

dave reid’s picture

There will be soon.

ThePeach’s picture

That was what I was looking for! thanks for sharing I'd have never reached it otherwise ;)