• Home
  • About

szehau's weblog

Life, Internet, Software, Gadgets, Programming and Investments

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

My Adsense Tracker

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

About Sze Hau

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

Email News Letter

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

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

LED Downlight

Troubleshooting A Flickering LED Downlight

February 13, 2016 00:29 By Sze Hau

Repair A Broken iPhone Lightning Cable

January 30, 2016 00:54 By Sze Hau

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

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

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