forked from CodeYourFuture/Module-Onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.js
More file actions
1 lines (1 loc) · 6.78 KB
/
analytics.js
File metadata and controls
1 lines (1 loc) · 6.78 KB
1
!(function(){"use strict";var g=function(i,o){for(var a=0;a<i.length;a++)o(i[a])},b=Object.assign||function(i){for(var o,a=1,u=arguments.length;a<u;a++){o=arguments[a];for(var v in o)Object.prototype.hasOwnProperty.call(o,v)&&(i[v]=o[v])}return i},s=window.document.currentScript,y=s.getAttribute("data-instance")||"AhrefsAnalytics";if(window[y]!==void 0){console.warn("".concat(y," script is already initialized, exiting... Did you install it twice? Please fix."));return}var E=s.getAttribute("data-api")||new URL(s.src).origin+"/api/event",_=s.getAttribute("data-error")||new URL(s.src).origin+"/api/error",V=s.getAttribute("data-track-visibility")!=null,z=s.getAttribute("data-no-pageview-on-load")!=null,F=s.getAttribute("data-no-pageview-auto")!=null,S=window.location;function J(){try{var i=s.getAttribute("data-page-location");return i==null||i===""?S:i.startsWith("/")?new URL(i,S.origin):new URL(i)}catch(o){}return S}function K(i,o,a){var u=new XMLHttpRequest;u.open("POST",i,!0),u.setRequestHeader("Content-Type","text/plain"),u.send(o),u.onreadystatechange=function(){u.readyState===4&&a!=null&&a()}}function f(i){try{i()}catch(a){if(a instanceof Error)K(_,JSON.stringify({message:a.message,stack:a.stack}));else{var o="cannot-stringify-error";try{o=String(a)}catch(u){}K(_,JSON.stringify({message:o,stack:null}))}throw a}}function G(i){document.readyState==="loading"?window.addEventListener("DOMContentLoaded",function(){f(function(){return i()})}):i()}f(function(){function i(t,e){t&&console.warn("Ignoring Event: "+t),e&&e.callback&&e.callback()}function o(t,e){var n=J();if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(n.hostname)||n.protocol==="file:")return i("localhost",e);if((window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)&&!window.__web_analytics)return i(null,e);var r=s.getAttribute("data-key"),c=s.getAttribute("data-domain");if(r==null&&c==null)return i("missing data-key",e);var d;try{d=window.navigator.languages||window.navigator.language||window.navigator.browserLanguage||window.navigator.userLanguage||window.navigator.systemLanguage}catch(m){}var p={},X=!1;try{for(var C=0;C<s.attributes.length;C++){var R=s.attributes[C];if(R.name.startsWith("data-prop-")){var I=R.name.substring(10),$=R.value;I&&$&&(p[I]=$,X=!0)}}}catch(m){}var N=null;try{N=document.title}catch(m){}var l={};l.n=t,l.u=n.href,d!=null&&(l.l=d),c!=null&&(l.d=c),r!=null&&(l.k=r),l.r=window.document.referrer||null,e&&e.meta&&(l.m=JSON.stringify(e.meta)),(e&&e.props||X)&&(l.p=JSON.stringify(b({},p,e==null?void 0:e.props)));var M;try{M=window.screen.width}catch(m){}M!=null&&(l.sw=M);var H;try{H=window.screen.height}catch(m){}H!=null&&(l.sh=H);var T;try{T=window.devicePixelRatio}catch(m){}return T!=null&&(l.sr=T),N!=null&&(l.t=N),l}function a(t,e){var n=o(t,e);if(n!=null){var r=new XMLHttpRequest;r.open("POST",E,!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(n)),r.onreadystatechange=function(){r.readyState===4&&e&&e.callback&&e.callback({status:r.status})}}}function u(t,e){var n=navigator.sendBeacon!=null,r=o(t,e);if(r!=null){var c=JSON.stringify(r);if(n){var d=new Blob([c],{type:"text/plain"});navigator.sendBeacon(E,d)}else{var p=new XMLHttpRequest;p.open("POST",E,!0),p.setRequestHeader("Content-Type","text/plain"),p.send(c)}}}window[y]={sendEvent:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];f(function(){a.apply(void 0,t)})}};var v;function h(){f(function(){var t=J();v!==t.href&&(v=t.href,a("pageview"))})}if(!F){var A=window.history;if(A.pushState){var Q=A.pushState;A.pushState=function(){Q.apply(this,arguments),h()},window.addEventListener("popstate",h)}z||(window.document.visibilityState==="prerender"?window.document.addEventListener("visibilitychange",function(){v||window.document.visibilityState!=="visible"||h()}):h())}V&&(document.addEventListener("visibilitychange",function(){f(function(){if(v==null){var t=document.visibilityState;t==="hidden"?u("x-visibilitychange-hidden"):t==="visible"&&u("x-visibilitychange-visible")}})}),document.addEventListener("pagehide",function(){f(function(){return u("x-pagehide")})}));var U=/\bAhrefsAnalytics\-prop\-([^\s\-]+)\-([^\s]+)/g;function L(t){if(t){var e=t.className;if(e){var n={};U.lastIndex=0;for(var r=null;r=U.exec(e);){var c=r[1],d=r[2];!c||!d||(n[c]=d)}if(Object.keys(n).length!==0)return n}}}function Y(t,e){if(!(e!=null&&e.defaultPrevented)&&!(e!=null&&e.type==="auxclick"&&e.button!==1)&&t&&t.href&&!(t.protocol==="data:"||t.protocol==="blob:"||t.protocol==="javascript:")){var n=L(t);u("x-link-click",{props:b({},n,{href:t.href}),meta:{metaKey:String(!!(e!=null&&e.metaKey)),ctrlKey:String(!!(e!=null&&e.ctrlKey)),shiftKey:String(!!(e!=null&&e.shiftKey))}})}}function Z(t){return!!t&&t instanceof HTMLAnchorElement&&!!t.href}function tt(t,e){if(!(e!=null&&e.defaultPrevented)&&t&&t.action){var n=L(t);u("x-form-submit",{props:b({},n,{action:t.action})})}}function j(t){return!!t&&t instanceof HTMLFormElement&&!!t.action}function B(t,e){var n=L(e);u(t,{props:n})}var W='*[class^="AhrefsAnalytics-event-"]',D=/\bAhrefsAnalytics\-event\-([^\s]+)/g;function k(t){if(!t||!(t instanceof HTMLElement)||!t.className)return[];var e=null,n=[];for(D.lastIndex=0;e=D.exec(t.className);){var r=e[1];r&&n.push(r)}return n}function et(t){return k(t).length>0}if(window.MutationObserver!=null){var O=function(t){if(!t.ahrefsAnalytics_click_tracked){t.ahrefsWebAnalytics_click_tracked=!0;var e=function(n){return f(function(){return Y(t,n)})};t.addEventListener("click",e),t.addEventListener("auxclick",e)}},x=function(t){if(!t.ahrefsAnalytics_submit_tracked){t.ahrefsWebAnalytics_submit_tracked=!0;var e=function(n){return f(function(){tt(t,n);for(var r=0,c=k(t);r<c.length;r++){var d=c[r];B(d,t)}})};t.addEventListener("submit",e)}},P=function(t){if(!j(t)&&!t.ahrefsAnalytics_event_tracked){t.ahrefsWebAnalytics_event_tracked=!0;var e=function(){f(function(){for(var n=0,r=k(t);n<r.length;n++){var c=r[n];B(c,t)}})};t.addEventListener("click",e)}},nt=new MutationObserver(function(t){f(function(){t.forEach(function(e){e.type==="childList"&&g(e.addedNodes,function(n){n.nodeType===Node.ELEMENT_NODE&&(Z(n)?O(n):n.querySelectorAll!=null&&g(n.querySelectorAll("a"),O),j(n)?x(n):n.querySelectorAll!=null&&g(n.querySelectorAll("form"),x),et(n)?P(n):n.querySelectorAll!=null&&g(n.querySelectorAll(W),P))})})})});G(function(){g(document.querySelectorAll("a"),O),g(document.querySelectorAll("form"),x),g(document.querySelectorAll(W),P),nt.observe(document.body,{childList:!0,subtree:!0})})}{var w=void 0,q=y+"-ready";typeof CustomEvent=="function"?w=new CustomEvent(q,{detail:null,bubbles:!0,cancelable:!0}):typeof document!="undefined"&&document.createEvent&&(w=document.createEvent("CustomEvent"),w.initCustomEvent(q,!0,!0,null)),w!=null&&typeof document!="undefined"&&(document.dispatchEvent?document.dispatchEvent(w):"fireEvent"in document&&document.fireEvent("on"+q,w))}})})();