@kylelogue/eventfoundry-tracker 0.1.0 → 0.3.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 +1 -1
- package/package.json +13 -5
package/dist/tracker.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var EventFoundry=(()=>{var
|
|
1
|
+
var EventFoundry=(()=>{var y=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var F=(e,n,t)=>n in e?y(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,I=(e,n)=>{for(var t in n||(n={}))A.call(n,t)&&F(e,t,n[t]);if(b)for(var t of b(n))$.call(n,t)&&F(e,t,n[t]);return e};var j=(e,n)=>{for(var t in n)y(e,t,{get:n[t],enumerable:!0})},H=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of G(n))!A.call(e,r)&&r!==t&&y(e,r,{get:()=>n[r],enumerable:!(o=R(n,r))||o.enumerable});return e};var V=e=>H(y({},"__esModule",{value:!0}),e);var f=(e,n,t)=>new Promise((o,r)=>{var s=c=>{try{i(t.next(c))}catch(l){r(l)}},a=c=>{try{i(t.throw(c))}catch(l){r(l)}},i=c=>c.done?o(c.value):Promise.resolve(c.value).then(s,a);i((t=t.apply(e,n)).next())});var re={};j(re,{reloadEventDefinitions:()=>L});var d=null,g=!1,v=null,u=!1;function C(){return g}function h(){return u}function W(){return["http://localhost","https://eventfoundry.app"]}function K(e){return W().includes(e)}function M(){if(g)return;g=!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),v=n,document.body.classList.add("eventfoundry-edit-mode"),document.body.addEventListener("mouseover",t=>{u||t.target.classList.contains("eventfoundry-overlay")||(d&&d.classList.remove("eventfoundry-highlight"),t.target.classList.add("eventfoundry-highlight"),d=t.target)},!0),document.body.addEventListener("mouseout",t=>{u||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")||u)return;t.preventDefault(),t.stopPropagation();let o=t.target,r="";o.className&&typeof o.className=="string"&&(r=o.className.trim().split(/\s+/).filter(i=>!i.startsWith("eventfoundry-")).join(" "));let s=window.location.pathname+window.location.search+window.location.hash,a={tagName:o.tagName.toLowerCase(),text:o.textContent.trim().substring(0,50),id:o.id,className:r,selector:B(o),page_path:s};window.parent.postMessage({type:"ELEMENT_SELECTED",element:a},"*")},!0),window.addEventListener("message",t=>{if(K(t.origin)&&(t.data.type==="HIGHLIGHT_SELECTOR"&&U(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}window.parent.postMessage({type:"MATCH_COUNT_RESULT",selector:o,count:r},"*")}})}function m(e){return e?e.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g,"\\$1"):""}function q(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 p(e,n){try{let t=document.querySelectorAll(n);return t.length===1&&t[0]===e}catch(t){return!1}}function B(e){let n=[];if(e.id&&!q(e.id)){let a=`#${m(e.id)}`;p(e,a)&&n.push({selector:a,priority:100})}let t=Array.from(e.attributes).filter(a=>a.name.startsWith("data-")&&a.value);for(let a of t){let i=`[${a.name}="${m(a.value)}"]`;if(p(e,i)){n.push({selector:i,priority:90});break}}if(e.className&&typeof e.className=="string"){let a=e.className.trim().split(/\s+/).filter(i=>!i.startsWith("eventfoundry-"));for(let i of a){let c=`.${m(i)}`;if(p(e,c)){n.push({selector:c,priority:80});break}}}let o=e.tagName.toLowerCase();e instanceof SVGElement&&(o=e.tagName.toLowerCase());let r=o,s=e.parentElement;if(s){let a;if(s.className&&typeof s.className=="string"){let l=s.className.trim().split(/\s+/).filter(x=>!x.startsWith("eventfoundry-"));a=l.length>0?`.${m(l[0])}`:s.tagName.toLowerCase()}else a=s.tagName.toLowerCase();let c=Array.from(s.children).indexOf(e)+1;r=`${a} ${o}:nth-child(${c})`}return p(e,r)&&n.push({selector:r,priority:50}),n.length>0?(n.sort((a,i)=>i.priority-a.priority),n[0].selector):o}function U(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){}}function P(){g&&(u=!0,v&&(v.style.display="none"),document.body.classList.remove("eventfoundry-edit-mode"),d&&(d.classList.remove("eventfoundry-highlight"),d=null))}function D(){g&&(u=!1,v&&(v.style.display=""),document.body.classList.add("eventfoundry-edit-mode"))}function E(e,n=!1){!e||e.length===0||document.addEventListener("click",t=>{if(C()&&!h())return;let o=e.filter(a=>{try{return t.target.closest(a.selector)!==null}catch(i){return!1}});if(o.length===0)return;let r=o[0],s=I({event_category:"EventFoundry",event_label:r.name,transport_type:"beacon"},r.gaEventParams);if(n||window.gtag("event",r.gaEventName,s),h())try{window.parent.postMessage({type:"EVENT_FIRED",timestamp:Date.now(),eventName:r.name,gaEventName:r.gaEventName,selector:r.selector,params:s,pagePath:window.location.pathname},"*")}catch(a){}o.length>1},!0)}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 w(){try{return window.self!==window.top}catch(e){return!0}}function T(){w()&&(window.addEventListener("message",e=>{if(J(e.origin))switch(e.data.type){case"ENTER_EDIT_MODE":Y();break;case"ENABLE_PREVIEW":Q();break;case"DISABLE_PREVIEW":X();break;case"RELOAD_CONFIG":L();break}}),setTimeout(()=>{window.parent&&window.parent.postMessage({type:"IFRAME_READY"},"*")},100))}function Y(){M()}function Q(){P()}function X(){D()}var _=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",Z=_?"http://localhost/api/tracking/events":"https://eventfoundry.app/api/tracking/events",ee=3600*1e3;function N(e){return`eventfoundry_definitions_${e}`}function k(){let e=document.currentScript||document.querySelector("script[data-site-key]");if(!e)return null;let n=e.getAttribute("data-dev-mode"),t=n==="false"?!1:_||n==="true";return{siteKey:e.getAttribute("data-site-key"),measurementId:e.getAttribute("data-measurement-id"),devMode:t}}function te(e){return f(this,null,function*(){if(window.gtag&&typeof window.gtag=="function")return{hasGtag:!0,wasInjected:!1};if(!e)return{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 S(){return f(this,null,function*(){let e=k();if(!e||!e.siteKey)return;let{siteKey:n,measurementId:t,devMode:o}=e;w()&&T();let{hasGtag:r,wasInjected:s}=yield te(t);if(r)try{let i=(yield O(n)).events;E(i,o)}catch(a){}})}function O(e){return f(this,null,function*(){let n=ne(e);if(n)return n;let t=yield fetch(`${Z}?siteKey=${e}`);if(!t.ok)throw new Error(`API returned ${t.status}`);let o=yield t.json();return oe(e,o),o})}function ne(e){try{let n=N(e),t=localStorage.getItem(n);if(!t)return null;let{data:o,timestamp:r}=JSON.parse(t);return Date.now()-r>ee?(localStorage.removeItem(n),null):o}catch(n){return null}}function oe(e,n){try{let t=N(e),o={data:n,timestamp:Date.now()};localStorage.setItem(t,JSON.stringify(o))}catch(t){}}function L(){return f(this,null,function*(){let e=k();if(!e||!e.siteKey)return;let{siteKey:n,devMode:t}=e;try{let o=N(n);localStorage.removeItem(o)}catch(o){}try{let r=(yield O(n)).events;E(r,t)}catch(o){}})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",S):S();return V(re);})();
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kylelogue/eventfoundry-tracker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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,10 +20,17 @@
|
|
|
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": {
|
|
26
|
-
"esbuild": "^0.27.0"
|
|
33
|
+
"esbuild": "^0.27.0",
|
|
34
|
+
"esbuild-minify-templates": "^0.13.1"
|
|
27
35
|
}
|
|
28
36
|
}
|