Nice asked some days ago on WpRecipes how can he’ll be able to prevent the blog admin from being tracked as a normal visitor by Google Analytics or any other tracking code. Here’s the answer to Nice question!
Nice asked some days ago on WpRecipes how can he’ll be able to prevent the blog admin from being tracked as a normal visitor by Google Analytics or any other tracking code. Here’s the answer to Nice question!
To achieve this recipe, we need the current_user_can() WordPress function. This function checks the given parameter, which is the level of the current user, and returns true if the level of the current user is superior or equals to the given parameter.
The following code will track any visitor or blog contributor exept the admin, if he's logged in, of course.
<?php
if (!current_user_can('level_10')){ ?>
INSERT ANALYTICS CODE HERE
<?php } ?>
That's all! Easy, isn't it?
14 Responses
Other way is to add filter in Analytics. I have static IP so simple filter by it excludes all traffic from me, even without logging in.
@Rarst: Thanks for the tip! Though, you need a static IP adress to do this. I don’t have one, for exemple, so this trick may be useful to people with a dynamic IP adress.
Neat trick.. now where would I need to put that code? In the header?
Hello Remkus!
If I remeber well, Google Analytics asks you to put their code just before the </body> tag. Sorry for forgetting to tell it in the recipe
I need this lol… now tracking will be “real”
At first I thought it didn’t work. It still shows the stat code whether I’m admin or guest
but my blog is 2.3.x so I tested on WordPress 2.6.3 localhost and it works like a charm!
I tried to search codex to find if there is alternative to current_user_can(‘level_10′)
)
any idea to make it work with 2.3?
(please don’t blame me as I’m not quite ready to upgrade.
Thanks jbj!
p.s. Nice is a girl and she giggle every time she saw your avatar. the white spot looks like (cartoon) cat’s mouth.
Sometimes she visit your twitter just to see the background for lolcat sake.
man I love your and your cat face expression in that pic lol
Nice
@SE7EN: Didn’t knew it didn’t work on WP 2.3. Sadly, I don’t have a solution for solving that issue, but you should see if there’s isn’t a deprecated function which do the same job as current_user_can().
Glad to see that Nice loves my cat! He’s indeed a very cute boy =^o^=
Thanks for clearing that up
Now I know why it doesn’t work with my blog. It’s not related to WordPress version
As I plan to create another WordPress blog in another directory, I use the method mention here
http://www.quickonlinetips.com/archives/2006/03/host-wordpress-in-alternative-directory/
so when I access http://www.se7enize.com, it doesn’t work
it works fine when I access http://www.se7enize.com/nice/ – which is real WordPress address – and other single pages, category archive, etc.
p.s. (Nice is me – the same person as SE7EN, sorry for making you confused. lol
)
Shoud level be 10 for me or i shoud change it.
p.s. sorry for bad language.
Does the code work with two admins?
Trackbacks: