Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var AdBlockUtil = (function()
- {
- var adBlockEnabled = false;
- function checkRedirect()
- {
- if(document.location.href.indexOf("haaretz.co.il") < 0) // avoid redirect in preview pages: check that we're in "haaretz.co.il" domain
- {
- return;
- }
- $.ajax({
- url: 'https://tpc.googlesyndication.com/simgad/1909367504824409356',
- type: "GET",
- error: function(jqXHR, textStatus, errorThrown) {
- adBlockEnabled = true;
- //console.log("adBlock Enabled");
- checkRedirectAfterAdBlockDetection();
- },
- success: function(data, textStatus, jqXHR) {
- adBlockEnabled = false;
- //console.log("adBlock Disabled");
- checkRedirectAfterAdBlockDetection();
- }
- });
- }
- var redirectProbabilityPercent = redirectProbabilityPercentTest;
- var url = encodeURIComponent(document.location.href);
- if(url.indexOf("www.haaretz.co.il") >= 0)
- {
- redirectProbabilityPercent = redirectProbabilityPercentProd;
- }
- function getParameterByName(name)
- {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
- var results = regex.exec(location.search);
- return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
- }
- function getUserType()
- {
- CookieUtil.reinit();
- var cookieMap = CookieUtil.getCookieMap();
- var isTMuser = cookieMap['tmsso'] ? 'registered' : 'anonymous';
- return cookieMap['HtzPusr'] ? 'paying' : isTMuser;
- }
- function isOnBlockedPage()
- {
- return document.location.href.indexOf('/hblocked') > 0 || document.location.href.indexOf('/vblocked') > 0;
- }
- function isAllowedPage() // pages allows for adBlock -> do not redirect from these pages. homepage, blocked page, promotions page, login page
- {
- return (typeof isInHomePage !== 'undefined' && isInHomePage) || isOnBlockedPage() || document.location.href.indexOf("/promotions") > 0 || document.location.href.indexOf("/login-page") > 0;
- }
- function goBack()
- {
- // redirect back to original page or homepage
- var returnTo = getParameterByName("returnTo");
- if(returnTo == "")
- {
- document.location.href = "/";
- }
- else
- {
- document.location.href = returnTo;
- }
- }
- function doAction(action, onSuccess)
- {
- var url = encodeURIComponent(document.location.href);
- var HtzRusr = "Rusr=";
- if(typeof CookieUtil.getCookie('HtzRusr') !== "undefined")
- {
- HtzRusr = HtzRusr + CookieUtil.getCookie('HtzRusr')
- }
- var HtzPusr = "Pusr=";
- if(typeof CookieUtil.getCookie('HtzPusr') !== "undefined")
- {
- HtzPusr = HtzPusr + CookieUtil.getCookie('HtzPusr')
- }
- var sendTo = 'http://ds.haaretz.co.il/dstest.php?';
- if(url.indexOf("www.haaretz.co.il") >= 0)
- {
- sendTo = 'http://ds.haaretz.co.il/ds.php?';
- }
- var domain = "domain=" + window.location.hostname;
- var urlS = "url=" + url;
- var userId = "userId="
- if(typeof CookieUtil.getCookie("tmsso") !== "undefined")
- {
- userId = userId + CookieUtil.getCookie("tmsso").userId;
- }
- else if(typeof CookieUtil.getCookie("anonymousId") !== "undefined")
- {
- userId = userId + CookieUtil.getCookie("anonymousId");
- }
- else
- {
- return;
- }
- data = urlS + "&" + domain + "&" + HtzRusr + "&" + HtzPusr + "&" + userId + "&actionType=" + action;
- jQuery.ajax({
- url: sendTo + data,
- dataType: 'text',
- type : "GET",
- success : onSuccess
- });
- }
- function checkRedirectAfterAdBlockDetection()
- {
- if(typeof CookieUtil.getCookie("skipAdblockRedirect") !== 'undefined')
- {
- return;
- }
- if(isOnBlockedPage()) // set link actions on blocked pages
- {
- // set abandon logic, in case user leaves the page
- $(window).on('beforeunload', function() {
- doAction(18, null); // report: abandon
- return undefined;
- });
- // set other click action which will send a report and also cancel the abandon logic, e.g. if user clicks the login button, it will not be considered an abandonment
- $("#go_to_purchase").click(function() {
- doAction(17, function(){$(window).off('beforeunload'); document.location.href = "https://www.haaretz.co.il/promotions-page";}); // report: go to purchase
- });
- var returnTo = getParameterByName("returnTo");
- if(returnTo != "")
- {
- $("#adblock_returnto").click(function() {
- $(window).off('beforeunload');
- document.location.href = returnTo;
- });
- $("#go_to_login").click(function() {
- doAction(16, function(){$(window).off('beforeunload'); document.location.href = "/misc/login-page?returnTo=" + encodeURIComponent(returnTo);}); // report: go to login
- });
- $(".js-login").attr("href","#");
- $(".js-login").click(function() {
- doAction(16, function(){$(window).off('beforeunload'); document.location.href = "/misc/login-page?returnTo=" + encodeURIComponent(returnTo);}); // report: go to login
- });
- }
- else
- {
- $("#adblock_returnto").click(function() {
- $(window).off('beforeunload');
- document.location.href = "";
- });
- $("#go_to_login").click(function() {
- doAction(16, function(){$(window).off('beforeunload'); document.location.href = "/misc/login-page";}); // report: go to login
- });
- $(".js-login").attr("href","#");
- $(".js-login").click(function() {
- doAction(16, function(){$(window).off('beforeunload'); document.location.href = "/misc/login-page";}); // report: go to login
- });
- }
- }
- if(!adBlockEnabled) // adBlock disabled
- {
- if(typeof CookieUtil.getCookie("adblockRedirect") !== 'undefined' && !isOnBlockedPage())
- {
- CookieUtil.deleteCookie("adblockRedirect", '/', 'haaretz.co.il'); // delete cookie
- localStorage.adblock_removed = true;
- doAction(15, function()
- {
- if(isOnBlockedPage())
- {
- $(window).off('beforeunload');
- }
- }); // report: user disabled adBlock for www.haaretz.co.il
- }
- }
- else // adBlock enabled
- {
- localStorage.adblock_removed = false;
- if(getUserType() == "paying") // paying user
- {
- if(isOnBlockedPage())
- {
- goBack();
- }
- else
- {
- return;
- }
- }
- else if(isAllowedPage()) // if user is on a page defined not to be redirected -> return (do nothing)
- {
- return;
- }
- else if(getUserType() != "paying") // apply redirect logic for anonymous or registered users only
- {
- if(typeof CookieUtil.getCookie("adblockRedirect") !== 'undefined') // if user already has a blocked page cookie, redirect.
- {
- document.location.href = "/" + CookieUtil.getCookie("adblockRedirect") + "?returnTo=" + encodeURIComponent(document.location.href);
- return;
- }
- else // user does not have a blocked page cookie -> calculate probability for redirect
- {
- var rand = Math.random();
- if(rand < redirectProbabilityPercent / 100) // we have a winner! redirect and set cookie for next visits -> user will be redirected for 90 days
- {
- var expireMs = Date.now() + ( 90*24*3600*1000); // 90 days
- var expire = new Date(expireMs);
- if(Math.random() < 0.5) // A/B testing
- {
- CookieUtil.setCookie('adblockRedirect', 'hblocked', '/', 'haaretz.co.il', expire);
- document.location.href = "/hblocked?returnTo=" + encodeURIComponent(document.location.href);
- }
- else
- {
- CookieUtil.setCookie('adblockRedirect', 'vblocked', '/', 'haaretz.co.il', expire);
- document.location.href = "/vblocked?returnTo=" + encodeURIComponent(document.location.href);
- }
- }
- else // set cookie for next visits, user will not be redirected for at least 3 more days
- {
- var expireMs = Date.now() + (3*24*3600*1000); // 3 days
- var expire = new Date(expireMs);
- CookieUtil.setCookie('skipAdblockRedirect', 'true', '/', 'haaretz.co.il', expire);
- }
- }
- }
- }
- }
- return{
- "checkRedirect":function(){
- checkRedirect();
- },
- "isOnBlockedPage":function(){
- return isOnBlockedPage();
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment