@hs-web-team/adblocker-detect
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

AdBlocker Detect Script

Index

Development

If you need to build the code for this package, you just need to either run the npm run build command, or if you want to build it in watch mode, just run npm run dev.

How to use it

First thing is to install the package, as a dependency of your project.

npm install --save @hs-web-team/adblocker-detect

Once installed you need to simply import the checkAdblock function in your module. Here an example:

import { checkAdblock } from '@hs-web-team/adblocker-detect';

/**
 * Checks the various strategies to detect an AdBlocker
 */
const hasAdBlockerWrapper = async () => {
  const adblocker = await checkAdblock();
  if (adblocker) {
    const adblockerElement = document.createElement('div');
    adblockerElement.id = 'adblocker-detected';
    adblockerElement.innerHTML = `
      <div class="adblocker-detected">
        <h2>Adblocker detected</h2>
        <p>
          Your browser is blocking ads.
        </p>
      </div>
    `;
    document.body.appendChild(adblockerElement);
  }
};

hasAdBlockerWrapper();

And that's it, you are good to go!

A global variable

Once called for the first time, a global variable is created, which is used to store the state of the results of the checks. You can invoke the state by calling window.hs_hasAdBlocker.

Readme

Keywords

Package Sidebar

Install

npm i @hs-web-team/adblocker-detect

Weekly Downloads

12

Version

2.0.0

License

ISC

Unpacked Size

4.54 kB

Total Files

5

Last publish

Collaborators

  • cfritz
  • ahiremath
  • conormalone
  • nmansurov
  • bcarolan
  • cwunder_hubspot
  • dgroechel_hs
  • sasharma
  • gsugrue_npm
  • annagallo-hs
  • rraj_hubspot
  • mbegyn
  • hzahra
  • mlamacchia
  • ralo_alo
  • yjgcharriz
  • damartinez
  • mvalenciahubspot
  • leocifnpm
  • cumana
  • mahad2
  • siva_h
  • kelvinmr
  • iogrizovic
  • pstafford
  • conor_heffernan
  • sduque
  • sdiaz88
  • andresllinasr
  • ronaldtorresn
  • hayala
  • snigam
  • adiazcometa
  • bjacobel
  • henryqdineen
  • troche_hub
  • stevehealy
  • cprince
  • ruthfarrell
  • kimccarthy
  • bpuseyhs
  • vickytran
  • ccameron
  • sgoldenson
  • markelly-hs
  • leahshearer
  • mndhlovu
  • denishubspot
  • mhewitt
  • epayret
  • dmooney
  • kebrahim
  • lopchannorie
  • pwilver
  • tswyter
  • dding
  • tstelmach
  • hs_cfrisoli
  • priedle
  • amichelini
  • lbergin
  • nhodgkiss447
  • dharmeshs
  • lhampson
  • cutlah
  • gwilliamshubspot
  • kelin599
  • dalcantara_hs
  • aulfich-hs
  • samson.yuwono