@li2/analytics 0.3.1-beta.0 → 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
- "use strict";var li2Analytics=(()=>{var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},k=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!E.call(n,s)&&s!==t&&u(n,s,{get:()=>e[s],enumerable:!(i=v(e,s))||i.enumerable});return n};var C=n=>k(u({},"__esModule",{value:!0}),n);var U={};I(U,{ClickTracker:()=>g,DEFAULT_CLICK_TRACKER_CONFIG:()=>H});var a="li2_vid",d="li2_sid",f="li2_la",c=class{constructor(e){this.config=e,this.visitorId=this.resolveVisitorId(),this.sessionId=this.resolveSessionId()}getVisitorId(){return this.visitorId}getSessionId(){return this.isSessionExpired()&&this.createNewSession(),this.sessionId}touch(){let e=Date.now();this.setStorage(f,e.toString(),"session")}createNewSession(){this.sessionId=this.generateId("sess"),this.setStorage(d,this.sessionId,"session"),this.touch()}resolveVisitorId(){let e=this.getStorage(a,"local");return!e&&!this.config.cookieLessMode&&(e=this.getCookie(a)),e||(e=this.generateId("vis")),this.setStorage(a,e,"local"),this.config.cookieLessMode||this.setCookie(a,e,365),e}resolveSessionId(){let e=this.getStorage(d,"session");return(!e||this.isSessionExpired())&&(e=this.generateId("sess"),this.setStorage(d,e,"session"),this.touch()),e}isSessionExpired(){let e=this.getStorage(f,"session");if(!e)return!0;let t=Date.now()-parseInt(e,10),i=this.config.timeout*60*1e3;return t>i}generateId(e){if(typeof crypto<"u"&&crypto.randomUUID)return`${e}_${crypto.randomUUID().replace(/-/g,"").slice(0,16)}`;let t=Array.from({length:16},()=>Math.floor(Math.random()*16).toString(16)).join("");return`${e}_${t}`}getStorage(e,t){try{return(t==="local"?localStorage:sessionStorage).getItem(e)}catch{return null}}setStorage(e,t,i){try{(i==="local"?localStorage:sessionStorage).setItem(e,t)}catch{}}getCookie(e){let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}setCookie(e,t,i){let s=[`${e}=${encodeURIComponent(t)}`,`path=${this.config.cookiePath}`,`max-age=${i*86400}`,"SameSite=Lax"];this.config.cookieDomain&&s.push(`domain=${this.config.cookieDomain}`),window.location.protocol==="https:"&&s.push("Secure"),document.cookie=s.join("; ")}};var y=new Set(["a","button","input","select","textarea","form","label"]),_=new Set(["button","link","tab","menuitem"]);function p(n){let e=n;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let i=w(e),s=x(i);return{tag:i.tagName.toLowerCase(),text:m(L(i),256),href:M(i),className:m(i.className||"",512),id:i.id||null,selectorPath:T(i),isFixed:s}}function w(n){let e=n,t=0;for(;e&&t<5&&e.tagName!=="BODY";){let i=e.tagName.toLowerCase(),s=e.getAttribute("role");if(y.has(i)||s&&_.has(s))return e;e=e.parentElement,t++}return n}function x(n){let e=n;for(;e&&e!==document.body;){try{let i=window.getComputedStyle(e).getPropertyValue("position");if(i==="fixed"||i==="sticky")return!0}catch{break}e=e.parentElement}return!1}function T(n){let e=[],t=n,i=0;for(;t&&t!==document.body&&i<5;){let s=t.tagName.toLowerCase();t.id&&(s+=`#${t.id}`);let o=t.parentElement;if(o){let r=Array.from(o.children).filter(l=>l.tagName===t.tagName);if(r.length>1){let l=r.indexOf(t)+1;s+=`:nth-of-type(${l})`}}e.unshift(s),t=t.parentElement,i++}return e.join(" > ")}function L(n){return n instanceof HTMLInputElement?n.value||n.placeholder||"":(n.innerText||n.textContent||"").trim()}function M(n){return n instanceof HTMLAnchorElement?n.href||null:n.getAttribute("href")||null}function m(n,e){return n.length<=e?n:n.slice(0,e)}function b(n,e){let t=window.scrollX||document.documentElement.scrollLeft,i=window.scrollY||document.documentElement.scrollTop;return{x:n.clientX+(e?0:t),y:n.clientY+(e?0:i),scrollY:i,pageHeight:document.documentElement.scrollHeight}}var h=class{constructor(e){this.buffer=[];this.timer=null;this.started=!1;this.handleBeforeUnload=null;this.handleVisibilityChange=null;this.config=e}start(){this.started||(this.started=!0,this.timer=setInterval(()=>this.flush(),this.config.batchInterval),this.handleBeforeUnload=()=>this.flush(!0),window.addEventListener("beforeunload",this.handleBeforeUnload),this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this.flush(!0)},document.addEventListener("visibilitychange",this.handleVisibilityChange))}stop(){this.started&&(this.started=!1,this.flush(!0),this.timer&&(clearInterval(this.timer),this.timer=null),this.handleBeforeUnload&&(window.removeEventListener("beforeunload",this.handleBeforeUnload),this.handleBeforeUnload=null),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.handleVisibilityChange=null))}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush()}getBufferSize(){return this.buffer.length}flush(e=!1){if(this.buffer.length===0)return;let t=this.buffer.splice(0,this.config.batchSize),i={interactions:t},s=`${this.config.apiUrl}/api/v1/track/interaction`,o=JSON.stringify(i);if(e&&navigator.sendBeacon){let r=new Blob([o],{type:"application/json"});navigator.sendBeacon(s,r)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(s,o,t)}else this.sendViaFetch(s,o,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,i){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(s=>{s.ok?this.log(`Sent: ${i.length} interactions`):(this.log(`Send failed: ${s.status}, re-queuing ${i.length} events`),this.buffer.unshift(...i))}).catch(()=>{this.log(`Network error, re-queuing ${i.length} events`),this.buffer.unshift(...i)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var H={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},N=50,g=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new c({timeout:e.sessionTimeout,cookieLessMode:e.cookieLessMode,cookieDomain:e.cookieDomain,cookiePath:e.cookiePath}),this.batchSender=new h({apiUrl:e.apiUrl,publishableKey:e.publishableKey,batchInterval:e.batchInterval,batchSize:e.batchSize,debug:e.debug})}start(){this.started||(this.started=!0,this.handleClick=e=>this.onDocumentClick(e),document.addEventListener("click",this.handleClick,!0),this.batchSender.start(),this.log("ClickTracker started"))}stop(){this.started&&(this.started=!1,this.handleClick&&(document.removeEventListener("click",this.handleClick,!0),this.handleClick=null),this.batchSender.stop(),this.log("ClickTracker stopped"))}onDocumentClick(e){if(e.button!==0)return;let t=Date.now();if(e.target===this.lastClickTarget&&t-this.lastClickTime<N||(this.lastClickTarget=e.target,this.lastClickTime=t,this.shouldExclude(e.target)))return;let i=p(e.target);if(!i)return;let s=b(e,i.isFixed),o={session_id:this.sessionManager.getSessionId(),visitor_id:this.sessionManager.getVisitorId(),li2_cid:this.config.clickId,page_url:window.location.href,page_path:window.location.pathname,x:s.x,y:s.y,target_fixed:i.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:s.pageHeight,scroll_y:s.scrollY,element_tag:i.tag,element_text:i.text,element_href:i.href,element_class:i.className,element_id:i.id,selector_path:i.selectorPath,interaction_type:"click",timestamp:t};this.sessionManager.touch(),this.batchSender.add(o)}shouldExclude(e){if(!this.config.excludeSelector||!e)return!1;let t=e;for(;t&&t!==document.body;){try{if(t.matches(this.config.excludeSelector))return!0}catch{return this.log(`Invalid excludeSelector: ${this.config.excludeSelector}`),this.config.excludeSelector=null,!1}t=t.parentElement}return!1}log(...e){this.config.debug&&console.log("[Li2 ClickTracker]",...e)}};return C(U);})();
1
+ "use strict";var li2Analytics=(()=>{var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},k=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!E.call(n,s)&&s!==t&&u(n,s,{get:()=>e[s],enumerable:!(i=v(e,s))||i.enumerable});return n};var C=n=>k(u({},"__esModule",{value:!0}),n);var N={};I(N,{ClickTracker:()=>g,DEFAULT_CLICK_TRACKER_CONFIG:()=>U});var a="li2_vid",d="li2_sid",f="li2_la",c=class{constructor(e){this.config=e,this.visitorId=this.resolveVisitorId(),this.sessionId=this.resolveSessionId()}getVisitorId(){return this.visitorId}getSessionId(){return this.isSessionExpired()&&this.createNewSession(),this.sessionId}touch(){let e=Date.now();this.setStorage(f,e.toString(),"session")}createNewSession(){this.sessionId=this.generateId("sess"),this.setStorage(d,this.sessionId,"session"),this.touch()}resolveVisitorId(){let e=this.getStorage(a,"local");return!e&&!this.config.cookieLessMode&&(e=this.getCookie(a)),e||(e=this.generateId("vis")),this.setStorage(a,e,"local"),this.config.cookieLessMode||this.setCookie(a,e,365),e}resolveSessionId(){let e=this.getStorage(d,"session");return(!e||this.isSessionExpired())&&(e=this.generateId("sess"),this.setStorage(d,e,"session"),this.touch()),e}isSessionExpired(){let e=this.getStorage(f,"session");if(!e)return!0;let t=Date.now()-parseInt(e,10),i=this.config.timeout*60*1e3;return t>i}generateId(e){if(typeof crypto<"u"&&crypto.randomUUID)return`${e}_${crypto.randomUUID().replace(/-/g,"").slice(0,16)}`;let t=Array.from({length:16},()=>Math.floor(Math.random()*16).toString(16)).join("");return`${e}_${t}`}getStorage(e,t){try{return(t==="local"?localStorage:sessionStorage).getItem(e)}catch{return null}}setStorage(e,t,i){try{(i==="local"?localStorage:sessionStorage).setItem(e,t)}catch{}}getCookie(e){let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}setCookie(e,t,i){let s=[`${e}=${encodeURIComponent(t)}`,`path=${this.config.cookiePath}`,`max-age=${i*86400}`,"SameSite=Lax"];this.config.cookieDomain&&s.push(`domain=${this.config.cookieDomain}`),window.location.protocol==="https:"&&s.push("Secure"),document.cookie=s.join("; ")}};var y=new Set(["a","button","input","select","textarea","form","label"]),_=new Set(["button","link","tab","menuitem"]);function p(n){let e=n;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let i=w(e),s=x(i);return{tag:i.tagName.toLowerCase(),text:m(L(i),256),href:M(i),className:m(i.className||"",512),id:i.id||null,selectorPath:T(i),isFixed:s}}function w(n){let e=n,t=0;for(;e&&t<5&&e.tagName!=="BODY";){let i=e.tagName.toLowerCase(),s=e.getAttribute("role");if(y.has(i)||s&&_.has(s))return e;e=e.parentElement,t++}return n}function x(n){let e=n;for(;e&&e!==document.body;){try{let i=window.getComputedStyle(e).getPropertyValue("position");if(i==="fixed"||i==="sticky")return!0}catch{break}e=e.parentElement}return!1}function T(n){let e=[],t=n,i=0;for(;t&&t!==document.body&&i<5;){let s=t.tagName.toLowerCase();t.id&&(s+=`#${t.id}`);let o=t.parentElement;if(o){let l=Array.from(o.children).filter(r=>r.tagName===t.tagName);if(l.length>1){let r=l.indexOf(t)+1;s+=`:nth-of-type(${r})`}}e.unshift(s),t=t.parentElement,i++}return e.join(" > ")}function L(n){return n instanceof HTMLInputElement?n.value||n.placeholder||"":(n.innerText||n.textContent||"").trim()}function M(n){return n instanceof HTMLAnchorElement?n.href||null:n.getAttribute("href")||null}function m(n,e){return n.length<=e?n:n.slice(0,e)}function b(n,e){let t=window.scrollX||document.documentElement.scrollLeft,i=window.scrollY||document.documentElement.scrollTop;return{x:n.clientX+(e?0:t),y:n.clientY+(e?0:i),scrollY:i,pageHeight:document.documentElement.scrollHeight}}var h=class{constructor(e){this.buffer=[];this.timer=null;this.started=!1;this.handleBeforeUnload=null;this.handleVisibilityChange=null;this.config=e}start(){this.started||(this.started=!0,this.timer=setInterval(()=>this.flush(),this.config.batchInterval),this.handleBeforeUnload=()=>this.flush(!0),window.addEventListener("beforeunload",this.handleBeforeUnload),this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this.flush(!0)},document.addEventListener("visibilitychange",this.handleVisibilityChange))}stop(){this.started&&(this.started=!1,this.flush(!0),this.timer&&(clearInterval(this.timer),this.timer=null),this.handleBeforeUnload&&(window.removeEventListener("beforeunload",this.handleBeforeUnload),this.handleBeforeUnload=null),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.handleVisibilityChange=null))}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush()}getBufferSize(){return this.buffer.length}flush(e=!1){if(this.buffer.length===0)return;let t=this.buffer.splice(0,this.config.batchSize),i={interactions:t},s=`${this.config.apiUrl}/api/v1/track/interaction`,o=JSON.stringify(i);if(e&&navigator.sendBeacon){let l=`${s}?li2_key=${encodeURIComponent(this.config.publishableKey)}`,r=new Blob([o],{type:"application/json"});navigator.sendBeacon(l,r)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(s,o,t)}else this.sendViaFetch(s,o,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,i){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(s=>{s.ok?this.log(`Sent: ${i.length} interactions`):(this.log(`Send failed: ${s.status}, re-queuing ${i.length} events`),this.buffer.unshift(...i))}).catch(()=>{this.log(`Network error, re-queuing ${i.length} events`),this.buffer.unshift(...i)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var U={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},H=50,g=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new c({timeout:e.sessionTimeout,cookieLessMode:e.cookieLessMode,cookieDomain:e.cookieDomain,cookiePath:e.cookiePath}),this.batchSender=new h({apiUrl:e.apiUrl,publishableKey:e.publishableKey,batchInterval:e.batchInterval,batchSize:e.batchSize,debug:e.debug})}start(){this.started||(this.started=!0,this.handleClick=e=>this.onDocumentClick(e),document.addEventListener("click",this.handleClick,!0),this.batchSender.start(),this.log("ClickTracker started"))}stop(){this.started&&(this.started=!1,this.handleClick&&(document.removeEventListener("click",this.handleClick,!0),this.handleClick=null),this.batchSender.stop(),this.log("ClickTracker stopped"))}onDocumentClick(e){if(e.button!==0)return;let t=Date.now();if(e.target===this.lastClickTarget&&t-this.lastClickTime<H||(this.lastClickTarget=e.target,this.lastClickTime=t,this.shouldExclude(e.target)))return;let i=p(e.target);if(!i)return;let s=b(e,i.isFixed),o={session_id:this.sessionManager.getSessionId(),visitor_id:this.sessionManager.getVisitorId(),li2_cid:this.config.clickId,page_url:window.location.href,page_path:window.location.pathname,x:s.x,y:s.y,target_fixed:i.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:s.pageHeight,scroll_y:s.scrollY,element_tag:i.tag,element_text:i.text,element_href:i.href,element_class:i.className,element_id:i.id,selector_path:i.selectorPath,interaction_type:"click",timestamp:t};this.sessionManager.touch(),this.batchSender.add(o)}shouldExclude(e){if(!this.config.excludeSelector||!e)return!1;let t=e;for(;t&&t!==document.body;){try{if(t.matches(this.config.excludeSelector))return!0}catch{return this.log(`Invalid excludeSelector: ${this.config.excludeSelector}`),this.config.excludeSelector=null,!1}t=t.parentElement}return!1}log(...e){this.config.debug&&console.log("[Li2 ClickTracker]",...e)}};return C(N);})();
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},k=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!E.call(n,s)&&s!==t&&u(n,s,{get:()=>e[s],enumerable:!(i=v(e,s))||i.enumerable});return n};var C=n=>k(u({},"__esModule",{value:!0}),n);var U={};I(U,{ClickTracker:()=>g,DEFAULT_CLICK_TRACKER_CONFIG:()=>H});module.exports=C(U);var a="li2_vid",d="li2_sid",f="li2_la",c=class{constructor(e){this.config=e,this.visitorId=this.resolveVisitorId(),this.sessionId=this.resolveSessionId()}getVisitorId(){return this.visitorId}getSessionId(){return this.isSessionExpired()&&this.createNewSession(),this.sessionId}touch(){let e=Date.now();this.setStorage(f,e.toString(),"session")}createNewSession(){this.sessionId=this.generateId("sess"),this.setStorage(d,this.sessionId,"session"),this.touch()}resolveVisitorId(){let e=this.getStorage(a,"local");return!e&&!this.config.cookieLessMode&&(e=this.getCookie(a)),e||(e=this.generateId("vis")),this.setStorage(a,e,"local"),this.config.cookieLessMode||this.setCookie(a,e,365),e}resolveSessionId(){let e=this.getStorage(d,"session");return(!e||this.isSessionExpired())&&(e=this.generateId("sess"),this.setStorage(d,e,"session"),this.touch()),e}isSessionExpired(){let e=this.getStorage(f,"session");if(!e)return!0;let t=Date.now()-parseInt(e,10),i=this.config.timeout*60*1e3;return t>i}generateId(e){if(typeof crypto<"u"&&crypto.randomUUID)return`${e}_${crypto.randomUUID().replace(/-/g,"").slice(0,16)}`;let t=Array.from({length:16},()=>Math.floor(Math.random()*16).toString(16)).join("");return`${e}_${t}`}getStorage(e,t){try{return(t==="local"?localStorage:sessionStorage).getItem(e)}catch{return null}}setStorage(e,t,i){try{(i==="local"?localStorage:sessionStorage).setItem(e,t)}catch{}}getCookie(e){let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}setCookie(e,t,i){let s=[`${e}=${encodeURIComponent(t)}`,`path=${this.config.cookiePath}`,`max-age=${i*86400}`,"SameSite=Lax"];this.config.cookieDomain&&s.push(`domain=${this.config.cookieDomain}`),window.location.protocol==="https:"&&s.push("Secure"),document.cookie=s.join("; ")}};var y=new Set(["a","button","input","select","textarea","form","label"]),_=new Set(["button","link","tab","menuitem"]);function p(n){let e=n;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let i=w(e),s=x(i);return{tag:i.tagName.toLowerCase(),text:m(L(i),256),href:M(i),className:m(i.className||"",512),id:i.id||null,selectorPath:T(i),isFixed:s}}function w(n){let e=n,t=0;for(;e&&t<5&&e.tagName!=="BODY";){let i=e.tagName.toLowerCase(),s=e.getAttribute("role");if(y.has(i)||s&&_.has(s))return e;e=e.parentElement,t++}return n}function x(n){let e=n;for(;e&&e!==document.body;){try{let i=window.getComputedStyle(e).getPropertyValue("position");if(i==="fixed"||i==="sticky")return!0}catch{break}e=e.parentElement}return!1}function T(n){let e=[],t=n,i=0;for(;t&&t!==document.body&&i<5;){let s=t.tagName.toLowerCase();t.id&&(s+=`#${t.id}`);let o=t.parentElement;if(o){let r=Array.from(o.children).filter(l=>l.tagName===t.tagName);if(r.length>1){let l=r.indexOf(t)+1;s+=`:nth-of-type(${l})`}}e.unshift(s),t=t.parentElement,i++}return e.join(" > ")}function L(n){return n instanceof HTMLInputElement?n.value||n.placeholder||"":(n.innerText||n.textContent||"").trim()}function M(n){return n instanceof HTMLAnchorElement?n.href||null:n.getAttribute("href")||null}function m(n,e){return n.length<=e?n:n.slice(0,e)}function b(n,e){let t=window.scrollX||document.documentElement.scrollLeft,i=window.scrollY||document.documentElement.scrollTop;return{x:n.clientX+(e?0:t),y:n.clientY+(e?0:i),scrollY:i,pageHeight:document.documentElement.scrollHeight}}var h=class{constructor(e){this.buffer=[];this.timer=null;this.started=!1;this.handleBeforeUnload=null;this.handleVisibilityChange=null;this.config=e}start(){this.started||(this.started=!0,this.timer=setInterval(()=>this.flush(),this.config.batchInterval),this.handleBeforeUnload=()=>this.flush(!0),window.addEventListener("beforeunload",this.handleBeforeUnload),this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this.flush(!0)},document.addEventListener("visibilitychange",this.handleVisibilityChange))}stop(){this.started&&(this.started=!1,this.flush(!0),this.timer&&(clearInterval(this.timer),this.timer=null),this.handleBeforeUnload&&(window.removeEventListener("beforeunload",this.handleBeforeUnload),this.handleBeforeUnload=null),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.handleVisibilityChange=null))}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush()}getBufferSize(){return this.buffer.length}flush(e=!1){if(this.buffer.length===0)return;let t=this.buffer.splice(0,this.config.batchSize),i={interactions:t},s=`${this.config.apiUrl}/api/v1/track/interaction`,o=JSON.stringify(i);if(e&&navigator.sendBeacon){let r=new Blob([o],{type:"application/json"});navigator.sendBeacon(s,r)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(s,o,t)}else this.sendViaFetch(s,o,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,i){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(s=>{s.ok?this.log(`Sent: ${i.length} interactions`):(this.log(`Send failed: ${s.status}, re-queuing ${i.length} events`),this.buffer.unshift(...i))}).catch(()=>{this.log(`Network error, re-queuing ${i.length} events`),this.buffer.unshift(...i)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var H={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},N=50,g=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new c({timeout:e.sessionTimeout,cookieLessMode:e.cookieLessMode,cookieDomain:e.cookieDomain,cookiePath:e.cookiePath}),this.batchSender=new h({apiUrl:e.apiUrl,publishableKey:e.publishableKey,batchInterval:e.batchInterval,batchSize:e.batchSize,debug:e.debug})}start(){this.started||(this.started=!0,this.handleClick=e=>this.onDocumentClick(e),document.addEventListener("click",this.handleClick,!0),this.batchSender.start(),this.log("ClickTracker started"))}stop(){this.started&&(this.started=!1,this.handleClick&&(document.removeEventListener("click",this.handleClick,!0),this.handleClick=null),this.batchSender.stop(),this.log("ClickTracker stopped"))}onDocumentClick(e){if(e.button!==0)return;let t=Date.now();if(e.target===this.lastClickTarget&&t-this.lastClickTime<N||(this.lastClickTarget=e.target,this.lastClickTime=t,this.shouldExclude(e.target)))return;let i=p(e.target);if(!i)return;let s=b(e,i.isFixed),o={session_id:this.sessionManager.getSessionId(),visitor_id:this.sessionManager.getVisitorId(),li2_cid:this.config.clickId,page_url:window.location.href,page_path:window.location.pathname,x:s.x,y:s.y,target_fixed:i.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:s.pageHeight,scroll_y:s.scrollY,element_tag:i.tag,element_text:i.text,element_href:i.href,element_class:i.className,element_id:i.id,selector_path:i.selectorPath,interaction_type:"click",timestamp:t};this.sessionManager.touch(),this.batchSender.add(o)}shouldExclude(e){if(!this.config.excludeSelector||!e)return!1;let t=e;for(;t&&t!==document.body;){try{if(t.matches(this.config.excludeSelector))return!0}catch{return this.log(`Invalid excludeSelector: ${this.config.excludeSelector}`),this.config.excludeSelector=null,!1}t=t.parentElement}return!1}log(...e){this.config.debug&&console.log("[Li2 ClickTracker]",...e)}};0&&(module.exports={ClickTracker,DEFAULT_CLICK_TRACKER_CONFIG});
1
+ "use strict";var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},k=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!E.call(n,s)&&s!==t&&u(n,s,{get:()=>e[s],enumerable:!(i=v(e,s))||i.enumerable});return n};var C=n=>k(u({},"__esModule",{value:!0}),n);var N={};I(N,{ClickTracker:()=>g,DEFAULT_CLICK_TRACKER_CONFIG:()=>U});module.exports=C(N);var a="li2_vid",d="li2_sid",f="li2_la",c=class{constructor(e){this.config=e,this.visitorId=this.resolveVisitorId(),this.sessionId=this.resolveSessionId()}getVisitorId(){return this.visitorId}getSessionId(){return this.isSessionExpired()&&this.createNewSession(),this.sessionId}touch(){let e=Date.now();this.setStorage(f,e.toString(),"session")}createNewSession(){this.sessionId=this.generateId("sess"),this.setStorage(d,this.sessionId,"session"),this.touch()}resolveVisitorId(){let e=this.getStorage(a,"local");return!e&&!this.config.cookieLessMode&&(e=this.getCookie(a)),e||(e=this.generateId("vis")),this.setStorage(a,e,"local"),this.config.cookieLessMode||this.setCookie(a,e,365),e}resolveSessionId(){let e=this.getStorage(d,"session");return(!e||this.isSessionExpired())&&(e=this.generateId("sess"),this.setStorage(d,e,"session"),this.touch()),e}isSessionExpired(){let e=this.getStorage(f,"session");if(!e)return!0;let t=Date.now()-parseInt(e,10),i=this.config.timeout*60*1e3;return t>i}generateId(e){if(typeof crypto<"u"&&crypto.randomUUID)return`${e}_${crypto.randomUUID().replace(/-/g,"").slice(0,16)}`;let t=Array.from({length:16},()=>Math.floor(Math.random()*16).toString(16)).join("");return`${e}_${t}`}getStorage(e,t){try{return(t==="local"?localStorage:sessionStorage).getItem(e)}catch{return null}}setStorage(e,t,i){try{(i==="local"?localStorage:sessionStorage).setItem(e,t)}catch{}}getCookie(e){let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}setCookie(e,t,i){let s=[`${e}=${encodeURIComponent(t)}`,`path=${this.config.cookiePath}`,`max-age=${i*86400}`,"SameSite=Lax"];this.config.cookieDomain&&s.push(`domain=${this.config.cookieDomain}`),window.location.protocol==="https:"&&s.push("Secure"),document.cookie=s.join("; ")}};var y=new Set(["a","button","input","select","textarea","form","label"]),_=new Set(["button","link","tab","menuitem"]);function p(n){let e=n;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let i=w(e),s=x(i);return{tag:i.tagName.toLowerCase(),text:m(L(i),256),href:M(i),className:m(i.className||"",512),id:i.id||null,selectorPath:T(i),isFixed:s}}function w(n){let e=n,t=0;for(;e&&t<5&&e.tagName!=="BODY";){let i=e.tagName.toLowerCase(),s=e.getAttribute("role");if(y.has(i)||s&&_.has(s))return e;e=e.parentElement,t++}return n}function x(n){let e=n;for(;e&&e!==document.body;){try{let i=window.getComputedStyle(e).getPropertyValue("position");if(i==="fixed"||i==="sticky")return!0}catch{break}e=e.parentElement}return!1}function T(n){let e=[],t=n,i=0;for(;t&&t!==document.body&&i<5;){let s=t.tagName.toLowerCase();t.id&&(s+=`#${t.id}`);let o=t.parentElement;if(o){let l=Array.from(o.children).filter(r=>r.tagName===t.tagName);if(l.length>1){let r=l.indexOf(t)+1;s+=`:nth-of-type(${r})`}}e.unshift(s),t=t.parentElement,i++}return e.join(" > ")}function L(n){return n instanceof HTMLInputElement?n.value||n.placeholder||"":(n.innerText||n.textContent||"").trim()}function M(n){return n instanceof HTMLAnchorElement?n.href||null:n.getAttribute("href")||null}function m(n,e){return n.length<=e?n:n.slice(0,e)}function b(n,e){let t=window.scrollX||document.documentElement.scrollLeft,i=window.scrollY||document.documentElement.scrollTop;return{x:n.clientX+(e?0:t),y:n.clientY+(e?0:i),scrollY:i,pageHeight:document.documentElement.scrollHeight}}var h=class{constructor(e){this.buffer=[];this.timer=null;this.started=!1;this.handleBeforeUnload=null;this.handleVisibilityChange=null;this.config=e}start(){this.started||(this.started=!0,this.timer=setInterval(()=>this.flush(),this.config.batchInterval),this.handleBeforeUnload=()=>this.flush(!0),window.addEventListener("beforeunload",this.handleBeforeUnload),this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this.flush(!0)},document.addEventListener("visibilitychange",this.handleVisibilityChange))}stop(){this.started&&(this.started=!1,this.flush(!0),this.timer&&(clearInterval(this.timer),this.timer=null),this.handleBeforeUnload&&(window.removeEventListener("beforeunload",this.handleBeforeUnload),this.handleBeforeUnload=null),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.handleVisibilityChange=null))}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush()}getBufferSize(){return this.buffer.length}flush(e=!1){if(this.buffer.length===0)return;let t=this.buffer.splice(0,this.config.batchSize),i={interactions:t},s=`${this.config.apiUrl}/api/v1/track/interaction`,o=JSON.stringify(i);if(e&&navigator.sendBeacon){let l=`${s}?li2_key=${encodeURIComponent(this.config.publishableKey)}`,r=new Blob([o],{type:"application/json"});navigator.sendBeacon(l,r)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(s,o,t)}else this.sendViaFetch(s,o,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,i){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(s=>{s.ok?this.log(`Sent: ${i.length} interactions`):(this.log(`Send failed: ${s.status}, re-queuing ${i.length} events`),this.buffer.unshift(...i))}).catch(()=>{this.log(`Network error, re-queuing ${i.length} events`),this.buffer.unshift(...i)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var U={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},H=50,g=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new c({timeout:e.sessionTimeout,cookieLessMode:e.cookieLessMode,cookieDomain:e.cookieDomain,cookiePath:e.cookiePath}),this.batchSender=new h({apiUrl:e.apiUrl,publishableKey:e.publishableKey,batchInterval:e.batchInterval,batchSize:e.batchSize,debug:e.debug})}start(){this.started||(this.started=!0,this.handleClick=e=>this.onDocumentClick(e),document.addEventListener("click",this.handleClick,!0),this.batchSender.start(),this.log("ClickTracker started"))}stop(){this.started&&(this.started=!1,this.handleClick&&(document.removeEventListener("click",this.handleClick,!0),this.handleClick=null),this.batchSender.stop(),this.log("ClickTracker stopped"))}onDocumentClick(e){if(e.button!==0)return;let t=Date.now();if(e.target===this.lastClickTarget&&t-this.lastClickTime<H||(this.lastClickTarget=e.target,this.lastClickTime=t,this.shouldExclude(e.target)))return;let i=p(e.target);if(!i)return;let s=b(e,i.isFixed),o={session_id:this.sessionManager.getSessionId(),visitor_id:this.sessionManager.getVisitorId(),li2_cid:this.config.clickId,page_url:window.location.href,page_path:window.location.pathname,x:s.x,y:s.y,target_fixed:i.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:s.pageHeight,scroll_y:s.scrollY,element_tag:i.tag,element_text:i.text,element_href:i.href,element_class:i.className,element_id:i.id,selector_path:i.selectorPath,interaction_type:"click",timestamp:t};this.sessionManager.touch(),this.batchSender.add(o)}shouldExclude(e){if(!this.config.excludeSelector||!e)return!1;let t=e;for(;t&&t!==document.body;){try{if(t.matches(this.config.excludeSelector))return!0}catch{return this.log(`Invalid excludeSelector: ${this.config.excludeSelector}`),this.config.excludeSelector=null,!1}t=t.parentElement}return!1}log(...e){this.config.debug&&console.log("[Li2 ClickTracker]",...e)}};0&&(module.exports={ClickTracker,DEFAULT_CLICK_TRACKER_CONFIG});
@@ -1 +1 @@
1
- import{a as c}from"../chunk-LZDMBCUK.mjs";var f=new Set(["a","button","input","select","textarea","form","label"]),m=new Set(["button","link","tab","menuitem"]);function u(i){let e=i;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let t=p(e),r=b(t);return{tag:t.tagName.toLowerCase(),text:h(E(t),256),href:k(t),className:h(t.className||"",512),id:t.id||null,selectorPath:v(t),isFixed:r}}function p(i){let e=i,n=0;for(;e&&n<5&&e.tagName!=="BODY";){let t=e.tagName.toLowerCase(),r=e.getAttribute("role");if(f.has(t)||r&&m.has(r))return e;e=e.parentElement,n++}return i}function b(i){let e=i;for(;e&&e!==document.body;){try{let t=window.getComputedStyle(e).getPropertyValue("position");if(t==="fixed"||t==="sticky")return!0}catch{break}e=e.parentElement}return!1}function v(i){let e=[],n=i,t=0;for(;n&&n!==document.body&&t<5;){let r=n.tagName.toLowerCase();n.id&&(r+=`#${n.id}`);let l=n.parentElement;if(l){let s=Array.from(l.children).filter(o=>o.tagName===n.tagName);if(s.length>1){let o=s.indexOf(n)+1;r+=`:nth-of-type(${o})`}}e.unshift(r),n=n.parentElement,t++}return e.join(" > ")}function E(i){return i instanceof HTMLInputElement?i.value||i.placeholder||"":(i.innerText||i.textContent||"").trim()}function k(i){return i instanceof HTMLAnchorElement?i.href||null:i.getAttribute("href")||null}function h(i,e){return i.length<=e?i:i.slice(0,e)}function d(i,e){let n=window.scrollX||document.documentElement.scrollLeft,t=window.scrollY||document.documentElement.scrollTop;return{x:i.clientX+(e?0:n),y:i.clientY+(e?0:t),scrollY:t,pageHeight:document.documentElement.scrollHeight}}var a=class{constructor(e){this.buffer=[];this.timer=null;this.started=!1;this.handleBeforeUnload=null;this.handleVisibilityChange=null;this.config=e}start(){this.started||(this.started=!0,this.timer=setInterval(()=>this.flush(),this.config.batchInterval),this.handleBeforeUnload=()=>this.flush(!0),window.addEventListener("beforeunload",this.handleBeforeUnload),this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this.flush(!0)},document.addEventListener("visibilitychange",this.handleVisibilityChange))}stop(){this.started&&(this.started=!1,this.flush(!0),this.timer&&(clearInterval(this.timer),this.timer=null),this.handleBeforeUnload&&(window.removeEventListener("beforeunload",this.handleBeforeUnload),this.handleBeforeUnload=null),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.handleVisibilityChange=null))}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush()}getBufferSize(){return this.buffer.length}flush(e=!1){if(this.buffer.length===0)return;let n=this.buffer.splice(0,this.config.batchSize),t={interactions:n},r=`${this.config.apiUrl}/api/v1/track/interaction`,l=JSON.stringify(t);if(e&&navigator.sendBeacon){let s=new Blob([l],{type:"application/json"});navigator.sendBeacon(r,s)?this.log(`Beacon sent: ${n.length} interactions`):this.sendViaFetch(r,l,n)}else this.sendViaFetch(r,l,n);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,n,t){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:n,keepalive:!0}).then(r=>{r.ok?this.log(`Sent: ${t.length} interactions`):(this.log(`Send failed: ${r.status}, re-queuing ${t.length} events`),this.buffer.unshift(...t))}).catch(()=>{this.log(`Network error, re-queuing ${t.length} events`),this.buffer.unshift(...t)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var M={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},C=50,g=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new c({timeout:e.sessionTimeout,cookieLessMode:e.cookieLessMode,cookieDomain:e.cookieDomain,cookiePath:e.cookiePath}),this.batchSender=new a({apiUrl:e.apiUrl,publishableKey:e.publishableKey,batchInterval:e.batchInterval,batchSize:e.batchSize,debug:e.debug})}start(){this.started||(this.started=!0,this.handleClick=e=>this.onDocumentClick(e),document.addEventListener("click",this.handleClick,!0),this.batchSender.start(),this.log("ClickTracker started"))}stop(){this.started&&(this.started=!1,this.handleClick&&(document.removeEventListener("click",this.handleClick,!0),this.handleClick=null),this.batchSender.stop(),this.log("ClickTracker stopped"))}onDocumentClick(e){if(e.button!==0)return;let n=Date.now();if(e.target===this.lastClickTarget&&n-this.lastClickTime<C||(this.lastClickTarget=e.target,this.lastClickTime=n,this.shouldExclude(e.target)))return;let t=u(e.target);if(!t)return;let r=d(e,t.isFixed),l={session_id:this.sessionManager.getSessionId(),visitor_id:this.sessionManager.getVisitorId(),li2_cid:this.config.clickId,page_url:window.location.href,page_path:window.location.pathname,x:r.x,y:r.y,target_fixed:t.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:r.pageHeight,scroll_y:r.scrollY,element_tag:t.tag,element_text:t.text,element_href:t.href,element_class:t.className,element_id:t.id,selector_path:t.selectorPath,interaction_type:"click",timestamp:n};this.sessionManager.touch(),this.batchSender.add(l)}shouldExclude(e){if(!this.config.excludeSelector||!e)return!1;let n=e;for(;n&&n!==document.body;){try{if(n.matches(this.config.excludeSelector))return!0}catch{return this.log(`Invalid excludeSelector: ${this.config.excludeSelector}`),this.config.excludeSelector=null,!1}n=n.parentElement}return!1}log(...e){this.config.debug&&console.log("[Li2 ClickTracker]",...e)}};export{g as ClickTracker,M as DEFAULT_CLICK_TRACKER_CONFIG};
1
+ import{a as l}from"../chunk-LZDMBCUK.mjs";import{a}from"../chunk-FF6VDEL5.mjs";function c(s,e){let i=window.scrollX||document.documentElement.scrollLeft,t=window.scrollY||document.documentElement.scrollTop;return{x:s.clientX+(e?0:i),y:s.clientY+(e?0:t),scrollY:t,pageHeight:document.documentElement.scrollHeight}}var o=class{constructor(e){this.buffer=[];this.timer=null;this.started=!1;this.handleBeforeUnload=null;this.handleVisibilityChange=null;this.config=e}start(){this.started||(this.started=!0,this.timer=setInterval(()=>this.flush(),this.config.batchInterval),this.handleBeforeUnload=()=>this.flush(!0),window.addEventListener("beforeunload",this.handleBeforeUnload),this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&this.flush(!0)},document.addEventListener("visibilitychange",this.handleVisibilityChange))}stop(){this.started&&(this.started=!1,this.flush(!0),this.timer&&(clearInterval(this.timer),this.timer=null),this.handleBeforeUnload&&(window.removeEventListener("beforeunload",this.handleBeforeUnload),this.handleBeforeUnload=null),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.handleVisibilityChange=null))}add(e){this.buffer.push(e),this.buffer.length>=this.config.batchSize&&this.flush()}getBufferSize(){return this.buffer.length}flush(e=!1){if(this.buffer.length===0)return;let i=this.buffer.splice(0,this.config.batchSize),t={interactions:i},n=`${this.config.apiUrl}/api/v1/track/interaction`,r=JSON.stringify(t);if(e&&navigator.sendBeacon){let d=`${n}?li2_key=${encodeURIComponent(this.config.publishableKey)}`,u=new Blob([r],{type:"application/json"});navigator.sendBeacon(d,u)?this.log(`Beacon sent: ${i.length} interactions`):this.sendViaFetch(n,r,i)}else this.sendViaFetch(n,r,i);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,i,t){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:i,keepalive:!0}).then(n=>{n.ok?this.log(`Sent: ${t.length} interactions`):(this.log(`Send failed: ${n.status}, re-queuing ${t.length} events`),this.buffer.unshift(...t))}).catch(()=>{this.log(`Network error, re-queuing ${t.length} events`),this.buffer.unshift(...t)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var y={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},g=50,h=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new l({timeout:e.sessionTimeout,cookieLessMode:e.cookieLessMode,cookieDomain:e.cookieDomain,cookiePath:e.cookiePath}),this.batchSender=new o({apiUrl:e.apiUrl,publishableKey:e.publishableKey,batchInterval:e.batchInterval,batchSize:e.batchSize,debug:e.debug})}start(){this.started||(this.started=!0,this.handleClick=e=>this.onDocumentClick(e),document.addEventListener("click",this.handleClick,!0),this.batchSender.start(),this.log("ClickTracker started"))}stop(){this.started&&(this.started=!1,this.handleClick&&(document.removeEventListener("click",this.handleClick,!0),this.handleClick=null),this.batchSender.stop(),this.log("ClickTracker stopped"))}onDocumentClick(e){if(e.button!==0)return;let i=Date.now();if(e.target===this.lastClickTarget&&i-this.lastClickTime<g||(this.lastClickTarget=e.target,this.lastClickTime=i,this.shouldExclude(e.target)))return;let t=a(e.target);if(!t)return;let n=c(e,t.isFixed),r={session_id:this.sessionManager.getSessionId(),visitor_id:this.sessionManager.getVisitorId(),li2_cid:this.config.clickId,page_url:window.location.href,page_path:window.location.pathname,x:n.x,y:n.y,target_fixed:t.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:n.pageHeight,scroll_y:n.scrollY,element_tag:t.tag,element_text:t.text,element_href:t.href,element_class:t.className,element_id:t.id,selector_path:t.selectorPath,interaction_type:"click",timestamp:i};this.sessionManager.touch(),this.batchSender.add(r)}shouldExclude(e){if(!this.config.excludeSelector||!e)return!1;let i=e;for(;i&&i!==document.body;){try{if(i.matches(this.config.excludeSelector))return!0}catch{return this.log(`Invalid excludeSelector: ${this.config.excludeSelector}`),this.config.excludeSelector=null,!1}i=i.parentElement}return!1}log(...e){this.config.debug&&console.log("[Li2 ClickTracker]",...e)}};export{h as ClickTracker,y as DEFAULT_CLICK_TRACKER_CONFIG};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Element metadata extraction for click capture.
3
+ * Resolves clicked elements to meaningful ancestors and builds stable CSS selectors.
4
+ */
5
+ interface ElementInfo {
6
+ /** HTML tag name (lowercase) */
7
+ tag: string;
8
+ /** innerText truncated to 256 chars */
9
+ text: string;
10
+ /** href attribute if link element */
11
+ href: string | null;
12
+ /** className truncated to 512 chars */
13
+ className: string;
14
+ /** id attribute */
15
+ id: string | null;
16
+ /** Stable CSS selector path (tag + nth-child hierarchy) */
17
+ selectorPath: string;
18
+ /** Whether element or ancestor has position: fixed/sticky */
19
+ isFixed: boolean;
20
+ }
21
+
22
+ export type { ElementInfo as E };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Element metadata extraction for click capture.
3
+ * Resolves clicked elements to meaningful ancestors and builds stable CSS selectors.
4
+ */
5
+ interface ElementInfo {
6
+ /** HTML tag name (lowercase) */
7
+ tag: string;
8
+ /** innerText truncated to 256 chars */
9
+ text: string;
10
+ /** href attribute if link element */
11
+ href: string | null;
12
+ /** className truncated to 512 chars */
13
+ className: string;
14
+ /** id attribute */
15
+ id: string | null;
16
+ /** Stable CSS selector path (tag + nth-child hierarchy) */
17
+ selectorPath: string;
18
+ /** Whether element or ancestor has position: fixed/sticky */
19
+ isFixed: boolean;
20
+ }
21
+
22
+ export type { ElementInfo as E };
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { P as PageviewTracker } from './index-B3dzYzIM.mjs';
2
2
  export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-B3dzYzIM.mjs';
