QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Bitcoin BankingBuy, Sell, Store and Earn Interest
  • Home
  • QIdea
  • QTrack
Home Carbon Ads Track Adblock Users with Google Analytics

Track Adblock Users with Google Analytics

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>
Feb 18, 2015Narayan Prusty
JavaScript "yield" Keyword and "function*()" SyntaxPassphrase Based Encryption using Web Cryptography API

Leave a Reply Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

Narayan Prusty

I am a full-stack web developer. I specialize in Blockchain and JavaScript. This is my personal blog where I write about programming and technologies that I learn and feel interesting to share.

6 years ago Tips and Tricks
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • Integrate Google Analytics in Intel XDK APP
  • Spypig Alternative
  • How to check if someone copied my website
  • How to Track if E-Mail has been opened
  • Database Design for Analytics
Our Sponsor
Freelance: I am available
@narayanprusty
Hi, I am a full-stack developer - focusing on JavaScript, WordPress, Blockchain, DevOps, Serverless and Cordova. You can outsource your app development to me.





Will get back to you soon!!!
WordPress
ReactJS
Meteor
Blockchain
Serverless
Kubernetes
DevOps
DB & Storage
Ejabberd
Let's get started
My Books

2014 - 2015 © QNimate
All tutorials MIT license