How to detect adblocker from Google Tag Manager: [GTM tutorial]

What made me write this post? – A simple google search of “how to detect adblocker” in google yields so many results. However, none of them were satisfactory to me. Some involved installing third party plugins and some wanted me to call an external JavaScript.

So, here is a really quick guide on how to detect adblockers using Google Tag Manager or otherwise.

detect adblocker and ad blockers

► First of all, if you don’t know what is a tag manager, read this post . It is best to use a tms (tag management system) for all digital marketing purposes.

► If you want to know how to quickly install Google tag manager, (plus, install google analytics) aka GTM on any website – Read this post.

Our Ads are non-intrusive and help us to run this blog.
Please add this website as an exception in your ad blocker.

If, for some reason you don’t use any tag management system, Mr. Avinash Kaushik has explained a way in his Occam’s Razor blog on how to do detect adblocker by native implementaion. (on page) It includes even Google analytics’ custom dimension.

In fact, the code I’ve put here is from that blog with just one modification.

Now, coming to our topic of detecting ad-blockers from tag management systems; if you are more of a ‘watcher’ than reader, probably this short video is for you.

If you like reading, carry on from – here.

Below is the simple logic – if you want to build your own code to detect adblocker.

Logic to detect adblocker from google tag manager

Step 1 and only 1 :- Create a variable in GTM to detect adblocker

Choose – Custom JavaScript and insert the below code.

google tag manager variable to detect adblockers
/*Simple Adblocker detector- */
function AdBlockEnabled() {
  var ad = document.createElement('ins');
  ad.className = 'AdSense'; = 'block'; = 'absolute'; = '-1px'; = '1px';
  var isAdBlockEnabled = !ad.clientHeight;
  window.localStorage.setItem('isAdblockEnabled',isAdBlockEnabled); // This is optional
  return isAdBlockEnabled;

Note that the window.localStorage.setItem is only optional. That is, if you wish to do something in future with this value, you can use it.

Our Ads are non-intrusive and help us to run this blog.
Please add this website as an exception in your ad blocker.

That’s pretty much it… There you go. You can either put it in a cookie, pass it to any other vendor, app etc.

Maybe you can use it to show a ‘humble request‘ like I do in this blog. 😀

This method of adblocker detection doesn’t involve any external scripts and therefore, the safest.


Leave a Reply

Your email address will not be published.