Taking tutorial submissions! Please email them to dave[AT]icemelon[DOT]com for review. Thanks!

Latest Tutorials
IceMelon IM: Add IM Functionality to phpBB [Misc] Want to add site-wide member IM to your phpBB community? Sure you do. Simple step-by-step instructions inside.

IceMelon IM: Add IM Functionality to vBulletin [Misc] Want to add site-wide member IM to your vBulletin community? Simple step-by-step instructions inside.

Crawl Your Site for PageRanks [PHP] So you know your site has a PageRank of 8. What about the PRs of all the inner pages? This tutorial will teach how you to automate the process of grabbing all these PRs.

Create CAPTCHA images [PHP] Worried about bots? Then create CAPTCHA images to prevent bots from taking advantage of your site.

Convert SHN and FLAC files to MP3 [Misc] Low on disk space and have an insensitive ear? Here are some steps to converting SHN and FLAC files to MP3 format.

[View All]

Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m.

Awesome Tutorials

Track Google Adsense Clicks
By dave

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:
<script type="text/javascript">
function logClick() {
    window.focus();
    bug = new Image();  
    bug.src = 'http://yourdomain.com/trackerScript.php?pg=' + escape(document.title) + '&advertisement=' + escape(window.status);
}
</script>
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.
<iframe src="adsenseCode.htm" frameborder=0 width=468 height=60 onFocus='logClick()'></iframe>
Make sure that the body margin of adsenseCode.htm is set to 0; e.g. <BODY topmargin=0 leftmargin=0>.

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.

P.S. Check out my new site TheManWhoSoldtheWeb.com, where I publish guides and scripts on Internet Marketing and SEO. Here is a limited time freebie: the Rapid Google Indexer.


» Bookmark this Tutorial
» Bookmark IceMelon
Icemelon -- Track Google Adsense Clicks -- PHP, CSS, Javascript Tutorials, & More!
  © 2005-2010 Icemelon.com   Email: dave[AT]icemelon[D0T]c0m