Version: 2.67.0

Adblock detection

The THEOplayer Ads API allows developers to detect adblockers, and react accordingly.

Adblock detection

SDK

Web SDKAndroid SDKiOS SDKtvOSAndroid TV SDKChromecast SDK
YesN/AN/AN/AN/AN/A

Adblock detection is typically a challenge in browsers. Hence, SDKs besides the Web SDK are considered 'not applicable'.

API

Below are some resources on adblock detection through the Ads API:

Code examples

Web SDK

The below code snippet uses the aderror event to detect ad blockers, and blockContentIfAdError to halt playback in-case of an adblocker.

// add an eventlistener to get custom behavior if there is an ad error
player.ads.addEventListener("aderror", function(event) {
// do something
});
// set the player source with ads and the blockContentIfAdError property
player.source = {
sources: {
src:
"http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest(format=m3u8-aapl)"
},
ads: [
{
sources:
"http://cdn.theoplayer.com/demos/advertisement/livereal-no-skip.xml"
}
],
// set this to true if you want to block the content
// default value is false
blockContentIfAdError: true
};

Note that blockContentIfAdError only works when you use the default advertisement integration. If you'd use Google IMA (or any other integration), you'll have to use the aderror event to halt playback.