Feeds

Help Us Test New Metrics Template Code

PerformancingAds
Submitted by Chris Garrett on April 12, 2006 - 10:11am in

By now Wordpress users will have seen Richards Metrics Hacks but I thought today I would show some Metrics template code tweaks you can implement for Blogger, Wordpress and Drupal blogs.

The main gripe people have had with the template code is how it needs to differentiate between posts and the homepage. My solution for Blogger users follows.

Index or Post Logic

Blogger

<Blogger>
<ItemPage><!--item-->
<script>
z_post_title="<$BlogItemTitle$>";
</script>
</ItemPage>

<MainOrArchivePage><!--archive or home-->
<script>
z_post_title="<$BlogPageTitle$>";
</script>
</MainOrArchivePage>

</Blogger>
<script id="stats_script" type="text/javascript" src="http://metrics.performancing.com/bl.js"></script>

This relies on Blogger template logic that decides which block of code to show depending on if it is an archive page or a post. Blogger also allows you to show the page title or post title. In the metrics code if the Z_ variables are not filled in it uses the page title as a default so you only really need the post title necessarily.

Many blog platforms have equivelant tags, in Drupal you can check to see if the $main or $page PHP variables are set as true (homepage or individual post), Textpattern has a "if_individual_article" tag. Wordpress is more complete than most, having "is_home()", "is_single()", "is_category()".

Don't Track Yourself

A much requested feature is to filter out your own visits. This can be most easily acheived by not showing the tracking script when a registered user is viewing or more specifically you are logged in. Some blogs have a feature that allows roles so you could have ordinary members still tracked but admins not.

In Wordpress you can check $userdata. If it is set there is user information available, you can also drill into the username, user ID or user level. This allows you to check for "Bob" or not show for users with permissions over a certain level.

Wordpress User Logic

<?php
global $userdata;
get_currentuserinfo();

if(
$userdata->user_login != "Bob") print "<script> ...";
?>

Drupal has roles so you can check to see if the user is in the role that should not be tracked.

Drupal User Logic

if(in_array("Bloggers",$user->roles))
{
print "<!-- Don't show metrics script to $roleToExclude -->";
}
else
{
print "<script>...";
}

And now you

Please share with us your experience of using the template code. Have you already implemented code like this? Do these things work for you? Should we put this into the system or leave it up to individual users to tweak their code?

We can only improve Metrics with your feedback so let us know.


Thanks Chris ... valuable info!

I am using the Blogger scriptlet on two sites since you published it for the first time and it works fine.

I still have an PMetrics issue with ALL my blogs. The time line graphs stop showing data after April third.

My Textpattern code was published in this comment.

testing in progress ...

I am using the Blogger code in this post on my two Blogger-based blogs, and so far I believe it is working as expected. Will know more after a full day of data-collection, but it certainly appears to solve the wee buggies re: titles and what not.

Good job, thanks!

Yay

Currently the PMetrics

Currently the PMetrics WordPress plugin ignores tracking with user levels. For now it seems to work well since the level can be customized by the user and for most people, they just want to ignore themselves (the admin - user level 8). I suppose if enough people requested it, I could add ignore by specific users, but it's not a big priority right now.

Chris's WP script will work great for people that aren't using the plugin - in which case they'll want to use if($userdata->user_login != "admin") ...

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <h2> <h3> <h4> <img> <div> <a> <em> <strong> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <span> <table> <td> <tr> <caption> <th> <hr> <pre> <br> <p> <object> <param> <embed> <strike>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.