While upgrading to WordPress 2.1 I did a periodic spin through my plugins to get the latest and greatest updates. I noticed that Stattraq 1.0b was no longer the latest update — in fact, there’s a new maintainer: “Murph” and he’s released a version 1.1.1 with a number of fixes.
Unfortunately, I had made a bunch of tweaks to 1.0b over the year I was running it. Bug fixes, performance improvements, anti-referrer-spam stuff. Mostly stuff I hacked together myself or picked up from other blog comments while I was troubleshooting some problem.
The good news is that windiff showed me that a number of these fixes were included in 1.1.1. The bad news is that windiff showed me that a number of these fixes were NOT included in 1.1.1
So I made the fixes again to my copy of stattraq.php. And then I tried to post the details back to Murph’s blog so that they could hopefully get integrated going forward. But the blog comment posting stripped all the meta data out and undoubtedly makes the changes hard to follow.
So, here (below) is what my blog post was supposed to look like. Also, here’s a link to my modified stattraq.php file in case you want to use it and/or DIFF it with your own changes.
The intended comment:
Couple of things I had fixed in my copy of 1.0b that are “rebroken” in the 1.1.1 release. Please consider integrating these so I can just run the baseline going forward:
1) Blogs using pretty permalinks (ie – not “?p=64″ style) don’t properly break page views out into the list of pages; everything shows up as “multiple pages”. This is because it’s not able to resolve the page view back to the actual page.
Changes:
$s_id = session_id();
<! // **EVAN – Move $urlRequested up to here (need it before you can get the article ID) and fix it to be the right value
<! $urlRequested = $_SERVER['PHP_SELF'] . $_SERVER['REQUEST_URI'] ;
<! // ** EVAN – End of $urlRequested change (except for commenting the original out below)
<!
// need to get the real article_id or type of server request (RSS, RDF, ATOM, Ping, etc)
and
$ipAddress = statTraqGetIPAddress();
<! // $urlRequested = $_SERVER['PHP_SELF'] . (isset($_SERVER['QUERY_STRING']) ? “?”.$_SERVER['QUERY_STRING'] : ” );
!> $urlRequested = $_SERVER['PHP_SELF'] . (isset($_SERVER['QUERY_STRING']) ? “?”.$_SERVER['QUERY_STRING'] : ” );
$browser = statTraqGetBrowser();
2) Make sure favicon.ico is excluded from tracking also. Also, change the insert style to “DELAYED” to improve performance.
Changes:
}
<! // **EVAN – also exclude favicon.ico
<! if (strstr($urlRequested, “favicon.ico”))
<! $isIgnored = true;
<! // **EVAN – end favicon.ico change
<!
if (!strstr($_SERVER['PHP_SELF'], ‘wp-admin’) && !strstr($_SERVER['PHP_SELF'], ‘wp-stattraq’) && !$isIgnored)
<! // **EVAN – make the “insert” a “Delayed” insert for performance
<! $wpdb->query(“INSERT DELAYED INTO $tablestattraq (session_id, access_time, ip_address, url, article_id, referrer, user_agent, browser, user_agent_type, search_phrase) values (‘”.$s_id.”‘, NOW(), ‘$ipAddress’,'$urlRequested’, ‘$article_id’, $referrer,’$userAgent’,'$browser’, $browser_type, ” . ($search_phrase==null?”NULL” : “‘$search_phrase’”) . “)”);
!> $wpdb->query(“INSERT INTO $tablestattraq (session_id, access_time, ip_address, url, article_id, referrer, user_agent, browser, user_agent_type, search_phrase) values (‘”.$s_id.”‘, NOW(), ‘$ipAddress’,'$urlRequested’, ‘$article_id’, $referrer,’$userAgent’,'$browser’, $browser_type, ” . ($search_phrase==null?”NULL” : “‘$search_phrase’”) . “)”);
$wpdb->show_errors();
3) Added in some additional referrer parsing plus antispam protection against some spam referrer strings
Changes:
$key = “q”
<! // **EVAN – added a few more search engines to parse for
<! }else if(strpos($referrer, “icerocket.”)!== false || strpos($referrer, “search.blogger”) !== false){
<! $key = “q”
<! }else if(strpos($referrer, “blogsearchengine.”)!== false){
<! $key = “p”
}else if(strpos($referrer, “yahoo.”)!== false){
$key = “p”
}else if(strpos($referrer, “aol.”) !== false || strpos($referrer, “netscape.”) !== false){
$key = “query”
}
<! // **EVAN – Antispam for search queries
<! else if(
<! strpos($referrer, “bingo”) !== false ||
<! strpos($referrer, “backgammon”) !== false ||
<! strpos($referrer, “casino”) !== false ||
<! strpos($referrer, “oyun”) !== false
<! )
<! {
<! return null;
<! }
<! // ** EVAN – end Antispam for search queries
if($s != null && $s != ”){return $s;}