Clicktracker code from PodCamp Toronto

Warning: this content is older than 365 days. It may be out of date and no longer relevant.

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, https://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=”https://www.christopherspenn.com/youve-discovered-the-missing-link/”; //change to end destinationip = _SERVER[‘REMOTE_ADDR’]; // gathers IP address of userrefer = _SERVER[‘HTTP_REFERER’]; // gathers referring page of user – good to see where clicks are coming fromtimestamp = date(“Y-m-d H:i:s”, time()); // timestamp
filedate = date(“Ymd”, time()); // creates file-friendly date format for logfile = “filedate-clicklog.csv”; // the log file namehandle = fopen(file, “a”); // open the file in write modestream = “ip,refer,timestamp\n”;
fwrite(
handle, stream);
fclose(
handle);

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

Comments

2 responses to “Clicktracker code from PodCamp Toronto”

  1. Daniele Rossi Avatar

    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.

  2. Daniele Rossi Avatar

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Shares
Share This