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
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
user_login != "Bob") print "