Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

AdBlocker detection snippet with jQuery and Google Analytics send event.

For those who are interested I made my first GitHub repository :)

It's an Adblocker detector with jQuery which also sends an Google Analytics event. I found some snippets online but none of them worked because they didn't wait until the page was fully loaded and AdBlock was not finished altering the DOM. Giving false negatives.

Anyway hope some of you find use in it :)

https://github.com/rhoekman/adblocker-detection

/* is the "ohDear" element where the ads would go? */
/* so the height == 0 is checking for their presence? */
if (jQuery('.ohDear').height() == 0)
/* is ga a built in function of some kind? */
ga('send', 'event', 'Ads', 'Inactive', 'AdBlocker Active');
/* are the parameters for ga preset? */

Thanks for any insights :D

1 Answer

I would love to see comments cause I have no idea what that means. Assuming it works that's very cool that you can do that.

Hi John,

I've updated the README.md on GitHub with motivation and additional notes.

-Rick