Introducing GOOPTracker

December 14th, 2008

GOOPTracker is an ad click tracker for publishers who have ads on their site(s). This is an alternative solution to other ad click scripts such as ClickAider and AsRep to name a few.

So what makes this one different from the others?
To start, its free. The code isn’t encrypted or hard to look through… you can easily understand what is going on through the lines of the code and I have made comments throughout it as well. You don’t need to sign up, or pay; you just download the files, configure/modify it ever so slightly to fit your needs (if you want), that is all. The script is MIT License, but I appreciate any enhancements or updates you have done to the code to help not me but everyone.

What are the advantages of this script compared to the others?
Its more accurate, to be honest. The scripts I have used don’t really capture the clicks as well as this one does. It isn’t 100%, but its a higher percentage than what the other scripts claims. But how do I know this? Because I have debugged the code from the other scripts and narrowed it down to what was working and what wasn’t working, and found out how and why it wasn’t… then made it work.

Can you give me an example of how you improved it, and how you made it more accurate?
Sure I can, and once I give you this example, just watch the other scripts implement it into theirs. First, I don’t use the onFocus event to the iFrame, this only applies to Internet Explorer. Second, I don’t track the coordinates of the cursor going all over the place of the screen for the other browsers. With those 2 events limited from my script, the only way to capture if the cursor is on the iFrame, is with the use of the onMouseOver and onMouseOut events. But here is the catch, you don’t apply these events to the iFrame itself, because of security reasons you can’t for the most part, but you create a div that wraps around the iFrame and attach the events to the div (many thanks to Dhryn for this suggestion and fix).

Good idea. But what else can your script do?
Try this with the other scripts mentioned: Go to your site with the browser FireFox. Hover over your ad. And press “Control/Command + R” or “F5” on the keyboard. Guess what? You just clicked on that ad. As mentioned before, the other scripts track the cursor position to detect if the user is over the ad, but they don’t check if the user refreshes the page. So your user could refresh your page 20+ times (which is unlikely, but you never know) with their cursor over your ad. Your script is counting each and every false click on your site from all the users who use the F5 key or Control/Command + R combo.

Ok, those are 2 good examples. What else can your script do?
That’s all, really. It does track the URL, Page Title, IP adress, Browser, and the date and time the ad was clicked on. Did I forget to mention this is version 0.1? Well, it is. So that is all you can do with it. You can attach your own custom values that you want to track, if you wanted.

How?
This is how you initiate the GOOPTracker in your script (assuming you have already set up the table in your MySQL database)

[js]
var GOOPTracker = new Object();
GOOPTracker.base_url = “http://gregathons.com/”; // default: “http://” + document.domain + “/”
GOOPTracker.tracker = “include/gooptracker.php”; // default: “gooptracker.php”
GOOPTracker.custom = new Array(‘custom value’, ‘another custom value’, ‘etc’); // default: -none-
[/js]

Then in your PHP script:

[php]
// define custom variable column names here, but make sure the column exists or you will get an error
$variable = array();
$variable[0] = “special_column_1”; // this gets the first value of GOOPTracker.custom
$variable[1] = “special_column_2”; // this gets the second
$variable[2] = “cool_column_3″; // the third, etc, etc

// get custom variables… lets assume that there 500 custom (haha, yeah right!)
$custom = ”;
for($i = 0; $i < 500; $i++) {
if(isset($_GET[“variable” . $i])) {
$custom .= “`” . $variable[$i] . “`='” . add($_GET[“variable” . $i]) . “‘, “;
} else {
break;
}
}
[/php]

You will have to look at that script several times to understand whats its doing, but once you know, its nice.

What does GOOP stand for?
Gregory’s Object Oriented Programming … I was bored one day, got a little crazy in the head, then came up with that name :)

Here is the link to the code, have fun.

Again, this script is free. You are free to modify it to your liking, or use the methods I mentioned to help better track your scripts with your already own ad clicking scripts. I would like to improve on this vastly… tie it into a analytic’s engine, or make a ad server with this… the options are endless.

** EDIT **

Wait, what are the limitations?
There is one and only limitation to this script – and all the others in that fact. The page must unload. When you click on the ad and sends you to the page of the ad on the same page/window, it will work. If the ad opens in a new window or a new tab, it will not. So if guest comes by right click on the ad and selected “Open in New Window” or “Open in New Tab”, it can’t be tracked. There is no work around for this… and to be honest, I don’t know if there can be. BUT I am open for any suggestions/ideas, code samples, if you have them.

GOOPTracker > Javascript > PHP

6 Responses to “Introducing GOOPTracker”

  1. rd2cm Says:

    Hi,

    Do you have live web site example?
    I am new to all this and have no clue how to use it.

  2. Gregory Says:

    Sorry, I don’t have a live web site using this example.

    What is exactly are unclear on how to use this? Setting it up, PHP, Javascript?

  3. rd2cm Says:

    Where and how do I place Java script in the page with ad code?
    And I want to write to a file instead of SQL data base because my hosting site prohibits sql for ad tracking. Can you place your code to this page to track Amazon ad?

  4. rd2cm Says:

    I try to write to a file like this in .php:
    $file(“gooptracker.log”,”a”);
    $ip =$_SERVER[“REMOTE_ADDR”] ;
    $browser=$_SERVER[“HTTP_USER_AGENT”];
    $url=$_GET[“url”];
    $title=$_GET[“title”];
    $datetime=NOW();
    fwrite($file,$custom,$ip,$browser,$url,$title,$datetime,”\n”);
    fclose($file);

  5. rd2cm Says:

    I meant
    $file = fopen(“gooptracker.log”,”a”);

  6. Gregory Says:

    Firstly, put the javascript code between the and tags. Personally, I put javascript near the end just before the tag.

    The PHP code you provided won’t work because ythe way you are handling the “fwrite” function. You are passing more values/variables/parameters to the “fwrite” function. Try doing this:

    $file = fopen(“gooptracker.log”, “a”);
    $string = $_SERVER[“REMOTE_ADDR”] . ” “;
    $string .= $_SERVER[“HTTP_USER_AGENT”] . ” “;
    $string .= $_GET[“url”] . ” “;
    $string .= $_GET[“title”] . ” “;
    $string .= date(“Y-m-d G:H:i”);
    fwrite($file, $string);
    fclose($file);

    Let me know how that goes.