JavaScript API

The Adtoniq JavaScript API provides a callback mechanism for your JavaScript code so that you can be alerted of various Adtoniq events. The following functions are available:

addAdBlockerCallback

The addAdBlockerCallback function is used to add a callback function when an ad blocker is detected. The function is passed three parameters which are all booleans:

  1. isNetwork indicates whether the ad blocker blocks network connections to ad services
  2. isElemHiding indicates whether the ad blocker hides or collapses ad units
  3. isAcceptable indicates whether the ad blocker is configured to allow acceptable ads
<script>
 if (typeof(adtoniq) != "undefined") adtoniq.addAdBlockerCallback(
 function(isNetwork, isElemHiding, isAcceptable) {
 if (isElemHiding)
 document.getElementById('elemhiding').style.display='none';
 if (isAcceptable)
 document.getElementById('accads').style.display='none';
 });
 </script>

The script shown above is used to update the two lines below. View the source code of this page to see how the DOM structure is set up for this.

You do not have acceptable ads enabled.
You do not have element hiding enabled.

addNoAdBlockerCallback

The addNoAdBlockerCallback function is used to add a callback function when no ad blocker is detected. The function is passed no parameters.

<script>
 if (typeof(adtoniq) != "undefined")
   adtoniq.addNoAdBlockerCallback(function() {
     console.log('No ad blocker in use');
 });
 </script>

onBlocked

The onBlocked function is used to add a callback function as soon as the first ad block detection signal is received. This will usually be much faster than addAdBlockerCallback because it will fire on the first ad block detection signal, as opposed to waiting for all signals to arrive. If you want to interact with your ad blocked audience, you should hook this event.

The function is passed no parameters.

<script>
 if (typeof(adtoniq) != "undefined")
   adtoniq.onBlocked(function(){console.log('Hello ad blocked user');});
 </script>