• Home
  • About

szehau's weblog

Life, Internet, Software, Gadgets, Programming and Investments

  • life log
  • internet
  • programming
  • software
  • working holiday
  • gadget
  • project

My Adsense Tracker

July 1, 2005 00:09 by Sze Hau 5 Comments

I have created an Adsense Tracker script to keep track adsense clicks on my websites. The scripts are pretty simple but can be expanded to generate a useful report. However, the scripts only work for ad unit and not ad link.

My Adsense Tracker contains 3 parts of code:

  1. Javacript tracker – to be added at webpages
  2. Tracking script (PHP) – the actual script that records the adsense clicks
  3. Report (PHP)

The JavaScript tracker looks like this:

<script type="text/javascript"><!--
function hit() {
  window.focus();
  if (window.status) {
    img = new Image();
    img.src = 'http://www.yoursite.com/adsense_track.php'
      + '&ads=' + escape(window.status) // title of the adsense unit
      + '&pageId=home' // page id
      + '&mg=4321432143214321'; // a magic number
  };
};
 
var elements;
elements = document.getElementsByTagName("iframe");
for (var i = 0; i < elements.length; i++){   if(elements[i].src.indexOf('googlesyndication.com') > -1) {
    elements[i].onfocus = hit;
  }
}
//-->

The Tracking script (name it as adsense_track.php) might look like this:

< ?php // mg - magic number // mg is just a simple checking to make sure this file is // executed from javascript if (isset($_GET['mg']) && $_GET['mg']==4321432143214321) {   $ads = $_GET['ads']; // ads title   $pageId = $_GET['pageId']; // page id   $time = mktime (); // timestamp   $ipAdd = getenv("REMOTE_ADDR"); // visitor's ip address   //   // Do some checking here   // e.g. Query database and ignore double clicks within 1 second   //   // Insert all data into database } ?>

For the Report, I wrote my adsense clicks reports based on:

  • Time range
  • Ads title and sort by total of clicks

From this two reports and together with the report from adsense account, you can actually know something that google never tell you. Such as

  • analyse the performance of each ads and filter out irrelavant ads
  • estimate the cost of the click for certain ads
  • what your visitors looking for and which ads is more attractive

More from my site

  • Wordpress with PloggerWordPress with Plogger
  • Electronics Project – Raspberry Pi + Attiny85 + LCD 1620Electronics Project – Raspberry Pi + Attiny85 + LCD 1620
  • Google Adsense is ready for Christmas!Google Adsense is ready for Christmas!
  • PPS Unbanned My BlogPPS Unbanned My Blog
  • Miss a Day Miss a LotMiss a Day Miss a Lot
  • Electronics Project – Simple Card Read Keyboard Emulator Using Arduino Pro MicroElectronics Project – Simple Card Read Keyboard Emulator Using Arduino Pro Micro

Filed Under: programming

About Sze Hau

Geek. Love programming. Coffee addicted. Married with a child. Working towards financial freedom.

Comments

  1. dannyFoo says

    July 1, 2005 02:14 at 2:14 am

    Well done, I guess you’re too lazy to login and check most of the time. :P Anyway, click checking is one thing. The other important thing is whether the value of the ad clicked is high or not. ;)

    Cheers.

    Reply
  2. LcF says

    July 1, 2005 03:03 at 3:03 am

    great! but you aren’t going to release the code?

    Perhaps the script can collect more data like source url, destination url, time, etc?

    I found one at http://www.monetizers.com/php-click-tracker.php

    Reply
  3. Hallaj says

    July 1, 2005 03:17 at 3:17 am

    Sweet!

    Reply
  4. szehau says

    July 1, 2005 21:28 at 9:28 pm

    dannyFoo:
    Ya … I only login into adsense once or twice a day to check my detailed earning statistic. But I can always know my earning because I have installed Adsense Notifier. at my Firefox browser It shows the summary of my earnings and it is updated every 20 minutes.

    LcF
    I have a version of script which only write the data to file, so I can’t generate a useful reports from the collected data (only able to show ads title and the count of clicks). Later when I have time, I will develop another version of adsense tracker using database (mysql).

    You can add referer url by append a line to the javascript:
    + '&ref='+ escape(document.referrer)
    I don’t think we can get ‘real’ destination from javascript because the destination url always point to google adsense’s url.
    The adsense_track.php above does keep the timestamp of the click.

    For me, the source url is not that useful because it could be an url of your site itself.

    I will try to write the code within this month and will update you all again. :)

    Reply

Trackbacks

  1. szehau weblog » Blog Archive » Adsense Tracker says:
    July 23, 2005 02:08 at 2:08 am

    […] As I have promised to upload my adsense tracker script at previous post, My Adsense Tracker, finally I have finalized my codes and uploaded it here. At the time I have finished the coding and testing, I found AdsenseLogger. Em… but never mind, at least I have my own tracker. […]

    Reply

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Email News Letter

Sign up to receive updates daily and to hear what's going on with us

  • Facebook
  • Google+
  • Instagram
  • Twitter

More Posts

5 Essential Things You Need To Have At Your Home During The COVID-19 Pandemic

June 1, 2021 22:15 By Sze Hau Leave a Comment

LED Downlight

Troubleshooting A Flickering LED Downlight

February 13, 2016 00:29 By Sze Hau Leave a Comment

Repair A Broken iPhone Lightning Cable

January 30, 2016 00:54 By Sze Hau Leave a Comment

Sponsored Links

Blog Network

  • Personal Fincance Personal Finance – Personal Money Tips, Stock Investment, Small Business and Make Money Online
  • Snippet IT Information technology news, ideas and experiences and opinions

szehau’s weblog

szehau is a software programmer that has strong interest in the world of programming and Internet. He is graduated in University of Malaya, Malaysia with a Bachelor’s degree in Software Engineering. He draws on his passsion for web programming to share with others how to build a successful websites.

Recent

  • 5 Essential Things You Need To Have At Your Home During The COVID-19 Pandemic
  • Troubleshooting A Flickering LED Downlight
  • Repair A Broken iPhone Lightning Cable
  • New Gadget – MacBook Pro with Retina Display (2015)
  • One Watt LED Night Light

Search

Tags

adsense advertisement baby blog blogtal Canon EOS 400D Chinese New Year Christchurch CNY DiGi electronic Facebook FBM Flickr Flickr Uploadr Google Google Maps Google Search Results Google Webmaster Central H1N1 income tax investment joke KLCI KLSE Lake Tekapo Maxis Maybank2u Motueka movie mutual funds New Zealand PC Fair 2009 Queenstown restaurant for dinner sharing stock trackback travel Twitter unit trust visa wordpress wordpress plugin working holiday

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in