/ Published in: PHP
A solution to tracking for example RSS feed usage - no Javascript required. * Note, an Apache .htaccess/httpd.conf edit is required - see code comment. * Example usage - see code comment. * Inspired by, nojsstats.appspot.com (Part of the OLnet/ OER tracking project.)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** Redirect to a Piwik webbug (1 pixel image), or the Google-Analytics one. OLnet.org / OER tracking project. @copyright 2010 The Open University. Usage - Piwik - title=X, r=referrer are optional, <img alt="" src="http://localhost/track/PI-1/example.org/path/to/123?title=My+Title" /> Usage - Google-Analytics, <img alt="" src="http://localhost/track/UA-1234-5/example.org/path/to/123?title=My+Title&r=http%3A//referer.example.com/" /> An Apache .htaccess/httpd.conf edit is required: <IfModule mod_rewrite.c> RewriteEngine on # If the file/dir is NOT real go to index RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L] </IfModule> <IfModule !mod_rewrite.c> # If mod_rewrite is NOT installed go to index.php ErrorDocument 404 index.php </IfModule> */ // Substitute your local Piwik here. #define('PIWIK_TRACKER', "http://localhost/my_piwik/piwik.php"); $local_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Optional Referrer/title - use parse_url for crude parsing. $request_string = NULL; // Piwik $request_string = piwik_analytics_bug_url($matches, $title, $referer); } // Google/Urchin? $request_string = google_analytics_bug_url($matches, $title, $referer); } //ELSE: Yahoo? // Error. if (!$request_string) { } // OK, do the redirect to the web bug (temporary). echo " DEBUG, redirect: $request_string "; /* Based on, http://dev.piwik.org/svn/trunk/core/Tracker/Visit.php http://www.burtonkent.com/wp-content/uploads/piwik-tag.php */ function piwik_analytics_bug_url($matches, $title=NULL, $referer=NULL) { // non-Javascript solution can't get screen-resolution, Flash, Java, other plugin capabilities. # idsite - Piwik site ID. $request['idsite'] = $matches[1]; # url - Requested URL. $scheme = 80==$_SERVER['SERVER_PORT'] ? 'http://' : 'https://'; $request['url'] = $scheme . $matches[2]; # urlref - Referrer. $request['urlref'] = $referer; # title, action_name? $request['title'] = $title; $request['action_name']= $title; # cookie - Are cookies enabled? /*if (isset($_SERVER['HTTP_COOKIE']) && $_SERVER['HTTP_COOKIE'] != '') { $request['cookie'] = 1; } else { $request['cookie'] = 0; # or possibly not set? Hmm, not convinced! }*/ # (d,) h, m, s - hours, minutes, seconds (, days?) # rand - random number - quick 17 precision random number. # rec - record? 1 by default $request['rec'] = 1; } /* Based on http://nojsstats.blogspot.com/ */ function google_analytics_bug_url($matches, $title=NULL, $referer=NULL) { 'utmje'=>'0', 'utmfl'=>'-', 'utmjv'=>'-'); //'hid' Another number? $request['utmac'] = $matches[1]; $request['utmhn'] = $p['host']; $request['utmdt'] = $title; $request['utmr' ] = $referer; # utmn - Random number? }
URL: http://olnet.org/node/149