(function () { /* if (typeof (window.QW_AB_VERSION) === 'undefined') { window.QW_AB_VERSION = 'site2021'; }*/ // The websites that need these parameters to be injected. var targetWebsites = [ 'social.quizwitz.com', 'app.quizwitz.com', 'accounts.catlab.eu' ]; function isTargetWebsite(href) { for (var i = 0; i < targetWebsites.length; i ++) { if (("" + href).indexOf(targetWebsites[i]) > -1) { return true; } } return false; } function getRefQueryParam(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 setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; } function isBot() { var botPattern = "(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)"; var re = new RegExp(botPattern, 'i'); var userAgent = navigator.userAgent; if (re.test(userAgent)) { return true; } return false; } var utmParamQueryString = ''; function initialize() { if (isBot()) { return; } var parametersToMonitor = ["utm_abversion","utm_referrer","utm_source","utm_medium","utm_campaign","utm_term","utm_content","_ga","_gac","pk_vid","_gl","_cc"]; if (window.QW_AB_VERSION) { utmParamQueryString = '&utm_abversion=' + window.QW_AB_VERSION; } var value; for (var i = 0; i < parametersToMonitor.length; i ++) { value = getRefQueryParam(parametersToMonitor[i]) if (value) { setCookie(parametersToMonitor[i], value, 1); } else { value = getCookie(parametersToMonitor[i]) } if (value) { utmParamQueryString += '&' + parametersToMonitor[i] + '=' + encodeURIComponent(value); } } if (utmParamQueryString.length > 0) { utmParamQueryString = utmParamQueryString.substring(1); } injectUtmParamsInLinks(); } function injectUtmParamsInLinks() { if (!utmParamQueryString) return; var navLinks = document.querySelectorAll('a'); navLinks.forEach(function (item) { if (!isTargetWebsite(item.href)) { return; } if (item.dataset.utmFixed) { return; } item.dataset.utmFixed = true; //if (item.href.indexOf('/') === 0 || item.href.indexOf(location.host) !== -1) { if (item.href.indexOf('?') === -1) { item.href += '?'; } else { item.href += '&'; } item.href += utmParamQueryString; //} }); } function docReady(fn) { // see if DOM is already available if (document.readyState === "complete" || document.readyState === "interactive") { // call on next available tick setTimeout(fn, 1); } else { document.addEventListener("DOMContentLoaded", fn); } } docReady(initialize); // Append to global 'on document change' callstack if (typeof(window._onDocumentChangeListeners) === 'undefined') { window._onDocumentChangeListeners = []; } window._onDocumentChangeListeners.push(injectUtmParamsInLinks); /* setInterval(function() { injectUtmParamsInLinks(); }, 1000);*/ })();