Last active
March 31, 2016 22:21
-
-
Save athlan/34564c8a676f7f1c2aca15b60383f390 to your computer and use it in GitHub Desktop.
Measure check Adblock disabled and push into Google Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- adblock checker --> | |
<div id="ablck_checker" class="ads ad adsbox doubleclick ad-placement carbon-ads"></div> | |
<script type="text/javascript"> | |
(function() { | |
var checkAdblockPresence = function(elementId) { | |
return (getComputedStyle(document.getElementById(elementId))["display"] == "none") ? true : false; | |
}; | |
var checkAdblockEvent = function() { | |
// check if adblock is enabled | |
var isAdBlocked = checkAdblockPresence('ablck_checker'); | |
// track event to Google Analytics | |
var category = 'user-env'; | |
var action = 'adblock'; | |
var label = (isAdBlocked) ? 'on' : 'off'; | |
// EDIT your tracker name or just 'send' | |
ga('mainTracker.send', 'event', category, action, label); | |
}; | |
setTimeout(checkAdblockEvent, 1000); // wait some time | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment