• How it works
  • Partners
  • Blog
  • Docs
  • Sign up
  • Client Area

Ad Publishers

  • Getting started with Ads – Common Issues & FAQs
  • Payment & Fee FAQs
  • Setting up your ads.txt file
  • Installing the ad script on your page
  • Creating an ad placement
  • US Privacy law compliance steps
  • Ad script lifecycle events
  • Detecting ad-blocking users
  • Special ad format: Sticky Stack
  • Placement Configuration API

CMP

  • Adding custom consents or disclosures
  • Creating a link for the user to manage their consents

Sponsor

  • Getting started with Sponsor

Users

  • Getting started with Users
  • Adding the Users SDK to your site
  • Initializing the Users SDK
  • Launching the login/registration screen
  • Managing user sessions
  • Users SDK API Reference
  • NitroPay
  • Docs
  • Ad Publishers
  • Detecting ad-blocking users

Detecting ad-blocking users

This code lets you detect with a high degree of reliability if a user is blocking NitroPay’s ad script.

Embed the following script anywhere on your page

<script type="text/javascript">
var npDetect = new (function () {
    this.blocking = false;
    var errcnt = 0;
    function testImg() {
        var i = new Image();
        i.onerror = () => {
            errcnt++;
            if (errcnt < 3) {
                setTimeout(testImg, 250);
            } else {
                npDetect.blocking = true;

                if (document.dispatchEvent && window.CustomEvent) {
                    document.dispatchEvent(
                        new CustomEvent('np.blocking', {
                            detail: {
                                blocking: npDetect.blocking,
                            },
                        })
                    );
                }
            }
        };
        i.onload = () => {
            npDetect.blocking = false;
        };

        i.src = 'https://s.nitropay.com/1.gif?' + Math.random() + '&adslot=';
    }
    testImg();
})();
</script>

Embed this script to listen for the np.blocking event. You should perform whatever task is necessary such as re-adjusting your layout or displaying an appeal to the user if this event is fired.

<script type="text/javascript">
document.addEventListener('np.blocking', (e) => {
    if (e.detail.blocking) {
        // the user is blocking the nitropay script
    }
});
</script>
Share this document:
  • Facebook
  • Twitter
  • LinkedIn
Updated on January 25, 2023
Ad script lifecycle eventsSpecial ad format: Sticky Stack
© GG Software, LP
Privacy Policy | Terms of Use | Contact us