npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-adblocker-detect

v1.0.6

Published

A lightweight React component that detects if an ad blocker is active in the user's browser. It allows developers to conditionally render UI elements or trigger custom actions when ad blocking is detected, enhancing user messaging or monetization strategi

Readme

📛 React Adblock Detector

A lightweight, customizable React component that detects AdBlock usage and shows a user-friendly modal with instructions to disable it. Supports persistent detection and polling behavior.

npm version package size minified JavaScript Style Guide

total downloads total downloads per year total downloads per week total downloads per month

react-adblocker-detect


📦 Installation

npm i react-adblocker-detect

yarn add react-adblocker-detect

pnpm i react-adblocker-detect

bun add react-adblocker-detect

⚙️ Demo

Access Demos at:

Demo

Demo Persistent

Demo Persistent With Polling


📸 Screenshot

Modal 1

Modal 2


✨ Features

  • Detects common adblockers
  • Beautiful modal UI with step-by-step disable instructions
  • Persistent and polling behavior options
  • Fully configurable via props
  • Written in TypeScript

🚀 Usage

For React/Vite

// app.tsx or main.tsx
import React from "react";

import { AdblockDetector } from "react-adblock-detector";

import "react-adblock-detector/dist/index.css";

const App = () => {
  return (
    <div>
      <AdblockDetector
        config={{
          persistent: true,
          pollingTime: 10000, // in milliseconds
          title: "AdBlocker Detected!",
        }}
      />
    </div>
  );
};

export default App;

For Next.js (Pages Router)

// _app.tsx
import React from "react";
import type { AppProps } from "next/app";
import { CookieConsent } from "react-consent-management-banner";

import "react-consent-management-banner/dist/index.css";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <React.Fragment>
      <Component {...pageProps} />

      <AdblockDetector
        config={{
          persistent: true,
          pollingTime: 10000, // in milliseconds
          title: "AdBlocker Detected!",
        }}
      />
    </React.Fragment>
  );
}

For Next.js App Router

// layout.tsx
import React from "react";

import { AdblockDetector } from "react-adblock-detector";

import "react-adblock-detector/dist/index.css";

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html>
      <body>
        {children}
        <AdblockDetector
          config={{
            persistent: true,
            pollingTime: 10000, // in milliseconds
            title: "AdBlocker Detected!",
          }}
        />
      </body>
    </html>
  );
}

⚙️ Configuration

The AdblockDetector component accepts a config prop of type Partial<IAdBlockerConfig>.

Default Config

const defaultConfig = {
  persistent: false,
  title: "AdBlocker Detected",
  howToTitle: "How to Disable the Adblocker",
  description:
    "We noticed you're using an ad blocker. Please disable it so we can keep the site running.",
  btn1Title: "How to disable adblocker",
  btn2Title: "I have disabled my adblocker",
  goBackButtonTitle: "Go Back",
  howToImageURL:
    "https://github.com/faraasat/react-adblocker-detect/blob/main/images/demo.gif",
  howToSteps: [
    {
      title: "Step 1: Click on the Extensions Icon",
      description:
        "At the top-right of your browser, click the puzzle piece icon to see all extensions.",
    },
    {
      title: "Step 2: Open AdBlock Settings",
      description:
        "Click the AdBlock or AdBlock Plus icon from the list. Then click the settings gear or options.",
    },
    {
      title: "Step 3: Pause or Whitelist",
      description: `Choose "Pause on this site" or "Don't run on this site" depending on your extension.`,
    },
    {
      title: "Step 4: Refresh the Page",
      description:
        "Reload the page to check if the content is now visible. Enjoy the experience!",
    },
  ],
  pollingTime: undefined, // in milliseconds
  initialInterval: 200, // delay before showing the modal initially
  persistSetting: true, // store detection state in localStorage
};

🪝 Hook

useAdblock(shouldDetect: boolean): boolean

A custom React hook that returns true if adblocker is detected. Used internally by AdblockDetector, but can be used separately if you need raw detection logic.


💡 Modal Behavior

  • Closeable: If persistent: false, the modal can be closed after user claims they disabled adblock.
  • Persistent: If persistent: true, the modal keeps rechecking adblock status at intervals using pollingTime.

🗃 Local Storage

This library stores a flag (rad_adblocker) in localStorage to avoid showing the modal again unnecessarily when not in persistent mode.


🧑‍🎓 Credits

Developed with ❤️ by Farasat Ali Feedback and contributions welcome!