Use the detection result in your own code
How your own JavaScript receives the result of each check (Plus), what each field means, and examples.
On this page
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:
trueorfalse. It isfalsewhen we are not sure: you only gettruewhen 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), orunknown. It isnullwhen ads are not blocked. - strength:
strong, orsoftwhen only part of the signals point to a blocker. - browser: the browser family, for example
chrome,firefox,safari,edgeorbrave. - member:
truefor a signed-in ad-free member. Members are never "blocked".
Three ways to read it
- 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>
- A browser event on
window:
window.addEventListener('cedar-harbor', function (e) {
console.log(e.detail.blocked);
});
- 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.blockedistrue, show a banner of your own instead of (or as well as) our notice. - Gate a download: when
result.blockedistrue, ask the visitor to allow ads before the download link appears. - Send it to your analytics: record
result.blockedandresult.typeas 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