From fbdf45f1fae71b7c140cf722ede84a5ae0c25910 Mon Sep 17 00:00:00 2001 From: Pankaj Date: Sat, 16 May 2026 12:52:29 +0530 Subject: [PATCH] Add GA4 integration example and GTM guidance --- README.md | 31 +++++++++++++++++++++++++++++++ adblockDetectorWithGA4.js | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 adblockDetectorWithGA4.js diff --git a/README.md b/README.md index b47c547..73a1f72 100644 --- a/README.md +++ b/README.md @@ -132,3 +132,34 @@ Submit a pull request - The script will not work locally. The page should get served from the server via http - Currently the “baits” or “honey pods” used in the Javascript are hardcoded @ #218. If you want to update the file with new baits update the line #218 - Use the sample file test.html find in the repository. Host the file on HTTP server eg. apache server and request the file in browser via http with adblocker on/off. + + +## GA4 Integration Example + +Since Universal Analytics has been sunset by Google, modern implementations can use GA4 event tracking. + +Example: + +```javascript +window.adblockDetector.init({ + found: function () { + if (typeof gtag === 'function') { + gtag('event', 'adblock_detected', { + adblock_status: 'detected' + }); + } + }, + + notFound: function () { + if (typeof gtag === 'function') { + gtag('event', 'adblock_not_detected', { + adblock_status: 'not_detected' + }); + } + } +}); +``` + +## Google Tag Manager (GTM) + +This library can also be integrated with Google Tag Manager using `dataLayer.push()` events. \ No newline at end of file diff --git a/adblockDetectorWithGA4.js b/adblockDetectorWithGA4.js new file mode 100644 index 0000000..1cfb0ee --- /dev/null +++ b/adblockDetectorWithGA4.js @@ -0,0 +1,17 @@ +window.adblockDetector.init({ + found: function () { + if (typeof gtag === 'function') { + gtag('event', 'adblock_detected', { + adblock_status: 'detected' + }); + } + }, + + notFound: function () { + if (typeof gtag === 'function') { + gtag('event', 'adblock_not_detected', { + adblock_status: 'not_detected' + }); + } + } +}); \ No newline at end of file