-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1 lines (1 loc) · 1.62 KB
/
script.js
File metadata and controls
1 lines (1 loc) · 1.62 KB
1
"use strict";var trackr=(()=>{var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},m=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of p(e))!l.call(t,o)&&o!==n&&s(t,o,{get:()=>e[o],enumerable:!(i=f(e,o))||i.enumerable});return t};var h=t=>m(s({},"__esModule",{value:!0}),t);var k={};g(k,{init:()=>w,track:()=>y});var r=null;function w(t){r=t,a(),typeof window!="undefined"&&(window.addEventListener("popstate",a),window.addEventListener("hashchange",a),c("pushState"),c("replaceState"))}function c(t){let e=history[t].bind(history);history[t]=function(...n){e(...n),a()}}function y(t,e){if(!r){console.warn("[trackr] Not initialized. Call init() first.");return}d({type:"event",name:t,url:u(),props:e,ts:Date.now()})}function a(){if(!r)return;let t=v();d({type:"pageview",url:u(),referrer:document.referrer?new URL(document.referrer).hostname:void 0,...Object.keys(t).length>0&&{utm:t},ts:Date.now()})}function u(){return window.location.pathname+window.location.search}function v(){let t=new URLSearchParams(window.location.search),e={},n=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];for(let i of n){let o=t.get(i);o&&(e[i.replace("utm_","")]=o)}return e}function d(t){if(!r)return;let e=JSON.stringify(t);navigator.sendBeacon?navigator.sendBeacon(r.endpoint,new Blob([e],{type:"application/json"})):fetch(r.endpoint,{method:"POST",body:e,keepalive:!0,headers:{"Content-Type":"application/json"}}).catch(()=>{}),r.debug&&console.log("[trackr]",t)}return h(k);})();