@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.
- package/README.md +179 -39
- package/dist/auto-events.global.js +1 -1
- package/dist/auto-events.js +1 -1
- package/dist/auto-events.mjs +1 -1
- package/dist/chunk-6HT4HNX2.mjs +1 -0
- package/dist/chunk-FF6VDEL5.mjs +1 -1
- package/dist/chunk-MURA7RU5.mjs +1 -1
- package/dist/click-tracker/index.d.mts +13 -0
- package/dist/click-tracker/index.d.ts +13 -0
- package/dist/click-tracker/index.global.js +1 -1
- package/dist/click-tracker/index.js +1 -1
- package/dist/click-tracker/index.mjs +1 -1
- package/dist/{index-B3dzYzIM.d.mts → index-DVbXHaIv.d.mts} +7 -2
- package/dist/{index-B3dzYzIM.d.ts → index-DVbXHaIv.d.ts} +7 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.global.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/outbound.global.js +1 -1
- package/dist/outbound.js +1 -1
- package/dist/outbound.mjs +1 -1
- package/dist/pageview/index.d.mts +1 -1
- package/dist/pageview/index.d.ts +1 -1
- package/dist/pageview/index.global.js +1 -1
- package/dist/pageview/index.js +1 -1
- package/dist/pageview/index.mjs +1 -1
- package/package.json +13 -12
- package/dist/chunk-LZDMBCUK.mjs +0 -1
|
@@ -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
|
|
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
|
|
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
|
|
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:
|
|
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,
|
|
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:
|
|
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,
|
|
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-
|
|
2
|
-
export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-
|
|
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-
|
|
2
|
-
export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-
|
|
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.
|