If you want to know how many of your users are blocking ads of your website then paste this code in your website. This code sends the tracked data to your Google Analytics account.
To run the below code you need to make sure that the webpage has Google Analytics tracking code embedded.
<script>
window.addEventListener("load", function(){
var iframe = document.createElement("iframe");
iframe.height = "1px";
iframe.width = "1px";
iframe.id = "ads-text-iframe";
iframe.src = "http://example.com/ads.html";
document.body.appendChild(iframe);
setTimeout(function(){
var iframe = document.getElementById("ads-text-iframe");
if(iframe.style.display == "none" || iframe.style.display == "hidden" || iframe.style.visibility == "hidden" || iframe.offsetHeight == 0)
{
iframe.remove();
if(typeof ga !== 'undefined')
{
ga('send', 'event', 'Adblock', 'Yes', {'nonInteraction': 1});
}
else if(typeof _gaq !== 'undefined')
{
_gaq.push(['_trackEvent', 'Adblock', 'Yes', undefined, undefined, true]);
}
}
}, 1000);
}, false);
</script>
window.addEventListener("load", function(){
var iframe = document.createElement("iframe");
iframe.height = "1px";
iframe.width = "1px";
iframe.id = "ads-text-iframe";
iframe.src = "http://example.com/ads.html";
document.body.appendChild(iframe);
setTimeout(function(){
var iframe = document.getElementById("ads-text-iframe");
if(iframe.style.display == "none" || iframe.style.display == "hidden" || iframe.style.visibility == "hidden" || iframe.offsetHeight == 0)
{
iframe.remove();
if(typeof ga !== 'undefined')
{
ga('send', 'event', 'Adblock', 'Yes', {'nonInteraction': 1});
}
else if(typeof _gaq !== 'undefined')
{
_gaq.push(['_trackEvent', 'Adblock', 'Yes', undefined, undefined, true]);
}
}
}, 1000);
}, false);
</script>
Leave a Reply