@kylelogue/eventfoundry-tracker 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var EventFoundry=(()=>{var p=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var A=(e,t,n)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))F.call(t,n)&&A(e,n,t[n]);if(N)for(var n of N(t))V.call(t,n)&&A(e,n,t[n]);return e};var K=(e,t)=>{for(var n in t)p(e,n,{get:t[n],enumerable:!0})},W=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!F.call(e,r)&&r!==n&&p(e,r,{get:()=>t[r],enumerable:!(o=j(t,r))||o.enumerable});return e};var q=e=>W(p({},"__esModule",{value:!0}),e);var g=(e,t,n)=>new Promise((o,r)=>{var a=d=>{try{l(n.next(d))}catch(m){r(m)}},s=d=>{try{l(n.throw(d))}catch(m){r(m)}},l=d=>d.done?o(d.value):Promise.resolve(d.value).then(a,s);l((n=n.apply(e,t)).next())});var ve={};K(ve,{reloadEventDefinitions:()=>b});var u=null,v=!1,y=null,f=!1;function P(){return v}function E(){return f}function B(){return["http://localhost","https://eventfoundry.app"]}function U(e){return B().includes(e)}function D(){if(v)return;v=!0;let e=document.createElement("style");e.textContent=` .eventfoundry-highlight { outline: 2px solid #3498db !important; outline-offset: 2px; cursor: pointer !important; } .eventfoundry-test-highlight { outline: 3px solid #e74c3c !important; outline-offset: 3px; background-color: rgba(231, 76, 60, 0.1) !important; } .eventfoundry-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 999998; pointer-events: none; cursor: crosshair; } body.eventfoundry-edit-mode, body.eventfoundry-edit-mode * { cursor: crosshair !important; } `,document.head.appendChild(e);let t=document.createElement("div");t.className="eventfoundry-overlay",document.body.appendChild(t),y=t,document.body.classList.add("eventfoundry-edit-mode"),document.body.addEventListener("mouseover",n=>{f||n.target.classList.contains("eventfoundry-overlay")||(u&&u.classList.remove("eventfoundry-highlight"),n.target.classList.add("eventfoundry-highlight"),u=n.target)},!0),document.body.addEventListener("mouseout",n=>{f||n.target.classList.contains("eventfoundry-overlay")||n.target.classList.remove("eventfoundry-highlight")},!0),document.body.addEventListener("click",n=>{if(n.target.classList.contains("eventfoundry-overlay")||f)return;n.preventDefault(),n.stopPropagation();let o=n.target,r="";o.className&&typeof o.className=="string"&&(r=o.className.trim().split(/\s+/).filter(l=>!l.startsWith("eventfoundry-")).join(" "));let a=window.location.pathname+window.location.search+window.location.hash,s={tagName:o.tagName.toLowerCase(),text:o.textContent.trim().substring(0,50),id:o.id,className:r,selector:ne(o),page_path:a};window.parent.postMessage({type:"ELEMENT_SELECTED",element:s},"*")},!0),window.addEventListener("message",n=>{if(U(n.origin)&&(n.data.type==="HIGHLIGHT_SELECTOR"&&oe(n.data.selector),n.data.type==="COUNT_MATCHES")){let o=n.data.selector,r=0;try{r=document.querySelectorAll(o).length}catch(a){r=0}window.parent.postMessage({type:"MATCH_COUNT_RESULT",selector:o,count:r},"*")}})}function i(e){return e?e.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g,"\\$1"):""}function z(e){return e?!!(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i.test(e)||/\d{13}/.test(e)||/^[a-f0-9]{16,}$/i.test(e)||/-\d{4,}$/.test(e)):!1}function J(e,t){try{let n=document.querySelectorAll(t);return n.length===1&&n[0]===e}catch(n){return!1}}function w(e){return!e.className||typeof e.className!="string"?[]:e.className.trim().split(/\s+/).filter(t=>t&&!t.startsWith("eventfoundry-"))}function $(e,t=!0){let n=e.parentElement;if(!n)return null;let o=w(n);return t&&o.length>0?`.${i(o[0])}`:n.tagName.toLowerCase()}function c(e,t,n,o){return J(o,t)?(e.push({selector:t,priority:n}),!0):!1}function Y(e){let t=[];if(e.id&&!z(e.id)){let n=`#${i(e.id)}`;c(t,n,100,e)}return t}function Q(e){let t=[],n=Array.from(e.attributes).filter(o=>o.name.startsWith("data-")&&o.value);for(let o of n){let r=`[${o.name}="${i(o.value)}"]`;if(c(t,r,90,e))break}return t}function X(e){let t=[],n=w(e);if(n.length===0)return t;let o=e.tagName.toLowerCase();for(let r of n){let a=`${o}.${i(r)}`;if(c(t,a,85,e))break}if(n.length>=2){let r=`.${i(n[0])}.${i(n[1])}`;if(c(t,r,82,e),n.length>=3){let a=`.${i(n[0])}.${i(n[1])}.${i(n[2])}`;c(t,a,82,e)}}for(let r of n){let a=`.${i(r)}`;if(c(t,a,80,e))break}return t}function Z(e){let t=[],n=e.tagName.toLowerCase(),o=["type","name","href","role","aria-label"];for(let r of o){let a=e.getAttribute(r);if(a){let s=`${n}[${r}="${i(a)}"]`;if(c(t,s,70,e))break}}return t}function ee(e){let t=[],n=$(e,!0);if(!n)return t;let o=e.tagName.toLowerCase(),r=w(e);if(r.length>0){let s=`${n} .${i(r[0])}`;c(t,s,75,e)}if(r.length>0){let s=`${n} ${o}.${i(r[0])}`;c(t,s,72,e)}let a=`${n} ${o}`;return c(t,a,65,e),t}function te(e){let t=[],n=e.tagName.toLowerCase(),o=e.parentElement;if(!o)return[{selector:n,priority:10}];let r=$(e,!0),s=Array.from(o.children).indexOf(e)+1,l=`${r} ${n}:nth-child(${s})`;return c(t,l,50,e),t}function ne(e){let t=[];return t.push(...Y(e)),t.push(...Q(e)),t.push(...X(e)),t.push(...Z(e)),t.push(...ee(e)),t.push(...te(e)),t.length>0?(t.sort((n,o)=>o.priority-n.priority),t[0].selector):e.tagName.toLowerCase()}function oe(e){document.querySelectorAll(".eventfoundry-test-highlight").forEach(t=>{t.classList.remove("eventfoundry-test-highlight")});try{let t=document.querySelectorAll(e);t.forEach(n=>{n.classList.add("eventfoundry-test-highlight")}),setTimeout(()=>{t.forEach(n=>{n.classList.remove("eventfoundry-test-highlight")})},3e3)}catch(t){}}function M(){v&&(f=!0,y&&(y.style.display="none"),document.body.classList.remove("eventfoundry-edit-mode"),u&&(u.classList.remove("eventfoundry-highlight"),u=null))}function T(){v&&(f=!1,y&&(y.style.display=""),document.body.classList.add("eventfoundry-edit-mode"))}var _=console.log;function h(e,...t){e&&_&&_(...t)}function L(e,t=!1){!e||e.length===0||document.addEventListener("click",n=>{if(P()&&!E())return;let o=e.filter(s=>{try{return n.target.closest(s.selector)!==null}catch(l){return!1}});if(o.length===0)return;let r=o[0],a=I({event_category:"EventFoundry",event_label:r.name,transport_type:"beacon"},r.gaEventParams);if(h(t,"EventFoundry [DEV]: Tracked event (not sent to GA4)",r.gaEventName,a),t||window.gtag("event",r.gaEventName,a),E())try{window.parent.postMessage({type:"EVENT_FIRED",timestamp:Date.now(),eventName:r.name,gaEventName:r.gaEventName,selector:r.selector,params:a,pagePath:window.location.pathname},"*")}catch(s){}o.length>1},!0)}function re(){return["http://localhost","https://eventfoundry.app"]}function ae(e){return re().some(n=>n==="http://localhost"?e.startsWith("http://localhost"):e===n)}function S(){try{return window.self!==window.top}catch(e){return!0}}function k(){S()&&(window.addEventListener("message",e=>{if(ae(e.origin))switch(e.data.type){case"ENTER_EDIT_MODE":se();break;case"ENABLE_PREVIEW":ie();break;case"DISABLE_PREVIEW":ce();break;case"RELOAD_CONFIG":b();break}}),setTimeout(()=>{window.parent&&window.parent.postMessage({type:"IFRAME_READY"},"*")},100))}function se(){D()}function ie(){M()}function ce(){T()}var O=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",le=O?"http://localhost/api/tracking/events":"https://eventfoundry.app/api/tracking/events",de=3600*1e3;function C(e){return`eventfoundry_definitions_${e}`}function R(){let e=document.currentScript||document.querySelector("script[data-site-key]");if(!e)return null;let t=e.getAttribute("data-dev-mode"),n=t==="false"?!1:O||t==="true";return{siteKey:e.getAttribute("data-site-key"),measurementId:e.getAttribute("data-measurement-id"),devMode:n}}function ue(e){return g(this,null,function*(){if(window.gtag&&typeof window.gtag=="function")return{hasGtag:!0,wasInjected:!1};if(!e)return{hasGtag:!1,wasInjected:!1};let t=document.createElement("script");t.async=!0,t.src=`https://www.googletagmanager.com/gtag/js?id=${e}`,document.head.appendChild(t),window.dataLayer=window.dataLayer||[];function n(){dataLayer.push(arguments)}return window.gtag=n,n("js",new Date),n("config",e),yield new Promise(o=>{t.onload=o,setTimeout(o,5e3)}),{hasGtag:!0,wasInjected:!0}})}function x(){return g(this,null,function*(){let e=R();if(!e||!e.siteKey)return;let{siteKey:t,measurementId:n,devMode:o}=e;S()&&k();let{hasGtag:r,wasInjected:a}=yield ue(n);if(r){h(o,"\u26A0 Dev mode: Events disabled"),h(!o,"\u2713 Production mode: Events enabled");try{let l=(yield G(t)).events;L(l,o)}catch(s){}}})}function G(e){return g(this,null,function*(){let t=fe(e);if(t)return t;let n=yield fetch(`${le}?siteKey=${e}`);if(!n.ok)throw new Error(`API returned ${n.status}`);let o=yield n.json();return ge(e,o),o})}function fe(e){try{let t=C(e),n=localStorage.getItem(t);if(!n)return null;let{data:o,timestamp:r}=JSON.parse(n);return Date.now()-r>de?(localStorage.removeItem(t),null):o}catch(t){return null}}function ge(e,t){try{let n=C(e),o={data:t,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(o))}catch(n){}}function b(){return g(this,null,function*(){let e=R();if(!e||!e.siteKey)return;let{siteKey:t,devMode:n}=e;try{let o=C(t);localStorage.removeItem(o)}catch(o){}try{let r=(yield G(t)).events;L(r,n)}catch(o){}})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",x):x();return q(ve);})();
1
+ var EventFoundry=(()=>{var E=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames,F=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var I=(e,n,t)=>n in e?E(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,_=(e,n)=>{for(var t in n||(n={}))P.call(n,t)&&I(e,t,n[t]);if(F)for(var t of F(n))K.call(n,t)&&I(e,t,n[t]);return e};var q=(e,n)=>{for(var t in n)E(e,t,{get:n[t],enumerable:!0})},B=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of W(n))!P.call(e,r)&&r!==t&&E(e,r,{get:()=>n[r],enumerable:!(o=H(n,r))||o.enumerable});return e};var U=e=>B(E({},"__esModule",{value:!0}),e);var g=(e,n,t)=>new Promise((o,r)=>{var a=d=>{try{c(t.next(d))}catch(w){r(w)}},s=d=>{try{c(t.throw(d))}catch(w){r(w)}},c=d=>d.done?o(d.value):Promise.resolve(d.value).then(a,s);c((t=t.apply(e,n)).next())});var pe={};q(pe,{reloadEventDefinitions:()=>S});var m=null;function v(){return m}function z(){return["http://localhost","https://eventfoundry.app"]}function J(e){return z().some(t=>t==="http://localhost"?e.startsWith("http://localhost"):e===t)}function L(){try{return window.self!==window.top}catch(e){return!0}}function D(){L()&&(console.log("EventFoundry: Running in iframe, waiting for editor activation"),window.addEventListener("message",e=>{if(!J(e.origin)){console.warn("EventFoundry: Rejected postMessage from untrusted origin:",e.origin);return}switch(m||(m=e.origin,console.log("EventFoundry: Parent origin established:",m)),e.data.type){case"ENTER_EDIT_MODE":console.log("\u2190 ENTER_EDIT_MODE received"),Y();break;case"ENABLE_PREVIEW":console.log("\u2190 ENABLE_PREVIEW received"),Q();break;case"DISABLE_PREVIEW":console.log("\u2190 DISABLE_PREVIEW received"),X();break;case"RELOAD_CONFIG":console.log("\u2190 RELOAD_CONFIG received"),S();break}}),setTimeout(()=>{window.parent&&(window.parent.postMessage({type:"IFRAME_READY"},"*"),console.log("\u2192 IFRAME_READY sent to parent"))},100))}function Y(){T()}function Q(){console.log("EventFoundry: Enabling Preview Mode"),$()}function X(){console.log("EventFoundry: Disabling Preview Mode (Edit Mode active)"),M()}var u=null,h=!1,p=null,f=!1;function O(){return h}function b(){return f}function Z(){return["http://localhost","https://eventfoundry.app"]}function ee(e){return Z().some(t=>t==="http://localhost"?e.startsWith("http://localhost"):e===t)}function T(){if(h)return;h=!0;let e=document.createElement("style");e.textContent=` .eventfoundry-highlight { outline: 2px solid #3498db !important; outline-offset: 2px; cursor: pointer !important; } .eventfoundry-test-highlight { outline: 3px solid #e74c3c !important; outline-offset: 3px; background-color: rgba(231, 76, 60, 0.1) !important; } .eventfoundry-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 999998; pointer-events: none; cursor: crosshair; } body.eventfoundry-edit-mode, body.eventfoundry-edit-mode * { cursor: crosshair !important; } `,document.head.appendChild(e);let n=document.createElement("div");n.className="eventfoundry-overlay",document.body.appendChild(n),p=n,document.body.classList.add("eventfoundry-edit-mode"),document.body.addEventListener("mouseover",t=>{f||t.target.classList.contains("eventfoundry-overlay")||(u&&u.classList.remove("eventfoundry-highlight"),t.target.classList.add("eventfoundry-highlight"),u=t.target)},!0),document.body.addEventListener("mouseout",t=>{f||t.target.classList.contains("eventfoundry-overlay")||t.target.classList.remove("eventfoundry-highlight")},!0),document.body.addEventListener("click",t=>{if(t.target.classList.contains("eventfoundry-overlay"))return;if(f){console.log("EventFoundry: Preview Mode - allowing click to pass through");return}t.preventDefault(),t.stopPropagation();let o=t.target,r="";o.className&&typeof o.className=="string"&&(r=o.className.trim().split(/\s+/).filter(d=>!d.startsWith("eventfoundry-")).join(" "));let a=window.location.pathname+window.location.search+window.location.hash,s={tagName:o.tagName.toLowerCase(),text:o.textContent.trim().substring(0,50),id:o.id,className:r,selector:le(o),page_path:a},c=v();c?(window.parent.postMessage({type:"ELEMENT_SELECTED",element:s},c),console.log("\u2192 ELEMENT_SELECTED sent to parent")):console.warn("EventFoundry: Cannot send ELEMENT_SELECTED - parent origin not established")},!0),window.addEventListener("message",t=>{if(ee(t.origin)&&(t.data.type==="HIGHLIGHT_SELECTOR"&&(console.log("\u2190 HIGHLIGHT_SELECTOR received:",t.data.selector),de(t.data.selector)),t.data.type==="COUNT_MATCHES")){let o=t.data.selector,r=0;try{r=document.querySelectorAll(o).length}catch(s){r=0}let a=v();a&&window.parent.postMessage({type:"MATCH_COUNT_RESULT",selector:o,count:r},a)}})}function i(e){return e?e.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g,"\\$1"):""}function te(e){return e?!!(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i.test(e)||/\d{13}/.test(e)||/^[a-f0-9]{16,}$/i.test(e)||/-\d{4,}$/.test(e)):!1}function ne(e,n){try{let t=document.querySelectorAll(n);return t.length===1&&t[0]===e}catch(t){return!1}}function C(e){return!e.className||typeof e.className!="string"?[]:e.className.trim().split(/\s+/).filter(n=>n&&!n.startsWith("eventfoundry-"))}function x(e,n=!0){let t=e.parentElement;if(!t)return null;let o=C(t);return n&&o.length>0?`.${i(o[0])}`:t.tagName.toLowerCase()}function l(e,n,t,o){return ne(o,n)?(e.push({selector:n,priority:t}),!0):!1}function oe(e){let n=[];if(e.id&&!te(e.id)){let t=`#${i(e.id)}`;l(n,t,100,e)}return n}function re(e){let n=[],t=Array.from(e.attributes).filter(o=>o.name.startsWith("data-")&&o.value);for(let o of t){let r=`[${o.name}="${i(o.value)}"]`;if(l(n,r,90,e))break}return n}function ae(e){let n=[],t=C(e);if(t.length===0)return n;let o=e.tagName.toLowerCase();for(let r of t){let a=`${o}.${i(r)}`;if(l(n,a,85,e))break}if(t.length>=2){let r=`.${i(t[0])}.${i(t[1])}`;if(l(n,r,82,e),t.length>=3){let a=`.${i(t[0])}.${i(t[1])}.${i(t[2])}`;l(n,a,82,e)}}for(let r of t){let a=`.${i(r)}`;if(l(n,a,80,e))break}return n}function se(e){let n=[],t=e.tagName.toLowerCase(),o=["type","name","href","role","aria-label"];for(let r of o){let a=e.getAttribute(r);if(a){let s=`${t}[${r}="${i(a)}"]`;if(l(n,s,70,e))break}}return n}function ie(e){let n=[],t=x(e,!0);if(!t)return n;let o=e.tagName.toLowerCase(),r=C(e);if(r.length>0){let s=`${t} .${i(r[0])}`;l(n,s,75,e)}if(r.length>0){let s=`${t} ${o}.${i(r[0])}`;l(n,s,72,e)}let a=`${t} ${o}`;return l(n,a,65,e),n}function ce(e){let n=[],t=e.tagName.toLowerCase(),o=e.parentElement;if(!o)return[{selector:t,priority:10}];let r=x(e,!0),s=Array.from(o.children).indexOf(e)+1,c=`${r} ${t}:nth-child(${s})`;return l(n,c,50,e),n}function le(e){let n=[];return n.push(...oe(e)),n.push(...re(e)),n.push(...ae(e)),n.push(...se(e)),n.push(...ie(e)),n.push(...ce(e)),n.length>0?(n.sort((t,o)=>o.priority-t.priority),n[0].selector):e.tagName.toLowerCase()}function de(e){document.querySelectorAll(".eventfoundry-test-highlight").forEach(n=>{n.classList.remove("eventfoundry-test-highlight")});try{let n=document.querySelectorAll(e);n.forEach(t=>{t.classList.add("eventfoundry-test-highlight")}),setTimeout(()=>{n.forEach(t=>{t.classList.remove("eventfoundry-test-highlight")})},3e3)}catch(n){console.error("EventFoundry: Invalid selector",e,n)}}function $(){if(!h){console.warn("EventFoundry: Cannot enable preview - overlay not active");return}f=!0,console.log("EventFoundry: Preview Mode enabled - all interactions allowed"),p&&(p.style.display="none"),document.body.classList.remove("eventfoundry-edit-mode"),u&&(u.classList.remove("eventfoundry-highlight"),u=null)}function M(){if(!h){console.warn("EventFoundry: Cannot disable preview - overlay not active");return}f=!1,console.log("EventFoundry: Preview Mode disabled - Edit Mode active"),p&&(p.style.display=""),document.body.classList.add("eventfoundry-edit-mode")}var k=console.log;function y(e,...n){e&&k&&k(...n)}function N(e,n=!1){!e||e.length===0||document.addEventListener("click",t=>{if(O()&&!b())return;let o=e.filter(s=>{try{return t.target.closest(s.selector)!==null}catch(c){return console.warn("EventFoundry: Invalid selector",s.selector,c.message),!1}});if(o.length===0)return;let r=o[0],a=_({event_category:"EventFoundry",event_label:r.name,transport_type:"beacon"},r.gaEventParams);if(y(n,"EventFoundry [DEV]: Tracked event (not sent to GA4)",r.gaEventName,a),n||window.gtag("event",r.gaEventName,a),b())try{let s=v();s?(window.parent.postMessage({type:"EVENT_FIRED",timestamp:Date.now(),eventName:r.name,gaEventName:r.gaEventName,selector:r.selector,params:a,pagePath:window.location.pathname},s),console.log("\u2192 EVENT_FIRED sent to parent")):console.warn("EventFoundry: Cannot send EVENT_FIRED - parent origin not established")}catch(s){console.warn("EventFoundry: Failed to send EVENT_FIRED postMessage",s)}o.length>1&&console.warn("EventFoundry: Multiple events matched, only firing first:",o.map(s=>s.name))},!0)}var G=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",ue=G?"http://localhost/api/tracking/events":"https://eventfoundry.app/api/tracking/events",fe=3600*1e3;function A(e){return`eventfoundry_definitions_${e}`}function V(){let e=document.currentScript||document.querySelector("script[data-site-key]");if(!e)return console.error("EventFoundry: Could not find script tag"),null;let n=e.getAttribute("data-dev-mode"),t=n==="false"?!1:G||n==="true";return{siteKey:e.getAttribute("data-site-key"),measurementId:e.getAttribute("data-measurement-id"),devMode:t}}function ge(e){return g(this,null,function*(){if(window.gtag&&typeof window.gtag=="function")return{hasGtag:!0,wasInjected:!1};if(!e)return console.warn("EventFoundry: No GA4 detected and no measurement ID provided. Events will not be tracked."),{hasGtag:!1,wasInjected:!1};let n=document.createElement("script");n.async=!0,n.src=`https://www.googletagmanager.com/gtag/js?id=${e}`,document.head.appendChild(n),window.dataLayer=window.dataLayer||[];function t(){dataLayer.push(arguments)}return window.gtag=t,t("js",new Date),t("config",e),yield new Promise(o=>{n.onload=o,setTimeout(o,5e3)}),{hasGtag:!0,wasInjected:!0}})}function R(){return g(this,null,function*(){let e=V();if(!e||!e.siteKey){console.error("EventFoundry: No site key provided");return}let{siteKey:n,measurementId:t,devMode:o}=e;console.log("\u2713 EventFoundry tracker loaded"),L()&&D();let{hasGtag:r,wasInjected:a}=yield ge(t);if(!r){console.error("EventFoundry: Cannot track events without GA4");return}console.log(a?"\u2713 GA4 injected successfully":"\u2713 GA4 detected"),y(o,"\u26A0 Dev mode: Events disabled (v0.3.3)"),y(!o,"\u2713 Production mode: Events enabled (v0.3.3)");try{let c=(yield j(n)).events;N(c,o)}catch(s){console.error("EventFoundry: Failed to initialize:",s)}})}function j(e){return g(this,null,function*(){let n=ve(e);if(n)return n;let t=yield fetch(`${ue}?siteKey=${e}`);if(!t.ok)throw new Error(`API returned ${t.status}`);let o=yield t.json();return he(e,o),o})}function ve(e){try{let n=A(e),t=localStorage.getItem(n);if(!t)return null;let{data:o,timestamp:r}=JSON.parse(t);return Date.now()-r>fe?(localStorage.removeItem(n),null):o}catch(n){return console.warn("EventFoundry: Cache read failed:",n),null}}function he(e,n){try{let t=A(e),o={data:n,timestamp:Date.now()};localStorage.setItem(t,JSON.stringify(o))}catch(t){console.warn("EventFoundry: Cache write failed:",t)}}function S(){return g(this,null,function*(){let e=V();if(!e||!e.siteKey){console.error("EventFoundry: No site key available for reload");return}let{siteKey:n,devMode:t}=e;try{let o=A(n);localStorage.removeItem(o),console.log("EventFoundry: Cache cleared, reloading definitions")}catch(o){console.warn("EventFoundry: Failed to clear cache",o)}try{let r=(yield j(n)).events;N(r,t),console.log("EventFoundry: Definitions reloaded successfully")}catch(o){console.error("EventFoundry: Failed to reload definitions",o)}})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",R):R();return U(pe);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kylelogue/eventfoundry-tracker",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "EventFoundry tracking script for custom GA4 event tracking",
5
5
  "main": "dist/tracker.min.js",
6
6
  "files": [