@kylelogue/eventfoundry-tracker 0.1.0 → 0.2.0
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.
- package/dist/tracker.min.js +22 -1
- package/package.json +11 -4
package/dist/tracker.min.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
var EventFoundry=(()=>{var
|
|
1
|
+
var EventFoundry=(()=>{var T=Object.defineProperty;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var v=(t,n,e)=>n in t?T(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,E=(t,n)=>{for(var e in n||(n={}))I.call(n,e)&&v(t,e,n[e]);if(y)for(var e of y(n))D.call(n,e)&&v(t,e,n[e]);return t};var l=(t,n,e)=>new Promise((o,a)=>{var i=c=>{try{s(e.next(c))}catch(u){a(u)}},r=c=>{try{s(e.throw(c))}catch(u){a(u)}},s=c=>c.done?o(c.value):Promise.resolve(c.value).then(i,r);s((e=e.apply(t,n)).next())});var f=null,m=!1;function w(){return m}function b(){return["http://localhost","https://eventfoundry.app"]}function M(t){return b().includes(t)}function L(){if(m)return;m=!0;let t=document.createElement("style");t.textContent=`
|
|
2
|
+
.eventfoundry-highlight {
|
|
3
|
+
outline: 2px solid #3498db !important;
|
|
4
|
+
outline-offset: 2px;
|
|
5
|
+
cursor: pointer !important;
|
|
6
|
+
}
|
|
7
|
+
.eventfoundry-test-highlight {
|
|
8
|
+
outline: 3px solid #e74c3c !important;
|
|
9
|
+
outline-offset: 3px;
|
|
10
|
+
background-color: rgba(231, 76, 60, 0.1) !important;
|
|
11
|
+
}
|
|
12
|
+
.eventfoundry-overlay {
|
|
13
|
+
position: fixed;
|
|
14
|
+
top: 0;
|
|
15
|
+
left: 0;
|
|
16
|
+
right: 0;
|
|
17
|
+
bottom: 0;
|
|
18
|
+
z-index: 999998;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
cursor: crosshair;
|
|
21
|
+
}
|
|
22
|
+
`,document.head.appendChild(t);let n=document.createElement("div");n.className="eventfoundry-overlay",document.body.appendChild(n),document.body.addEventListener("mouseover",e=>{e.target.classList.contains("eventfoundry-overlay")||(f&&f.classList.remove("eventfoundry-highlight"),e.target.classList.add("eventfoundry-highlight"),f=e.target)},!0),document.body.addEventListener("mouseout",e=>{e.target.classList.contains("eventfoundry-overlay")||e.target.classList.remove("eventfoundry-highlight")},!0),document.body.addEventListener("click",e=>{if(e.target.classList.contains("eventfoundry-overlay"))return;e.preventDefault(),e.stopPropagation();let o=e.target,a="";o.className&&typeof o.className=="string"&&(a=o.className.trim().split(/\s+/).filter(r=>!r.startsWith("eventfoundry-")).join(" "));let i={tagName:o.tagName.toLowerCase(),text:o.textContent.trim().substring(0,50),id:o.id,className:a,selector:x(o)};window.parent.postMessage({type:"ELEMENT_SELECTED",element:i},"*"),console.log("\u2192 ELEMENT_SELECTED sent to parent")},!0),window.addEventListener("message",e=>{if(M(e.origin)&&(e.data.type==="HIGHLIGHT_SELECTOR"&&(console.log("\u2190 HIGHLIGHT_SELECTOR received:",e.data.selector),_(e.data.selector)),e.data.type==="COUNT_MATCHES")){let o=e.data.selector,a=0;try{a=document.querySelectorAll(o).length}catch(i){a=0}window.parent.postMessage({type:"MATCH_COUNT_RESULT",selector:o,count:a},"*")}})}function g(t){return t?t.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g,"\\$1"):""}function F(t){return t?!!(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i.test(t)||/\d{13}/.test(t)||/^[a-f0-9]{16,}$/i.test(t)||/-\d{4,}$/.test(t)):!1}function d(t,n){try{let e=document.querySelectorAll(n);return e.length===1&&e[0]===t}catch(e){return!1}}function x(t){let n=[];if(t.id&&!F(t.id)){let r=`#${g(t.id)}`;d(t,r)&&n.push({selector:r,priority:100})}let e=Array.from(t.attributes).filter(r=>r.name.startsWith("data-")&&r.value);for(let r of e){let s=`[${r.name}="${g(r.value)}"]`;if(d(t,s)){n.push({selector:s,priority:90});break}}if(t.className&&typeof t.className=="string"){let r=t.className.trim().split(/\s+/).filter(s=>!s.startsWith("eventfoundry-"));for(let s of r){let c=`.${g(s)}`;if(d(t,c)){n.push({selector:c,priority:80});break}}}let o=t.tagName.toLowerCase();t instanceof SVGElement&&(o=t.tagName.toLowerCase());let a=o,i=t.parentElement;if(i){let s=Array.from(i.children).indexOf(t)+1;a+=`:nth-child(${s})`}return d(t,a)&&n.push({selector:a,priority:50}),n.length>0?(n.sort((r,s)=>s.priority-r.priority),n[0].selector):o}function _(t){document.querySelectorAll(".eventfoundry-test-highlight").forEach(n=>{n.classList.remove("eventfoundry-test-highlight")});try{let n=document.querySelectorAll(t);n.forEach(e=>{e.classList.add("eventfoundry-test-highlight")}),setTimeout(()=>{n.forEach(e=>{e.classList.remove("eventfoundry-test-highlight")})},3e3)}catch(n){console.error("EventFoundry: Invalid selector",t,n)}}function A(t,n=!1){!t||t.length===0||document.addEventListener("click",e=>{if(w())return;let o=t.filter(r=>{try{return e.target.closest(r.selector)!==null}catch(s){return console.warn("EventFoundry: Invalid selector",r.selector,s.message),!1}});if(o.length===0)return;let a=o[0],i=E({event_category:"EventFoundry",event_label:a.name},a.gaEventParams);n?console.log("EventFoundry [DEV]: Tracked event (not sent to GA4)",a.gaEventName,i):(console.log("EventFoundry: Tracked event",a.gaEventName,i),window.gtag("event",a.gaEventName,i)),o.length>1&&console.warn("EventFoundry: Multiple events matched, only firing first:",o.map(r=>r.name))},!0)}function k(){return["http://localhost","https://eventfoundry.app"]}function O(t){return k().some(e=>e==="http://localhost"?t.startsWith("http://localhost"):t===e)}function h(){try{return window.self!==window.top}catch(t){return!0}}function C(){h()&&(window.addEventListener("message",t=>{if(!O(t.origin)){console.warn("EventFoundry: Rejected postMessage from untrusted origin:",t.origin);return}t.data.type==="ENTER_EDIT_MODE"&&(console.log("\u2190 ENTER_EDIT_MODE received"),G())}),setTimeout(()=>{window.parent&&(window.parent.postMessage({type:"IFRAME_READY",timestamp:Date.now()},"*"),console.log("\u2192 IFRAME_READY sent to parent"))},100))}function G(){L()}var S=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",P=S?"http://localhost/api/tracking/events":"https://eventfoundry.app/api/tracking/events",p="eventfoundry_definitions",$=3600*1e3;function H(){let t=document.currentScript||document.querySelector("script[data-site-key]");if(!t)return console.error("EventFoundry: Could not find script tag"),null;let n=t.getAttribute("data-dev-mode"),e=n==="false"?!1:S||n==="true";return{siteKey:t.getAttribute("data-site-key"),measurementId:t.getAttribute("data-measurement-id"),devMode:e}}function j(t){return l(this,null,function*(){if(window.gtag&&typeof window.gtag=="function")return{hasGtag:!0,wasInjected:!1};if(!t)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=${t}`,document.head.appendChild(n),window.dataLayer=window.dataLayer||[];function e(){dataLayer.push(arguments)}return window.gtag=e,e("js",new Date),e("config",t),yield new Promise(o=>{n.onload=o,setTimeout(o,5e3)}),{hasGtag:!0,wasInjected:!0}})}function N(){return l(this,null,function*(){let t=H();if(!t||!t.siteKey){console.error("EventFoundry: No site key provided");return}let{siteKey:n,measurementId:e,devMode:o}=t;console.log("\u2713 EventFoundry tracker loaded"),h()&&C();let{hasGtag:a,wasInjected:i}=yield j(e);if(!a){console.error("EventFoundry: Cannot track events without GA4");return}console.log(i?"\u2713 GA4 injected successfully":"\u2713 GA4 detected"),console.log(o?"\u26A0 Dev mode: Events disabled":"\u2713 Production mode: Events enabled");try{let r=yield R(n),s=r.events||r;A(s,o)}catch(r){console.error("EventFoundry: Failed to initialize:",r)}})}function R(t){return l(this,null,function*(){let n=q();if(n)return n;let e=yield fetch(`${P}?siteKey=${t}`);if(!e.ok)throw new Error(`API returned ${e.status}`);let o=yield e.json();return K(o),o})}function q(){try{let t=localStorage.getItem(p);if(!t)return null;let{data:n,timestamp:e}=JSON.parse(t);return Date.now()-e>$?(localStorage.removeItem(p),null):n}catch(t){return console.warn("EventFoundry: Cache read failed:",t),null}}function K(t){try{let n={data:t,timestamp:Date.now()};localStorage.setItem(p,JSON.stringify(n))}catch(n){console.warn("EventFoundry: Cache write failed:",n)}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",N):N();})();
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kylelogue/eventfoundry-tracker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "EventFoundry tracking script for custom GA4 event tracking",
|
|
5
5
|
"main": "dist/tracker.min.js",
|
|
6
|
-
"files": [
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
7
9
|
"scripts": {
|
|
8
10
|
"build": "node build.js",
|
|
9
11
|
"dev": "node build.js --watch",
|
|
10
12
|
"test": "echo \"No tests yet\"",
|
|
11
|
-
"serve": "./serve-test.sh",
|
|
12
13
|
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
@@ -19,7 +20,13 @@
|
|
|
19
20
|
"bugs": {
|
|
20
21
|
"url": "https://github.com/kylelogue/eventfoundry-tracker/issues"
|
|
21
22
|
},
|
|
22
|
-
"keywords": [
|
|
23
|
+
"keywords": [
|
|
24
|
+
"analytics",
|
|
25
|
+
"ga4",
|
|
26
|
+
"tracking",
|
|
27
|
+
"google-analytics",
|
|
28
|
+
"eventfoundry"
|
|
29
|
+
],
|
|
23
30
|
"author": "Kyle Logue",
|
|
24
31
|
"license": "MIT",
|
|
25
32
|
"devDependencies": {
|