Google AdWords (or any third party) tracking with onclick that really works

Disclaimer: this works for me and my clients today (Sep 2010). If Google or one on the web browsers change something, this may break all tracking, so use this on your own risk.

Below is working code fragments. In the process of making the code work, there was following problems / symptoms:

  • Chrome and Safari refused to follow / ping image src at all;
  • Firefox seemed to ignore / not follow googleadservices.com issued redirect 302 to googleads.g.doubleclick.net;
  • It all seemed like some sort of Same origin policy;
  • Firefox plug-in Firebug Net Panel showed strange question marks in Persist mode (seemed like request never completes). And on next click it showed – aborted.

This all was caused by fact, that after JavaScript function returned, original – “href” handler somehow canceled image download request. So by adding setTimeout it has nothing to cancel any more.

Your HTML code:
<a href="http://some-lead-page-where-you-cannot-add-or-change-code" onclick="googletrack()">Some lead / sale / page view / other action</a>

Simple example code:
function googletrack(){
setTimeout('(new Image()).src="http://www.googleadservices.com/pagead/conversion/0123456789/?label={yourlabelprovidedbygoogle}&guid=ON&script=0"',100);
}

Example code with custom label passed as parameter:
function googletrack(label){
setTimeout('(new Image()).src="http://www.googleadservices.com/pagead/conversion/0123456789/?label='+label+'&guid=ON&script=0"',100);
}

Other fields such as value, etc. can be added as needed.

In my setup I attach onclick handler dynamically using JavaScript that is called from HTML in JavaScript defer mode. Also links in question opens in new window (not sure if it will work if opening in the same window).

Tested on Internet Explorer 8.0.7600.16385, Mozilla Firefox 3.6.8, Google Chrome 6.0.472.53, Opera 10.61, Apple Safari 5.0.1.

Updated Sep 17, 2010.

August 2010, links

stackoverflow.com – Strangest programming language feature

Kyle Brandt writes about – Should Developers have Access to Production?

International Telecommunications Union is considering eliminating leap seconds from the Coordinated Universal Time (UTC). Read here.

Icons of the Web. A large-scale scan of the top million web sites (per
Alexa traffic data) was performed. We retrieved each site’s icon…

Searching For Backdoors From Rogue IT Admin / Staff

Joel on Software – Command and Conquer and the Herd of Coconuts

IIS 7.5 error: Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

Today I installed Clean Windows Web Server 2008 R2 64-bit with IIS 7.5. To my surprise opening .NET 4.0 application I received the following error:


IIS 7.5 Detailed Error - 500.21 - Internal Server Error

Server Error in Application "DEFAULT WEB SITE"
Internet Information Services 7.5

[Error Summary]
HTTP Error 500.21 - Internal Server Error
Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

[Detailed Error Information]
Module IIS Web Core
Notification ExecuteRequestHandler
Handler PageHandlerFactory-Integrated
Error Code 0x8007000d
Requested URL http://localhost:80/default.aspx
Physical Path C:\inetpub\wwwroot\default.aspx
Logon Method Anonymous
Logon User Anonymous

[Most likely causes:]
•Managed handler is used; however, ASP.NET is not installed or is not installed completely.
•There is a typographical error in the configuration for the handler module list.

[Things you can try:]
•Install ASP.NET if you are using managed handler.
•Ensure that the handler module's name is specified correctly. Module names are case-sensitive and use the format modules="StaticFileModule, DefaultDocumentModule, DirectoryListingModule".

[Links and More Information]
IIS core does not recognize the module.
View more information »

As it turns out, some glitch caused this problem, and somehow .NET was not registered with IIS.

Running the following commands solved this issue:

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i