As a publisher of Google Adsense ads, you only know the CTR and the revenue of these ads. Would you like to know a bit more? This tutorial will teach you how to track the ads that are being clicked, on what page they are being clicked, and who is doing the clicking.
If you're feeling any qualms, don't worry. If you read through the TOS [https://google.com/adsense/policies], no rules are being broken by this method. There is no need to modify any of Google's code.
A little bit of Javascript
The following Javascript function is the secret ingredient:
Include the above function.
Next, we need to call logClick everytime someone clicks on an Adsense ad. This is done by loading the ad through an IFRAME and embedding an onFocus event into the IFRAME tag. For example.
Make sure that the body margin of adsenseCode.htm is set to 0; e.g.
Quick explanation
Once the Adsense ad is clicked, the IFRAME that it has been embedded within will "focus," thus calling the Javascript function logClick. This function will then call trackerScript.php and pass to it the current page's title, as well as the current window status message. (Note: The URL of the clicked ad is displayed in the window status message. Eureka!)
Some PHP
The rest of the work is done in trackerScript.php. Essentially, all this script does it store values into your MySQL database. Here is a quick example:
$advertisement = $_GET['advertisement'];
$IP = $_SERVER['REMOTE_ADDR'];
$page = $_GET['pg'];
mysql_query("INSERT INTO adsenseStats (advertisement, IP, page) VALUES ('$advertisement', '$IP', '$page')");
The above code should be pretty much self-explanatory.
Well, that's a wrap. Be fancy and have your script keep track of more data.
Using your database, you can now discover which pages are generating the most clicks, which ads are generating the most clicks, and perhaps... with some intuition, which ads are generating the most revenue! Hope this tutorial proves helpful.
0 comments
Post a Comment