3
3
  export { AnalyticsSettings, AutoEvent, ConditionOperator, ConditionType, EventAction, EventActionType, EventTrigger, TriggerCondition, TriggerType } from './auto-events.mjs';
4
4
  export { ClickTrackerConfig } from './click-tracker/index.mjs';
5
+ export { E as ElementInfo } from './element-resolver-BnZ_ItHT.mjs';
5
6
 
6
7
  /**
7
8
  * Batch sender for click interaction events.
@@ -52,27 +53,6 @@ interface InteractionBatchPayload {
52
53
  interactions: InteractionEvent[];
53
54
  }
54
55
 
55
- /**
56
- * Element metadata extraction for click capture.
57
- * Resolves clicked elements to meaningful ancestors and builds stable CSS selectors.
58
- */
59
- interface ElementInfo {
60
- /** HTML tag name (lowercase) */
61
- tag: string;
62
- /** innerText truncated to 256 chars */
63
- text: string;
64
- /** href attribute if link element */
65
- href: string | null;
66
- /** className truncated to 512 chars */
67
- className: string;
68
- /** id attribute */
69
- id: string | null;
70
- /** Stable CSS selector path (tag + nth-child hierarchy) */
71
- selectorPath: string;
72
- /** Whether element or ancestor has position: fixed/sticky */
73
- isFixed: boolean;
74
- }
75
-
76
56
  /**
77
57
  * Coordinate calculation for click capture.
78
58
  * Handles fixed/sticky element positioning and scroll adjustment.
@@ -447,4 +427,4 @@ declare const _default: {
447
427
  initServer: typeof initServer;
448
428
  };
449
429
 
450
- export { type ClickCoordinates, type CookieOptions, type ElementInfo, type InteractionBatchPayload, type InteractionEvent, Li2Analytics, type Li2Config, Li2ServerAnalytics, type Li2ServerConfig, type ServerTrackLeadParams, type ServerTrackSaleParams, type TrackLeadParams, type TrackLeadResponse, type TrackSaleParams, type TrackSaleResponse, _default as default, getClickId, getInstance, identify, init, initServer, isTrackingAvailable, trackEvent, trackLead, trackPageview, trackSale };
430
+ export { type ClickCoordinates, type CookieOptions, type InteractionBatchPayload, type InteractionEvent, Li2Analytics, type Li2Config, Li2ServerAnalytics, type Li2ServerConfig, type ServerTrackLeadParams, type ServerTrackSaleParams, type TrackLeadParams, type TrackLeadResponse, type TrackSaleParams, type TrackSaleResponse, _default as default, getClickId, getInstance, identify, init, initServer, isTrackingAvailable, trackEvent, trackLead, trackPageview, trackSale };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { P as PageviewTracker } from './index-B3dzYzIM.js';
2
2
  export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-B3dzYzIM.js';
3
3
  export { AnalyticsSettings, AutoEvent, ConditionOperator, ConditionType, EventAction, EventActionType, EventTrigger, TriggerCondition, TriggerType } from './auto-events.js';
4
4
  export { ClickTrackerConfig } from './click-tracker/index.js';
5
+ export { E as ElementInfo } from './element-resolver-BnZ_ItHT.js';
5
6
 
6
7
  /**
7
8
  * Batch sender for click interaction events.
@@ -52,27 +53,6 @@ interface InteractionBatchPayload {
52
53
  interactions: InteractionEvent[];
53
54
  }
54
55
 
55
- /**
56
- * Element metadata extraction for click capture.
57
- * Resolves clicked elements to meaningful ancestors and builds stable CSS selectors.
58
- */
59
- interface ElementInfo {
60
- /** HTML tag name (lowercase) */
61
- tag: string;
62
- /** innerText truncated to 256 chars */
63
- text: string;
64
- /** href attribute if link element */
65
- href: string | null;
66
- /** className truncated to 512 chars */
67
- className: string;
68
- /** id attribute */
69
- id: string | null;
70
- /** Stable CSS selector path (tag + nth-child hierarchy) */
71
- selectorPath: string;
72
- /** Whether element or ancestor has position: fixed/sticky */
73
- isFixed: boolean;
74
- }
75
-
76
56
  /**
77
57
  * Coordinate calculation for click capture.
78
58
  * Handles fixed/sticky element positioning and scroll adjustment.
@@ -447,4 +427,4 @@ declare const _default: {
447
427
  initServer: typeof initServer;
448
428
  };
449
429
 
450
- export { type ClickCoordinates, type CookieOptions, type ElementInfo, type InteractionBatchPayload, type InteractionEvent, Li2Analytics, type Li2Config, Li2ServerAnalytics, type Li2ServerConfig, type ServerTrackLeadParams, type ServerTrackSaleParams, type TrackLeadParams, type TrackLeadResponse, type TrackSaleParams, type TrackSaleResponse, _default as default, getClickId, getInstance, identify, init, initServer, isTrackingAvailable, trackEvent, trackLead, trackPageview, trackSale };
430
+ export { type ClickCoordinates, type CookieOptions, type InteractionBatchPayload, type InteractionEvent, Li2Analytics, type Li2Config, Li2ServerAnalytics, type Li2ServerConfig, type ServerTrackLeadParams, type ServerTrackSaleParams, type TrackLeadParams, type TrackLeadResponse, type TrackSaleParams, type TrackSaleResponse, _default as default, getClickId, getInstance, identify, init, initServer, isTrackingAvailable, trackEvent, trackLead, trackPageview, trackSale };