Created
July 20, 2011 10:32
-
-
Save mikeflynn/1094737 to your computer and use it in GitHub Desktop.
Tracking Clicks on iFrame Ads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Limitations: | |
// 1. We won't know where they are headed. | |
// 2. If the ads open in a new window, it doesn't trigger the unload event. | |
// 3. If there are multiple ad units in the iframe, we won't know which one was clicked. | |
function iframe_click_tracking(selector) { | |
jQuery(selector).bind('mouseover', function() { | |
// If they are over the ad and click, the unload will trigger to log the click. | |
jQuery(window).unload(function(){ // Event: onbeforeunload | |
jQuery.ajax({url:'http://local.logger.com/logger/?log=mobile&message=realclick', async: false}); | |
}); | |
// If they leave the ad, then they aren't going to click. Kill the unload event. | |
jQuery(this).mouseout(function(){ // Event: onmouseout | |
jQuery(window).unbind('unload'); | |
}); | |
// So if the ads open in a new window and the unload isn't called, kill the unbind after a while. | |
setTimeout(function(){ | |
jQuery(window).unbind('unload'); | |
}, 2000); | |
}); | |
} | |
iframe_click_tracking('div.ads iframe'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment