Skip to content

Instantly share code, notes, and snippets.

@asprouse
Created July 29, 2015 16:51
Show Gist options
  • Save asprouse/0761766a769be2c34f54 to your computer and use it in GitHub Desktop.
Save asprouse/0761766a769be2c34f54 to your computer and use it in GitHub Desktop.
FairTread AdBlock Analytics
<script>
!function(a,b,c,d){var e=a[a.GoogleAnalyticsObject],f=!!e;f||(!function(c,d,e,f,g){a.GoogleAnalyticsObject=e,a[e]=a[e]||function(){(a[e].q=a[e].q||[]).push(arguments)},a[e].l=1*new Date,f=b.createElement(c),g=b.getElementsByTagName(c)[0],f.async=1,f.src=d,g.parentNode.insertBefore(f,g)}("script","//www.google-analytics.com/analytics.js","ga"),e=a[a.GoogleAnalyticsObject]),e("create","UA-46472229-3","auto",{name:"fairTread"}),e("fairTread.send","pageview");var g=function(b){this._options={checkOnLoad:!1,resetOnEnd:!1,loopCheckTime:50,loopMaxNumber:5,baitClass:"pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links",baitStyle:"width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;"},this._var={version:"3.1.1",bait:null,checking:!1,loop:null,loopNumber:0,event:{detected:[],notDetected:[]}},void 0!==b&&this.setOption(b);var c=this,d=function(){setTimeout(function(){c._options.checkOnLoad===!0&&(null===c._var.bait&&c._creatBait(),setTimeout(function(){c.check()},1))},1)};void 0!==a.addEventListener?a.addEventListener("load",d,!1):a.attachEvent("onload",d)};g.prototype._options=null,g.prototype._var=null,g.prototype._bait=null,g.prototype.setOption=function(a,b){if(void 0!==b){var c=a;a={},a[c]=b}for(var d in a)this._options[d]=a[d];return this},g.prototype._creatBait=function(){var c=b.createElement("div");c.setAttribute("class",this._options.baitClass),c.setAttribute("style",this._options.baitStyle),this._var.bait=a.document.body.appendChild(c)},g.prototype._destroyBait=function(){a.document.body.removeChild(this._var.bait),this._var.bait=null},g.prototype.check=function(a){if(void 0===a&&(a=!0),this._var.checking===!0)return!1;this._var.checking=!0,null===this._var.bait&&this._creatBait();var b=this;return this._var.loopNumber=0,a===!0&&(this._var.loop=setInterval(function(){b._checkBait(a)},this._options.loopCheckTime)),this._checkBait(a),!0},g.prototype._checkBait=function(b){var c=!1;if(null===this._var.bait&&this._creatBait(),(null!==a.document.body.getAttribute("abp")||null===this._var.bait.offsetParent||0==this._var.bait.offsetHeight||0==this._var.bait.offsetLeft||0==this._var.bait.offsetTop||0==this._var.bait.offsetWidth||0==this._var.bait.clientHeight||0==this._var.bait.clientWidth)&&(c=!0),void 0!==a.getComputedStyle){var d=a.getComputedStyle(this._var.bait,null);("none"==d.getPropertyValue("display")||"hidden"==d.getPropertyValue("visibility"))&&(c=!0)}b===!0&&(this._var.loopNumber++,this._var.loopNumber>=this._options.loopMaxNumber&&(clearInterval(this._var.loop),this._var.loop=null,this._var.loopNumber=0)),c===!0?(b===!0&&(this._var.checking=!1),this._destroyBait(),this.emitEvent(!0)):(null===this._var.loop||b===!1)&&(b===!0&&(this._var.checking=!1),this._destroyBait(),this.emitEvent(!1))},g.prototype.emitEvent=function(a){var b=this._var.event[a===!0?"detected":"notDetected"];for(var c in b)b.hasOwnProperty(c)&&b[c]();return this._options.resetOnEnd===!0&&this.clearEvent(),this},g.prototype.clearEvent=function(){this._var.event.detected=[],this._var.event.notDetected=[]},g.prototype.on=function(a,b){return this._var.event[a===!0?"detected":"notDetected"].push(b),this},g.prototype.onDetected=function(a){return this.on(!0,a)},g.prototype.onNotDetected=function(a){return this.on(!1,a)};var h=new g({checkOnLoad:!1,resetOnEnd:!0});h.onDetected(function(){var b=a._gaq;b&&b.push&&b.push(["_trackEvent",c,d]),f&&e("send","event",c,d),e("fairTread.send","event",c,d)}),h.check()}(window,document,"adBlock","detected");
</script>
@mankins
Copy link

mankins commented Aug 3, 2015

Add that right before the closing body tag. [email protected] for support.

It will find your Google Analytics and then add a Google Analytics events for "adblock, detected" when adblock is detected. Just compare this with your page views.

@michaelBenin
Copy link

Nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment