Clicktracker code from PodCamp Toronto

Someone reminded me recently that I haven’t posted the click tracking software I mentioned during PodCamp Toronto. This is it – to use it, edit the URL at the top of the code, then copy and paste it into its own directory on your server, naming the file index.php. Next, link to that directory – for example, http://www.FinancialAidPodcast.com/bumrush/ and it will automatically record a few statistics and then bounce the user invisibly to the destination you want them to go to.

The statistics it collects are:

  • IP address
  • Date
  • Time
  • Referring URL

No personally identifying information is collected, unless for some reason you mapped your static IP address to your personal domain, in which case, you probably want people to know that anyway. The stats themselves will be in a text CSV file stored in that same folder, broken out by day. It collects raw clicks, so if someone comes and visits you over and over again, it’ll record it each time.

Here’s the code:

<?php

$url=”http://www.financialaidpodcast.com”; //change to end destination

$ip = $_SERVER['REMOTE_ADDR']; // gathers IP address of user
$refer = $_SERVER['HTTP_REFERER']; // gathers referring page of user – good to see where clicks are coming from
$timestamp = date(“Y-m-d H:i:s”, time()); // timestamp
$filedate = date(“Ymd”, time()); // creates file-friendly date format for log
$file = “$filedate-clicklog.csv”; // the log file name
$handle = fopen($file, “a”); // open the file in write mode
$stream = “$ip,$refer,$timestampn”;
fwrite($handle, $stream);
fclose($handle);

// now redirect the user!
header(“Location:$url”);
?>

Related posts:

  1. PodCamp NYC Needs Your BRAIN
  2. The Spirit of PodCamp: Rockstars
  • http://www.superspud.com/ Daniele Rossi

    I’ve been waiting for this ever since you showed it during your presentation at PodCamp Toronto (I remember trying to frantically write it all down). Thanks again for sharing your genius!

    I’m wondering though if this code would work for the AddThis bug (addthis.com)? It allows the blog reader to choose which services they want to click (del.icio.us, technorati, etc.) instead of listing many icons.

  • http://www.superspud.com Daniele Rossi

    I’ve been waiting for this ever since you showed it during your presentation at PodCamp Toronto (I remember trying to frantically write it all down). Thanks again for sharing your genius!

    I’m wondering though if this code would work for the AddThis bug (addthis.com)? It allows the blog reader to choose which services they want to click (del.icio.us, technorati, etc.) instead of listing many icons.