Repository navigation
Expand file tree
/
Copy pathtracking.js
More file actions
7 lines (6 loc) · 12.3 KB
/
Copy pathtracking.js
File metadata and controls
7 lines (6 loc) · 12.3 KB
1
2
3
4
5
6
7
(function(){"use strict";function e(e){for(var o=1;o<arguments.length;o++){var t=arguments[o];for(var r in t)e[r]=t[r]}return e}var o=function o(t,r){function n(o,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),o=encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in i)i[c]&&(a+="; "+c,!0!==i[c]&&(a+="="+i[c].split(";")[0]));return document.cookie=o+"="+t.write(n,o)+a}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var o=document.cookie?document.cookie.split("; "):[],r={},n=0;n<o.length;n++){var i=o[n].split("="),a=i.slice(1).join("=");try{var c=decodeURIComponent(i[0]);if(r[c]=t.read(a,c),e===c)break}catch(e){}}return e?r[e]:r}},remove:function(o,t){n(o,"",e({},t,{expires:-1}))},withAttributes:function(t){return o(this.converter,e({},this.attributes,t))},withConverter:function(t){return o(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),t=["gclid","utm_source","utm_medium","utm_campaign","utm_term","utm_content","gbraid","wbraid","fbclid","gad_source","gad_campaignid"],r=function(e){return e instanceof URL?e:e?new URL(e):null},n=function(e){return e instanceof URL?e.hostname:e.startsWith("http")?new URL(e).hostname:e},i=function(e,o,t){void 0===t&&(t=!1);try{var r="string"==typeof e?new URL(e).hostname:e.hostname;return o.some((function(e){return r===e||!t&&r.endsWith(".".concat(e))}))}catch(e){return!1}},a=function(e){return t.reduce((function(o,t){var r=e.get(t);return r&&(o[t]=r),o}),{})},c=function(e,o,t){try{if(!o)return e;var r="string"==typeof e?new URL(e):e;return Object.entries(o).forEach((function(e){var o=e[0],n=e[1];n?r.searchParams.set(t?"".concat(t).concat(o):o,n):r.searchParams.delete(o)})),"string"==typeof e?r.toString():e}catch(o){return e}},g=function(e){return t.reduce((function(o,t){var r=e(t);return void 0!==r&&(null!=o||(o={}),o[t]=r),o}),null)},s={"360.cn":"360.cn","alice.com":"alice","aliceadsl.fr":"alice","alltheweb.com":"alltheweb","altavista.com":"altavista","aol.com":"aol","ask.com":"ask","search.aol.fr":"aol","alicesuche.aol.de":"aol","auone.jp":"auone","avg.com":"avg","babylon.com":"babylon","baidu.com":"baidu","biglobe.ne.jp":"biglobe","bing.com":"bing","centrum.cz":"centrum.cz","comcast.net":"comcast","conduit.com":"conduit","cnn.com":"cnn","daum.net":"daum","duckduckgo.com":"duckduckgo","ecosia.org":"ecosia","ekolay.net":"ekolay","eniro.se":"eniro","globo.com":"globo","google.com":"google","google.com.ar":"google","google.com.au":"google","google.com.br":"google","google.com.co":"google","google.com.hk":"google","google.com.mx":"google","google.com.my":"google","google.com.ng":"google","google.com.pe":"google","google.com.ph":"google","google.com.pk":"google","google.com.sa":"google","google.com.sg":"google","google.com.tr":"google","google.com.tw":"google","google.com.ua":"google","google.com.vn":"google","google.de":"google","google.es":"google","google.fr":"google","google.gr":"google","google.ae":"google","google.be":"google","google.bg":"google","google.ca":"google","google.ch":"google","google.cl":"google","google.co.il":"google","google.co.in":"google","google.co.jp":"google","google.co.kr":"google","google.co.th":"google","google.co.uk":"google","google.co.za":"google","google.com.bo":"google","google.com.kh":"google","google.dk":"google","google.ee":"google","google.fi":"google","google.gg":"google","google.lt":"google","google.no":"google","google.hu":"google","google.ie":"google","google.it":"google","google.nl":"google","google.pl":"google","google.pt":"google","google.ro":"google","google.ru":"google","google.se":"google","goo.ne.jp":"goo.ne","haosou.com":"haosou.com","incredimail.com":"incredimail","kvasir.no":"kvasir","lycos.com":"lycos","search.lycos.de":"lycos","mamma.com":"mamma","msn.com":"msn","money.msn.com":"msn","local.msn.com":"msn","mynet.com":"mynet","najdi.si":"najdi","naver.com":"naver","netscape.com":"netscape","search.netscape.com":"netscape","onet.pl":"onet","szukaj.onet.pl":"onet","ozu.es":"ozu","qwant.com":"qwant","rakuten.co.jp":"rakuten","search-results.com":"search-results","search.smt.docomo.ne.jp":"search.smt.docomo","sesam.no":"sesam","seznam.cz":"seznam","so.com":"so.com","sogou.com":"sogou","startsidan.se":"startsidan","szukacz.pl":"szukacz","terra.com.br":"terra","tut.by":"tut.by","search.tut.by":"tut.by","ukr.net":"ukr","search.ukr.net":"ukr","search.virgilio.it":"virgilio","voila.fr":"voila","wp.pl":"wirtualna-polska","yahoo.com":"yahoo","yahoo.cn":"yahoo","m.yahoo.com":"yahoo","yam.com":"yam"},l={"facebook.com":"facebook","m.facebook.com":"facebook","l.facebook.com":"facebook","lm.facebook.com":"facebook","twitter.com":"twitter","linkedin.com":"linkedin","instagram.com":"instagram","m.instagram.com":"instagram","l.instagram.com":"instagram","lm.instagram.com":"instagram","youtube.com":"youtube","m.youtube.com":"youtube","reddit.com":"reddit","tumblr.com":"tumblr"},u="(none)",m="null",f={gclid:m,utm_source:u,utm_medium:u,utm_campaign:u,utm_term:u,utm_content:u,gbraid:m,wbraid:m,fbclid:m},d=function(){return d=Object.assign||function(e){for(var o,t=1,r=arguments.length;t<r;t++)for(var n in o=arguments[t])Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n]);return e},d.apply(this,arguments)},h=function(){function e(){this.ownDomains=[],this.excludedDomains=[],this.excludedDomainPrefixes=[]}return e.prototype.isOwnDomain=function(e){return i(e,this.ownDomains)},e.prototype.isExcludedDomain=function(e){return i(e,this.excludedDomains)||function(e,o){try{var t="string"==typeof e?new URL(e).hostname.toLowerCase():e.hostname.toLowerCase();return o.some((function(e){var o=e.toLowerCase().trim().replace(/\.$/,"");return!!o&&(t===o||t.startsWith("".concat(o,"."))||t.endsWith(".".concat(o))||t.includes(".".concat(o,".")))}))}catch(e){return!1}}(e,this.excludedDomainPrefixes)},e.prototype.isSameDomain=function(e){var o;return window.location.hostname===(null===(o=r(e))||void 0===o?void 0:o.hostname)},e.prototype.setCookie=function(e,t){var r=function(e){var o=n(e).replace(/^www\./,"");if(/^(?:\d{1,3}\.){3}\d{1,3}$/.test(o))return o;var t=o.split(".");if(t.length<=2)return o;var r=new Set(["ac","co","com","edu","gov","net","org"]),i=t[t.length-2],a=t[t.length-1];return r.has(i)&&2===a.length?t.slice(-3).join("."):t.slice(-2).join(".")}(window.location.hostname);o.set(e,t,{path:"/",expires:730,domain:r})},e.prototype.getTrafficSourceCookies=function(){return g((function(e){return o.get(e)}))},e.prototype.getFirstTrafficSourceCookies=function(){return g((function(e){return o.get("first_".concat(e))}))},e.prototype.init=function(e){this.ownDomains=e.ownDomains||[],this.excludedDomains=e.excludedDomains||[],this.excludedDomainPrefixes=e.excludedDomainPrefixes||[],this.config=e,this.trackLandingPage(),this.trackLandingPageReferrer(),this.trackLandingPageUserAgent(),this.trackSessionStartTimeUsec(),this.trackCookies(),this.trackFirstCookies(),this.watchLinkClicks(),this.watchTransitions()},e.prototype.getCurrentParams=function(){var e=r(window.location.href),o=this.getTrafficSourceCookies()||{},t=a(e.searchParams),i=Object.keys(t).length>0,c="gad_campaignid"in t||"gad_source"in t||"gbraid"in t||"wbraid"in t||"gclid"in t;if("fbclid"in t)return d(d(d({},f),t),{utm_source:"facebook"});if(c)return d(d(d({},f),t),{utm_source:"google",utm_medium:"cpc"});if(i)return d(d({},f),t);if(document.referrer){if(this.isSameDomain(document.referrer))return d(d({},f),o);if(!this.isOwnDomain(document.referrer)&&!this.isExcludedDomain(document.referrer)){var g=n(document.referrer).replace("www.",""),u=s[g],m=l[g];return d(d({},f),{utm_source:u||m||g,utm_medium:u?"organic":m?"social":"referral"})}}return o&&Object.keys(o).length>0?d(d({},f),o):d(d({},f),{utm_source:"(direct)"})},e.prototype.saveTrafficSourceCookies=function(e){var o=this;Object.entries(e).forEach((function(e){var t=e[0],r=e[1];r&&("fbclid"===t&&(t="fbc_lnd",r="null"===r?"null":"fb.1.".concat(Date.now(),".").concat(r)),o.setCookie(t,r))}))},e.prototype.saveFirstTrafficSourceCookies=function(e){var t=this;Object.entries(e).forEach((function(e){var r=e[0],n=e[1];if(n){if("fbclid"===r)if(r="fbc","null"===n)n="null";else{n=o.get("fbc_lnd")||"fb.1.".concat(Date.now(),".").concat(n)}t.setCookie("first_".concat(r),n)}}))},e.prototype.trackCookies=function(){var e=this.getTrafficSourceCookies(),o=this.getCurrentParams(),t=r(window.location.href),n=a(t.searchParams),i=Object.keys(n).length>0,c=new URLSearchParams(window.location.search);if("true"!==c.get("ignore_referrer")){if(["gclid","wbraid","gbraid","gad_source","gad_campaignid"].some((function(e){return c.has(e)}))){var g=c.get("gad_source")||"null",s=c.get("gad_campaignid")||"null",l=(1e3*(new Date).getTime()).toString(),u=window.location.href,m=document.referrer||"null",f=navigator.userAgent||"null";this.setCookie("gad_source_last_click",g),this.setCookie("gad_campaignid_last_click",s),this.setCookie("session_start_time_usec_last_click",l),this.setCookie("landing_page_last_click",u),this.setCookie("landing_page_referrer_last_click",m),this.setCookie("landing_page_user_agent_last_click",f)}e&&!i&&document.referrer&&(this.isOwnDomain(document.referrer)||this.isExcludedDomain(document.referrer))?this.saveTrafficSourceCookies(e):this.saveTrafficSourceCookies(o)}},e.prototype.trackFirstCookies=function(){var e="true"===new URLSearchParams(window.location.search).get("ignore_referrer"),t=o.get("landing_page"),r=o.get("landing_page_referrer"),n=o.get("landing_page_user_agent"),i=o.get("session_start_time_usec");t&&!o.get("first_landing_page")&&this.setCookie("first_landing_page",t),r&&!o.get("first_landing_page_referrer")&&this.setCookie("first_landing_page_referrer",r),n&&!o.get("first_landing_page_user_agent")&&this.setCookie("first_landing_page_user_agent",n),i&&!o.get("first_session_start_time_usec")&&this.setCookie("first_session_start_time_usec",i),e||this.saveFirstTrafficSourceCookies(this.getFirstTrafficSourceCookies()||this.getCurrentParams())},e.prototype.trackLandingPageReferrer=function(){var e=document.referrer;e&&this.setCookie("landing_page_referrer",e)},e.prototype.trackLandingPageUserAgent=function(){var e=navigator.userAgent||"null";e&&this.setCookie("landing_page_user_agent",e)},e.prototype.trackLandingPage=function(){var e=o.get("landing_page"),t=new URLSearchParams(window.location.search),r="true"===t.get("ignore_referrer"),n=t.get("landing_page");r||(n?this.setCookie("landing_page",n):e&&document.referrer&&(this.isOwnDomain(document.referrer)||this.isExcludedDomain(document.referrer))?this.setCookie("landing_page",e):this.setCookie("landing_page",window.location.href))},e.prototype.trackSessionStartTimeUsec=function(){var e=1e3*(new Date).getTime();this.setCookie("session_start_time_usec",e.toString())},e.prototype.filterParams=function(e){if(e)return Object.fromEntries(Object.entries(e).filter((function(e){var o=e[1];return null!==o&&"null"!==o&&""!==o})))},e.prototype.watchLinkClicks=function(){var e=this;document.addEventListener("click",(function(t){var r;if(!t.defaultPrevented){var n=null===(r=t.target)||void 0===r?void 0:r.closest("a");if(n&&n.hasAttribute("href")){var i=n.getAttribute("href");if(!i)return;var a=e.isOwnDomain(i),g=e.isSameDomain(i);if(a&&!g){var s=e.filterParams(e.getTrafficSourceCookies()),l=e.getFirstTrafficSourceCookies(),u=o.get("landing_page"),m=c(i,s);l&&(m=c(m,l,"first_")),u&&(m=c(m,{landing_page:u})),m instanceof URL&&(m=m.href),n.setAttribute("href",m)}}}}))},e.prototype.watchTransitions=function(){var e=this,t=window.open;window.open=function(r,n,i){var a=r;if(r){var g=e.isOwnDomain(r),s=e.isSameDomain(r);if(g&&!s){var l=e.filterParams(e.getTrafficSourceCookies()),u=e.getFirstTrafficSourceCookies(),m=o.get("landing_page");a=c(r,l),u&&(a=c(r,u,"first_")),m&&(a=c(a,{landing_page:m}))}}return t(a,n,i)}},e}();window.trafficSourceManager||Object.defineProperty(window,"trafficSourceManager",{value:new h})})();
trafficSourceManager.init({
ownDomains: ["newscatcherapi.com"],
excludedDomains: [],
excludedDomainPrefixes: ["accounts.google", "accounts.youtube", "login.microsoftonline"],
});