Detecting Ad-blocked Pages
Detailed guide on detecting ad-blocked pages via the RudderStack JavaScript SDK.
The JavaScript SDK provides a way to send a page view containing relevant markers that determine whether a page is ad-blocked. You can analyze this data to find what percent of your website's page views are affected by ad blockers.
Sending an ad-blocked page view
To send an ad-blocked page view, load the JavaScript SDK as shown below:
rudderanalytics.load(WRITE_KEY, DATA_PLANE_URL, {
sendAdblockPage: true,
sendAdblockPageOptions: {
integrations: {
All: false,
Amplitude: true
}
}
});The following sections describe the properties included in the snippet above.
sendAdblockPage
sendAdblockPageThis property enables the JavaScript SDK to make a call to load the Google AdSense library. If RudderStack fails to load this library, it concludes that an ad blocker is enabled on the page.
Since most ad blockers block the request to the Google AdSense servers, we assume this approach to be a good measure to detect ad-blocked pages.
sendAdblockPageOptions
sendAdblockPageOptionsThe JavaScript SDK will make an implicit page call about the ad-blocked pages if sendAdblockPage is set to true.
With sendAdblockPageOptions (which internally contains the IntegrationOpts object), you can provide the destinations to which you want to forward this page call.
For more information on filtering destinations, refer to the Filtering selective destinations section of the SDK guide.
The implicit page call semantics is as shown:
rudderanalytics.page(
"RudderJS-Initiated",
"ad-block page request",
{
path: "/ad-blocked",
title:
"error in script loading:: src:: http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js id:: ad-block"
},
sendAdblockPageOptions
);Contact us
For queries on any of the sections covered in this guide, you can contact us or start a conversation in our Slack community.
If you come across any issues while using this SDK, you can submit them on our GitHub issues page.
Last updated
Was this helpful?