adblock-detect-react
Version:
Provides utilities to check if ad block is enabled on a page via both a React hook and a wrapper component.
21 lines • 631 B
JavaScript
import { useEffect, useState } from "react";
export const useDetectAdBlock = () => {
const [adBlockDetected, setAdBlockDetected] = useState(false);
useEffect(() => {
const url = "https://www3.doubleclick.net";
fetch(url, {
method: "HEAD",
mode: "no-cors",
cache: "no-store",
})
.then(({ redirected }) => {
if (redirected)
setAdBlockDetected(true);
})
.catch(() => {
setAdBlockDetected(true);
});
}, []);
return adBlockDetected;
};
//# sourceMappingURL=useDetectAdBlock.js.map