Use the detection result in your own code

2 min readUpdated on

How your own JavaScript receives the result of each check (Plus), what each field means, and examples.

On this page
  1. What you receive
  2. Three ways to read it
  3. Examples

On the Plus plan, your own JavaScript can receive the result of each check, so you can build your own logic: a download gate, a video player that behaves differently, your own message, or a line in your analytics. It works with the notice on and with the notice off (then AdCobalt only measures and hands you the result).

Your account has its own names for this. You find them, with ready-to-copy examples, on the Install tab of any website, under Detection result for your own code. The names below (mapleRiver, cedar-harbor, willowStone) are only examples.

What you receive

One small object per page view, after the check has finished:

  • blocked: true or false. It is false when we are not sure: you only get true when we would also show a notice.
  • type: how ads are blocked: extension (an ad-blocking extension), browser (protection built into the browser, such as Brave Shields or Firefox strict mode), network (a DNS filter, Pi-hole, or an office or mobile network), or unknown. It is null when ads are not blocked.
  • strength: strong, or soft when only part of the signals point to a blocker.
  • browser: the browser family, for example chrome, firefox, safari, edge or brave.
  • member: true for a signed-in ad-free member. Members are never "blocked".

Three ways to read it

  1. A callback: define a function with your callback name before the AdCobalt code. It is called once per page view.
<script>
  window.mapleRiver = function (result) {
    if (result.blocked) {
      console.log(result.type, result.strength);
    }
  };
</script>
  1. A browser event on window:
window.addEventListener('cedar-harbor', function (e) {
  console.log(e.detail.blocked);
});
  1. A last-result variable, for code that starts later (for example in single-page apps): window.willowStone. It is empty until the first check has finished.

Examples

  • Show your own message: when result.blocked is true, show a banner of your own instead of (or as well as) our notice.
  • Gate a download: when result.blocked is true, ask the visitor to allow ads before the download link appears.
  • Send it to your analytics: record result.blocked and result.type as a custom dimension, so you can compare visitors with and without ad blockers.

Be gentle with network visitors. People on an office, school or mobile network with filtering usually cannot switch it off. A soft message works better for them than a hard block.

If your code has an error, it never breaks AdCobalt or your page, and we are not told about it. Nothing extra is sent or stored for this: no new requests and no cookies.

Still stuck? Sign in and use Help & Support: it checks your setup and you can write to us from there.

Get help in your dashboard