danger

You are viewing documentation for an older version.

Click here to view the latest documentation.

Detect Ad-blocked Pages

Detect ad-blocked pages via the RudderStack JavaScript SDK.

The JavaScript SDK lets you send a page view containing the relevant markers that determine whether a page is ad-blocked. You can analyze this data to find what percentage of your website’s page views are affected by adblockers.

Sending an ad-blocked page view

To send an ad-blocked page view, load the JavaScript SDK as shown:

rudderanalytics.load(WRITE_KEY, DATA_PLANE_URL, {
    sendAdblockPage: true,
    sendAdblockPageOptions: {
        integrations: {
            All: false,
            Amplitude: true
        }
    }
});

The properties included in the above snippet are explained below:

  • sendAdblockPage: 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 adblocker is enabled on the page.
info
Since most adblockers block the request to the Google AdSense servers, this approach is assumed to be a good measure to detect the ad-blocked pages.
  • sendAdblockPageOptions: If the sendAdblockPage property is set to true, the JavaScript SDK makes an implicit page call about the ad-blocked pages.

With sendAdblockPageOptions (containing the IntegrationOpts object), you can specify the destinations to which you want to forward this page call.

Refer to the Filtering selective destinations guide for more information on filtering the destinations.

The implicit page call semantics is shown below:

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
);

Questions? Contact us by email or on Slack