Search code examples
javascriptadobe-analytics

Adobe DTM Ad Blocker Identifier


I have a HTML element in the page JavaScript that returns true when there is ad-blocker on the page and 'False' when there is no ad blocker.

I am new to DTM and had a Query regarding capturing this in Omniture event on page load. So whenever JS function returns 'True' I want to increment an Omniture event. And do nothing when the function returns false.

This is the JS function I have got implemented on the page:

function AdBlockEnabled() { 
  var ad = document.createElement('ins'); 
  ad.className = 'AdSense'; 
  ad.style.display = 'block'; 
  ad.style.position = 'absolute'; 
  ad.style.top = '-1px'; 
  ad.style.height = '1px'; 
  document.body.appendChild(ad); 
  var isAdBlockEnabled = !ad.clientHeight; 
  document.body.removeChild(ad); 
  return isAdBlockEnabled; 
}

Solution

  • DTM does not offer a way to conditionally populate an event in the event fields of a page load rule, so you will need to populate s.events via javascript.

    Basically something like (using event1 in example):

    s.events=s.events||'';
    s.events+=AdBlockEnabled()?'event1':'';
    

    If you are looking to do this on specific page(s), you can create a Page Load Rule with conditions targeting the page(s).

    If it is to be evaluated on every page load, then you can stick with a Page Load Rule with no conditions, or you can put it in the custom code box in the Adobe Analytics tool config.