Google Adsense Tracking
So today i decided to utilise my adsense account which i’ve had since 2004. I can’t remember the last time I actually
used it, but it hasn’t been active for quite awhile.
Anyway, I’ve put some ad code here and there and I thought to myself, wouldn’t it be great if I could detect when someone
clicked on an ad and do some simple logging. Now I know adsense allows you to gather certain information using channels, but i wanted
to do my own tracking.
So the following is what I came up with:
Basically the script runs the function adsense when the window/page loads.This fuction scans through your page
and attaches an ‘onfocus’ event to your google Adsense ads. All google adsense ads are in iframes (generated by the javascript you include in you pages).
So, every time someone gives focus to an advert, the AdSenseLog function is called.
I haven’t included the code i’m using for logging as i’m still working on it, but there is no reason why you
couldn’t utilise ajax to call some server side script/functions to do some logging.
You’ll also notice that I’ve created my own function called AttachEvent. This is because IE doesn’t support.
The DOM friendly ‘addEventListener’ like Mozilla/FireFox does. IE uses its own event managment called ‘attachEvent’ (lower case ‘a’).
Therefore I needed a simple cross-browser solution as above, which i’ve called ‘AttachEvent’ (uppercase ‘A’).
Related posts:
- Google Adsense Referrals are going! Just a quick note to everyone out there, that...























Recent Comments