Guest User

Untitled

a guest
Feb 19th, 2016
1,600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _satellite.pushAsyncScript(function (event, target, $variables) {
  2.   (function (window) {
  3.     if (window.sniffAdBlock !== undefined) {
  4.       return;
  5.     }
  6.  
  7.     var SniffAdBlock = function (options) {
  8.       if (options !== undefined) {
  9.         this.setOption(options);
  10.       }
  11.  
  12.       var self = this;
  13.       var eventCallback = function () {
  14.         setTimeout(function () {
  15.           if (self._options.checkOnLoad === true) {
  16.             if (self._var.bait === null) {
  17.               self._creatBait();
  18.             }
  19.             setTimeout(function () {
  20.               self.check();
  21.             }, 1);
  22.           }
  23.         }, 1);
  24.       };
  25.       if (window.addEventListener) {
  26.         window.addEventListener('load', eventCallback, false);
  27.       } else {
  28.         window.attachEvent('onload', eventCallback);
  29.       }
  30.     };
  31.     SniffAdBlock.prototype._options = {
  32.       checkOnLoad : true,
  33.       resetOnEnd : true,
  34.       loopCheckTime : 50,
  35.       loopMaxNumber : 5,
  36.       baitClass : 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links',
  37.       baitStyle : 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;'
  38.     };
  39.     SniffAdBlock.prototype._var = {
  40.       version : '3.0.1',
  41.       bait : null,
  42.       checking : false,
  43.       loop : null,
  44.       loopNumber : 0,
  45.       event : {
  46.         detected : [],
  47.         notDetected : []
  48.       }
  49.     };
  50.     SniffAdBlock.prototype._bait = null;
  51.  
  52.     SniffAdBlock.prototype.setOption = function (options, value) {
  53.       if (value !== undefined) {
  54.         var key = options;
  55.         options = {};
  56.         options[key] = value;
  57.       }
  58.       for (option in options) {
  59.         this._options[option] = options[option];
  60.       }
  61.       return this;
  62.     };
  63.  
  64.     SniffAdBlock.prototype._creatBait = function () {
  65.       var bait = document.createElement('div');
  66.       bait.setAttribute('class', this._options.baitClass);
  67.       bait.setAttribute('style', this._options.baitStyle);
  68.       this._var.bait = window.document.body.appendChild(bait);
  69.  
  70.       this._var.bait.offsetParent;
  71.       this._var.bait.offsetHeight;
  72.       this._var.bait.offsetLeft;
  73.       this._var.bait.offsetTop;
  74.       this._var.bait.offsetWidth;
  75.       this._var.bait.clientHeight;
  76.       this._var.bait.clientWidth;
  77.     };
  78.     SniffAdBlock.prototype._destroyBait = function () {
  79.       window.document.body.removeChild(this._var.bait);
  80.       this._var.bait = null;
  81.     };
  82.  
  83.     SniffAdBlock.prototype.check = function (loop) {
  84.       if (loop === undefined) {
  85.         loop = true;
  86.       }
  87.  
  88.       if (this._var.checking === true) {
  89.         return false;
  90.       }
  91.       this._var.checking = true;
  92.  
  93.       if (this._var.bait === null) {
  94.         this._creatBait();
  95.       }
  96.  
  97.       var self = this;
  98.       this._var.loopNumber = 0;
  99.       if (loop === true) {
  100.         this._var.loop = setInterval(function () {
  101.             self._checkBait(loop);
  102.           }, this._options.loopCheckTime);
  103.       }
  104.       this._checkBait(loop);
  105.  
  106.       return true;
  107.     };
  108.     SniffAdBlock.prototype._checkBait = function (loop) {
  109.       var detected = false;
  110.  
  111.       if (this._var.bait === null) {
  112.         this._creatBait();
  113.       }
  114.  
  115.       if (window.document.body.getAttribute('abp') !== null || this._var.bait.offsetParent === null || 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 == 0) {
  116.         detected = true;
  117.       }
  118.       if (window.getComputedStyle !== undefined) {
  119.         var baitTemp = window.getComputedStyle(this._var.bait, null);
  120.         if (baitTemp.getPropertyValue('display') == 'none' || baitTemp.getPropertyValue('visibility') == 'hidden') {
  121.           detected = true;
  122.         }
  123.       }
  124.  
  125.       if (loop === true) {
  126.         this._var.loopNumber++;
  127.         if (this._var.loopNumber >= this._options.loopMaxNumber) {
  128.           clearInterval(this._var.loop);
  129.           this._var.loop = null;
  130.           this._var.loopNumber = 0;
  131.         }
  132.       }
  133.  
  134.       if (detected === true) {
  135.         if (loop === true) {
  136.           this._var.checking = false;
  137.         }
  138.         this._destroyBait();
  139.         this.emitEvent(true);
  140.       } else if (this._var.loop === null || loop === false) {
  141.         if (loop === true) {
  142.           this._var.checking = false;
  143.         }
  144.         this._destroyBait();
  145.         this.emitEvent(false);
  146.       }
  147.     };
  148.  
  149.     SniffAdBlock.prototype.emitEvent = function (detected) {
  150.       var fns = this._var.event[(detected === true ? 'detected' : 'notDetected')];
  151.       for (i in fns) {
  152.         fns[i]();
  153.       }
  154.       if (this._options.resetOnEnd === true) {
  155.         this.clearEvent();
  156.       }
  157.       return this;
  158.     };
  159.     SniffAdBlock.prototype.clearEvent = function () {
  160.       this._var.event.detected = [];
  161.       this._var.event.notDetected = [];
  162.     };
  163.  
  164.     SniffAdBlock.prototype.on = function (detected, fn) {
  165.       this._var.event[(detected === true ? 'detected' : 'notDetected')].push(fn);
  166.       return this;
  167.     };
  168.     SniffAdBlock.prototype.onDetected = function (fn) {
  169.       return this.on(true, fn);
  170.     };
  171.     SniffAdBlock.prototype.onNotDetected = function (fn) {
  172.       return this.on(false, fn);
  173.     };
  174.  
  175.     window.sniffAdBlock = new SniffAdBlock();
  176.  
  177.     // Cookie setter and getter functions
  178.     // We only want to count daily unique ad blocks
  179.     // Taken from www.w3schools.com/js/js_cookies.asp
  180.     function setCookie(cname, cvalue, exdays) {
  181.       var d = new Date();
  182.       d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  183.       var expires = "expires=" + d.toUTCString();
  184.       document.cookie = cname + "=" + cvalue + "; " + expires;
  185.     }
  186.  
  187.     function getCookie(cname) {
  188.       var name = cname + "=";
  189.       var ca = document.cookie.split(';');
  190.       for (var i = 0; i < ca.length; i++) {
  191.         var c = ca[i];
  192.         while (c.charAt(0) == ' ')
  193.           c = c.substring(1);
  194.         if (c.indexOf(name) == 0)
  195.           return c.substring(name.length, c.length);
  196.       }
  197.       return "";
  198.     }
  199.  
  200.     // Setup the tracking function to submit a GET request (i.e. fire the image pixel)
  201.     // Taken from cn.dart.js (author: Rob Sethi), with some modifications
  202.     function trackETF(blocked, new_visit) {
  203.  
  204.       if (blocked) {
  205.         if (new_visit) {
  206.           _blocked = 'blocked';
  207.         } else {
  208.           _blocked = 'blocked_pageview';
  209.         }
  210.       } else {
  211.         if (new_visit) {
  212.           _blocked = 'not_blocked';
  213.         } else {
  214.           _blocked = 'not_blocked_pageview';
  215.         }
  216.       }
  217.  
  218.       if (/iPhone|iPad/i.test(navigator.userAgent)) {
  219.         _blocked = _blocked + '/iOS'
  220.       }
  221.  
  222.       var track,
  223.       buildParams;
  224.  
  225.       // Fire the event with the event params
  226.       track = function () {
  227.         jQuery.ajax({
  228.           type : "GET",
  229.           url : '//event.condenastdigital.com/images/event.gif?' + buildParams(),
  230.           cache : false
  231.         });
  232.       };
  233.  
  234.       // Function to build the parameters of the gif URL
  235.       buildParams = function () {
  236.         var params,
  237.         markers;
  238.  
  239.         params = {
  240.           "e0_id" : document.location.host + '/' + _blocked,
  241.           "e0_ec" : "adblock",
  242.           "e0_env" : "dart",
  243.           "e0_sc" : document.location.host.split('.')[1].substring(0, 3),
  244.           "e0_tit" : browserCheck(),
  245.           "e0_url" : document.location.href
  246.         };
  247.  
  248.         function browserCheck() {
  249.           var N = navigator.appName,
  250.           ua = navigator.userAgent,
  251.           tem;
  252.           var M = ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i);
  253.  
  254.           if (M && (tem = ua.match(/version\/([\.\d]+)/i)) != null) {
  255.             M[2] = tem[1];
  256.           }
  257.           M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?'];
  258.           return M.toString()
  259.         };
  260.  
  261.         return jQuery.param(params);
  262.       };
  263.  
  264.       //console.log(buildParams);
  265.  
  266.       track();
  267.  
  268.     };
  269.  
  270.     var new_visit;
  271.     // Set a BlockerSniffer cookie to ensure that we only count 1 detection event per user per day
  272.     if (getCookie("BlockerSniffer_" + document.location.host.split('.')[1]) != 1) {
  273.       setCookie("BlockerSniffer_" + document.location.host.split('.')[1], 1, 1);
  274.       new_visit = true;
  275.     } else {
  276.       new_visit = false;
  277.     }
  278.  
  279.     // Apply SniffAdBlocker (must include SniffAdBlocker.js (https://github.com/veeracs/SniffAdBlock)
  280.     // Adapted from http://wiki.conde-dev.com/pages/viewpage.action?pageId=20188075
  281.     if (!sniffAdBlock) { //  if the sniffer is blocked by AdBlock
  282.       console.log('Adblocker detected');
  283.       setCookie("AdHt", 1, 365);
  284.       if (typeof _satellite != "undefined") {
  285.         _satellite.track('adBlock');
  286.       }
  287.       if (new_visit) {
  288.         trackETF(true, true);
  289.         trackETF(true, false);
  290.       } else {
  291.         trackETF(true, false);
  292.       }
  293.     } else {
  294.       console.log('checking for ad blockers...');
  295.       sniffAdBlock.onDetected(function () {
  296.         console.log('Adblocker detected');
  297.         setCookie("AdHt", 1, 365);
  298.         if (typeof _satellite != "undefined") {
  299.           _satellite.track('adBlock');
  300.         }
  301.         if (new_visit) {
  302.           console.log('new visit');
  303.           trackETF(true, true);
  304.           trackETF(true, false);
  305.         } else {
  306.           trackETF(true, false);
  307.         }
  308.       });
  309.       sniffAdBlock.onNotDetected(function () {
  310.         console.log("Adblocker not detected");
  311.         if (getCookie("AdCv") == "" && getCookie("AdHt") == 1) {
  312.           window.optimizely = window.optimizely || [];
  313.           window.optimizely.push(["trackEvent", "blockerConversion"]);
  314.           setCookie("AdCv", 1, 365);
  315.         }
  316.         if (new_visit) {
  317.           trackETF(false, true);
  318.           trackETF(false, false);
  319.         } else {
  320.           trackETF(false, false);
  321.         }
  322.       });
  323.     }
  324.  
  325.     //  Optionally, invoke a manual check if the onDetected callback never fires
  326.     setTimeout(function () {
  327.       sniffAdBlock.check();
  328.     }, 10);
  329.  
  330.   })(window);
  331. });
Advertisement
Add Comment
Please, Sign In to add comment