Skip to content

Instantly share code, notes, and snippets.

@chrisblakley
Last active August 29, 2015 14:10
Show Gist options
  • Save chrisblakley/ca7a61aa054402248d1b to your computer and use it in GitHub Desktop.
Save chrisblakley/ca7a61aa054402248d1b to your computer and use it in GitHub Desktop.
Detect if users are blocking your ads using jQuery
<style>
.hidden {display: none;} /* Just for reference. This should be in your stylesheet! */
</style>
<div class="extra_resources">
<!-- [AD_CODE_HERE] -->
</div>
<a class="blockdetection hidden" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VALMBPW4PWH8S" target="_blank"><img src="donate_image.png" alt="Donate via Paypal" /></a>
$(window).on('load', function(){
if ( $('.extra_resources').length ) {
if ( $('.extra_resources').height() < 1 ) {
$('.blockdetection').removeClass('hidden');
ga('send', 'event', 'Ads Blocked', 'Using Browser Extension'); //Log the event in Google Analytics
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment