@li2/analytics 0.3.2 → 0.3.4

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,9 +1,20 @@
1
+ /**
2
+ * Dynamic Configuration Module
3
+ * Consolidated single-file implementation for easy reading
4
+ */
5
+ interface DataCollectionRules {
6
+ mode?: 'exclude' | 'include';
7
+ excludePaths?: string[];
8
+ includePaths?: string[];
9
+ }
10
+
1
11
  /**
2
12
  * ClickTracker — auto-captures all clicks on the page.
3
13
  *
4
14
  * Attaches a single delegated listener on document (capture phase).
5
15
  * Extracts coordinates, element metadata, and sends via InteractionBatchSender.
6
16
  */
17
+
7
18
  interface ClickTrackerConfig {
8
19
  /** API base URL */
9
20
  apiUrl: string;
@@ -17,6 +28,8 @@ interface ClickTrackerConfig {
17
28
  batchSize: number;
18
29
  /** CSS selector for elements to exclude from capture */
19
30
  excludeSelector: string | null;
31
+ /** Path filtering rules from config */
32
+ dataCollectionRules?: DataCollectionRules;
20
33
  /** Debug logging */
21
34
  debug: boolean;
22
35
  /** Session manager config */
@@ -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 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
+ "use strict";var li2Analytics=(()=>{var d=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)d(i,t,{get:e[t],enumerable:!0})},_=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of x(e))!y.call(i,o)&&o!==t&&d(i,o,{get:()=>e[o],enumerable:!(n=C(e,o))||n.enumerable});return i};var T=i=>_(d({},"__esModule",{value:!0}),i);var R={};w(R,{ClickTracker:()=>f,DEFAULT_CLICK_TRACKER_CONFIG:()=>N});var a="li2_vid",g="li2_sid",p="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(p,e.toString(),"session")}createNewSession(){this.sessionId=this.generateId("sess"),this.setStorage(g,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(g,"session");return(!e||this.isSessionExpired())&&(e=this.generateId("sess"),this.setStorage(g,e,"session"),this.touch()),e}isSessionExpired(){let e=this.getStorage(p,"session");if(!e)return!0;let t=Date.now()-parseInt(e,10),n=this.config.timeout*60*1e3;return t>n}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,n){try{(n==="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,n){let o=[`${e}=${encodeURIComponent(t)}`,`path=${this.config.cookiePath}`,`max-age=${n*86400}`,"SameSite=Lax"];this.config.cookieDomain&&o.push(`domain=${this.config.cookieDomain}`),window.location.protocol==="https:"&&o.push("Secure"),document.cookie=o.join("; ")}};var L=new Set(["a","button","input","select","textarea","form","label"]),M=new Set(["button","link","tab","menuitem"]);function v(i){let e=i;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let n=P(e),o=$(n);return{tag:n.tagName.toLowerCase(),text:b(D(n),256),href:H(n),className:b(n.className||"",512),id:n.id||null,selectorPath:U(n),isFixed:o}}function P(i){let e=i,t=0;for(;e&&t<5&&e.tagName!=="BODY";){let n=e.tagName.toLowerCase(),o=e.getAttribute("role");if(L.has(n)||o&&M.has(o))return e;e=e.parentElement,t++}return i}function $(i){let e=i;for(;e&&e!==document.body;){try{let n=window.getComputedStyle(e).getPropertyValue("position");if(n==="fixed"||n==="sticky")return!0}catch{break}e=e.parentElement}return!1}function U(i){let e=[],t=i,n=0;for(;t&&t!==document.body&&n<5;){let o=t.tagName.toLowerCase();t.id&&(o+=`#${t.id}`);let s=t.parentElement;if(s){let r=Array.from(s.children).filter(l=>l.tagName===t.tagName);if(r.length>1){let l=r.indexOf(t)+1;o+=`:nth-of-type(${l})`}}e.unshift(o),t=t.parentElement,n++}return e.join(" > ")}function D(i){return i instanceof HTMLInputElement?i.value||i.placeholder||"":(i.innerText||i.textContent||"").trim()}function H(i){return i instanceof HTMLAnchorElement?i.href||null:i.getAttribute("href")||null}function b(i,e){return i.length<=e?i:i.slice(0,e)}function E(i,e){let t=window.scrollX||document.documentElement.scrollLeft,n=window.scrollY||document.documentElement.scrollTop;return{x:i.clientX+(e?0:t),y:i.clientY+(e?0:n),scrollY:n,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),n={interactions:t},o=`${this.config.apiUrl}/api/v1/track/interaction`,s=JSON.stringify(n);if(e&&navigator.sendBeacon){let r=`${o}?li2_key=${encodeURIComponent(this.config.publishableKey)}`,l=new Blob([s],{type:"application/json"});navigator.sendBeacon(r,l)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(o,s,t)}else this.sendViaFetch(o,s,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,n){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(o=>{o.ok?this.log(`Sent: ${n.length} interactions`):(this.log(`Send failed: ${o.status}, re-queuing ${n.length} events`),this.buffer.unshift(...n))}).catch(()=>{this.log(`Network error, re-queuing ${n.length} events`),this.buffer.unshift(...n)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};function I(i,e,t){if(!e)return!0;let{mode:n,includePaths:o,excludePaths:s}=e;if(n==="include"){if(!(o&&o.length>0))return t&&console.log(`[PathFilter] mode=include but no includePaths, blocking "${i}"`),!1;let m=o.some(S=>k(i,S));return t&&(m?console.log(`[PathFilter] mode=include: "${i}" matched includePath`):console.log(`[PathFilter] mode=include: "${i}" not in includePaths:`,o)),m}return s&&s.length>0?s.some(u=>k(i,u))?(t&&console.log(`[PathFilter] mode=exclude: "${i}" matched excludePath:`,s),!1):(t&&console.log(`[PathFilter] Path "${i}" allowed by rules`),!0):(t&&console.log(`[PathFilter] No excludePaths, path "${i}" allowed`),!0)}function k(i,e){let n=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*\*|\*/g,o=>o==="**"?".*":"[^/]*");return new RegExp(`^${n}$`).test(i)}var N={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},F=50,f=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=window.location.pathname;if(!I(t,this.config.dataCollectionRules,this.config.debug)){this.log(`Path excluded from tracking: ${t}`);return}let n=Date.now();if(e.target===this.lastClickTarget&&n-this.lastClickTime<F||(this.lastClickTarget=e.target,this.lastClickTime=n,this.shouldExclude(e.target)))return;let o=v(e.target);if(!o)return;let s=E(e,o.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:s.x,y:s.y,target_fixed:o.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:s.pageHeight,scroll_y:s.scrollY,element_tag:o.tag,element_text:o.text,element_href:o.href,element_class:o.className,element_id:o.id,selector_path:o.selectorPath,interaction_type:"click",timestamp:n};this.sessionManager.touch(),this.batchSender.add(r)}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 T(R);})();
@@ -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 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
+ "use strict";var d=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)d(i,t,{get:e[t],enumerable:!0})},_=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of x(e))!y.call(i,o)&&o!==t&&d(i,o,{get:()=>e[o],enumerable:!(n=C(e,o))||n.enumerable});return i};var T=i=>_(d({},"__esModule",{value:!0}),i);var R={};w(R,{ClickTracker:()=>f,DEFAULT_CLICK_TRACKER_CONFIG:()=>N});module.exports=T(R);var a="li2_vid",g="li2_sid",p="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(p,e.toString(),"session")}createNewSession(){this.sessionId=this.generateId("sess"),this.setStorage(g,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(g,"session");return(!e||this.isSessionExpired())&&(e=this.generateId("sess"),this.setStorage(g,e,"session"),this.touch()),e}isSessionExpired(){let e=this.getStorage(p,"session");if(!e)return!0;let t=Date.now()-parseInt(e,10),n=this.config.timeout*60*1e3;return t>n}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,n){try{(n==="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,n){let o=[`${e}=${encodeURIComponent(t)}`,`path=${this.config.cookiePath}`,`max-age=${n*86400}`,"SameSite=Lax"];this.config.cookieDomain&&o.push(`domain=${this.config.cookieDomain}`),window.location.protocol==="https:"&&o.push("Secure"),document.cookie=o.join("; ")}};var L=new Set(["a","button","input","select","textarea","form","label"]),M=new Set(["button","link","tab","menuitem"]);function v(i){let e=i;for(;e&&!(e instanceof HTMLElement);)e=e.parentElement;if(!e)return null;let n=P(e),o=$(n);return{tag:n.tagName.toLowerCase(),text:b(D(n),256),href:H(n),className:b(n.className||"",512),id:n.id||null,selectorPath:U(n),isFixed:o}}function P(i){let e=i,t=0;for(;e&&t<5&&e.tagName!=="BODY";){let n=e.tagName.toLowerCase(),o=e.getAttribute("role");if(L.has(n)||o&&M.has(o))return e;e=e.parentElement,t++}return i}function $(i){let e=i;for(;e&&e!==document.body;){try{let n=window.getComputedStyle(e).getPropertyValue("position");if(n==="fixed"||n==="sticky")return!0}catch{break}e=e.parentElement}return!1}function U(i){let e=[],t=i,n=0;for(;t&&t!==document.body&&n<5;){let o=t.tagName.toLowerCase();t.id&&(o+=`#${t.id}`);let s=t.parentElement;if(s){let r=Array.from(s.children).filter(l=>l.tagName===t.tagName);if(r.length>1){let l=r.indexOf(t)+1;o+=`:nth-of-type(${l})`}}e.unshift(o),t=t.parentElement,n++}return e.join(" > ")}function D(i){return i instanceof HTMLInputElement?i.value||i.placeholder||"":(i.innerText||i.textContent||"").trim()}function H(i){return i instanceof HTMLAnchorElement?i.href||null:i.getAttribute("href")||null}function b(i,e){return i.length<=e?i:i.slice(0,e)}function E(i,e){let t=window.scrollX||document.documentElement.scrollLeft,n=window.scrollY||document.documentElement.scrollTop;return{x:i.clientX+(e?0:t),y:i.clientY+(e?0:n),scrollY:n,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),n={interactions:t},o=`${this.config.apiUrl}/api/v1/track/interaction`,s=JSON.stringify(n);if(e&&navigator.sendBeacon){let r=`${o}?li2_key=${encodeURIComponent(this.config.publishableKey)}`,l=new Blob([s],{type:"application/json"});navigator.sendBeacon(r,l)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(o,s,t)}else this.sendViaFetch(o,s,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,n){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(o=>{o.ok?this.log(`Sent: ${n.length} interactions`):(this.log(`Send failed: ${o.status}, re-queuing ${n.length} events`),this.buffer.unshift(...n))}).catch(()=>{this.log(`Network error, re-queuing ${n.length} events`),this.buffer.unshift(...n)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};function I(i,e,t){if(!e)return!0;let{mode:n,includePaths:o,excludePaths:s}=e;if(n==="include"){if(!(o&&o.length>0))return t&&console.log(`[PathFilter] mode=include but no includePaths, blocking "${i}"`),!1;let m=o.some(S=>k(i,S));return t&&(m?console.log(`[PathFilter] mode=include: "${i}" matched includePath`):console.log(`[PathFilter] mode=include: "${i}" not in includePaths:`,o)),m}return s&&s.length>0?s.some(u=>k(i,u))?(t&&console.log(`[PathFilter] mode=exclude: "${i}" matched excludePath:`,s),!1):(t&&console.log(`[PathFilter] Path "${i}" allowed by rules`),!0):(t&&console.log(`[PathFilter] No excludePaths, path "${i}" allowed`),!0)}function k(i,e){let n=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*\*|\*/g,o=>o==="**"?".*":"[^/]*");return new RegExp(`^${n}$`).test(i)}var N={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},F=50,f=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=window.location.pathname;if(!I(t,this.config.dataCollectionRules,this.config.debug)){this.log(`Path excluded from tracking: ${t}`);return}let n=Date.now();if(e.target===this.lastClickTarget&&n-this.lastClickTime<F||(this.lastClickTarget=e.target,this.lastClickTime=n,this.shouldExclude(e.target)))return;let o=v(e.target);if(!o)return;let s=E(e,o.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:s.x,y:s.y,target_fixed:o.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:s.pageHeight,scroll_y:s.scrollY,element_tag:o.tag,element_text:o.text,element_href:o.href,element_class:o.className,element_id:o.id,selector_path:o.selectorPath,interaction_type:"click",timestamp:n};this.sessionManager.touch(),this.batchSender.add(r)}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 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};
1
+ import{a,b as c}from"../chunk-6HT4HNX2.mjs";import{a as h}from"../chunk-FF6VDEL5.mjs";function d(s,e){let t=window.scrollX||document.documentElement.scrollLeft,n=window.scrollY||document.documentElement.scrollTop;return{x:s.clientX+(e?0:t),y:s.clientY+(e?0:n),scrollY:n,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 t=this.buffer.splice(0,this.config.batchSize),n={interactions:t},i=`${this.config.apiUrl}/api/v1/track/interaction`,r=JSON.stringify(n);if(e&&navigator.sendBeacon){let l=`${i}?li2_key=${encodeURIComponent(this.config.publishableKey)}`,g=new Blob([r],{type:"application/json"});navigator.sendBeacon(l,g)?this.log(`Beacon sent: ${t.length} interactions`):this.sendViaFetch(i,r,t)}else this.sendViaFetch(i,r,t);this.buffer.length>0&&this.flush(e)}sendViaFetch(e,t,n){fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Li2-Key":this.config.publishableKey},body:t,keepalive:!0}).then(i=>{i.ok?this.log(`Sent: ${n.length} interactions`):(this.log(`Send failed: ${i.status}, re-queuing ${n.length} events`),this.buffer.unshift(...n))}).catch(()=>{this.log(`Network error, re-queuing ${n.length} events`),this.buffer.unshift(...n)})}log(...e){this.config.debug&&console.log("[Li2 InteractionBatchSender]",...e)}};var I={batchInterval:5e3,batchSize:50,excludeSelector:null,debug:!1,sessionTimeout:30,cookieLessMode:!1,cookiePath:"/"},f=50,u=class{constructor(e){this.started=!1;this.handleClick=null;this.lastClickTarget=null;this.lastClickTime=0;this.config=e,this.sessionManager=new a({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 t=window.location.pathname;if(!c(t,this.config.dataCollectionRules,this.config.debug)){this.log(`Path excluded from tracking: ${t}`);return}let n=Date.now();if(e.target===this.lastClickTarget&&n-this.lastClickTime<f||(this.lastClickTarget=e.target,this.lastClickTime=n,this.shouldExclude(e.target)))return;let i=h(e.target);if(!i)return;let r=d(e,i.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:i.isFixed,viewport_width:window.innerWidth,viewport_height:window.innerHeight,page_height:r.pageHeight,scroll_y:r.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:n};this.sessionManager.touch(),this.batchSender.add(l)}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)}};export{u as ClickTracker,I as DEFAULT_CLICK_TRACKER_CONFIG};
@@ -7,13 +7,18 @@ interface PageviewConfig {
7
7
  /** Enable/disable pageview tracking */
8
8
  enabled: boolean;
9
9
  /** SPA detection mode: 'auto' | 'manual' | 'disabled' */
10
- spaMode: 'auto' | 'manual' | 'disabled';
10
+ spaMode: "auto" | "manual" | "disabled";
11
11
  /** Batch send interval in milliseconds (default: 5000) */
12
12
  batchInterval: number;
13
13
  /** Max pageviews per batch (default: 50) */
14
14
  batchSize: number;
15
15
  /** URL patterns to exclude from tracking (glob-like) */
16
16
  excludePatterns: string[];
17
+ /** Path filtering rules from config (takes precedence over excludePatterns) */
18
+ dataCollectionRules?: {
19
+ excludePaths?: string[];
20
+ includePaths?: string[];
21
+ };
17
22
  /** Track hash changes as separate pageviews (default: false) */
18
23
  trackHashChanges: boolean;
19
24
  /** Session timeout in minutes (default: 30) */
@@ -78,7 +83,7 @@ declare class PageviewTracker {
78
83
  private enabled;
79
84
  private lastPageUrl;
80
85
  private lastPageTimestamp;
81
- constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, 'apiUrl' | 'publishableKey'>);
86
+ constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, "apiUrl" | "publishableKey">);
82
87
  /** Start tracking pageviews */
83
88
  start(): void;
84
89
  /** Stop tracking pageviews */
@@ -7,13 +7,18 @@ interface PageviewConfig {
7
7
  /** Enable/disable pageview tracking */
8
8
  enabled: boolean;
9
9
  /** SPA detection mode: 'auto' | 'manual' | 'disabled' */
10
- spaMode: 'auto' | 'manual' | 'disabled';
10
+ spaMode: "auto" | "manual" | "disabled";
11
11
  /** Batch send interval in milliseconds (default: 5000) */
12
12
  batchInterval: number;
13
13
  /** Max pageviews per batch (default: 50) */
14
14
  batchSize: number;
15
15
  /** URL patterns to exclude from tracking (glob-like) */
16
16
  excludePatterns: string[];
17
+ /** Path filtering rules from config (takes precedence over excludePatterns) */
18
+ dataCollectionRules?: {
19
+ excludePaths?: string[];
20
+ includePaths?: string[];
21
+ };
17
22
  /** Track hash changes as separate pageviews (default: false) */
18
23
  trackHashChanges: boolean;
19
24
  /** Session timeout in minutes (default: 30) */
@@ -78,7 +83,7 @@ declare class PageviewTracker {
78
83
  private enabled;
79
84
  private lastPageUrl;
80
85
  private lastPageTimestamp;
81
- constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, 'apiUrl' | 'publishableKey'>);
86
+ constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, "apiUrl" | "publishableKey">);
82
87
  /** Start tracking pageviews */
83
88
  start(): void;
84
89
  /** Stop tracking pageviews */
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PageviewTracker } from './index-B3dzYzIM.mjs';
2
- export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-B3dzYzIM.mjs';
1
+ import { P as PageviewTracker } from './index-DVbXHaIv.mjs';
2
+ export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-DVbXHaIv.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
5
  export { E as ElementInfo } from './element-resolver-BnZ_ItHT.mjs';
@@ -219,6 +219,10 @@ declare class Li2Analytics {
219
219
  * Initialize auto-event tracking
220
220
  */
221
221
  private initAutoEventTracking;
222
+ /**
223
+ * Get data collection rules from config
224
+ */
225
+ private getDataCollectionRules;
222
226
  /**
223
227
  * Initialize pageview tracking from data-attributes or config.
224
228
  * Uses dynamic import to lazy-load the pageview module only when enabled.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PageviewTracker } from './index-B3dzYzIM.js';
2
- export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-B3dzYzIM.js';
1
+ import { P as PageviewTracker } from './index-DVbXHaIv.js';
2
+ export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-DVbXHaIv.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
5
  export { E as ElementInfo } from './element-resolver-BnZ_ItHT.js';
@@ -219,6 +219,10 @@ declare class Li2Analytics {
219
219
  * Initialize auto-event tracking
220
220
  */
221
221
  private initAutoEventTracking;
222
+ /**
223
+ * Get data collection rules from config
224
+ */
225
+ private getDataCollectionRules;
222
226
  /**
223
227
  * Initialize pageview tracking from data-attributes or config.
224
228
  * Uses dynamic import to lazy-load the pageview module only when enabled.