@li2/analytics 0.2.3 → 0.3.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +69 -0
  2. package/dist/auto-events.global.js +1 -1
  3. package/dist/auto-events.js +1 -1
  4. package/dist/auto-events.mjs +1 -1
  5. package/dist/chunk-6RUMMSEZ.mjs +1 -0
  6. package/dist/chunk-LZDMBCUK.mjs +1 -0
  7. package/dist/chunk-MURA7RU5.mjs +1 -1
  8. package/dist/click-tracker/index.d.mts +52 -0
  9. package/dist/click-tracker/index.d.ts +52 -0
  10. package/dist/click-tracker/index.global.js +1 -0
  11. package/dist/click-tracker/index.js +1 -0
  12. package/dist/click-tracker/index.mjs +1 -0
  13. package/dist/click-triggers.d.mts +2 -0
  14. package/dist/click-triggers.d.ts +2 -0
  15. package/dist/click-triggers.global.js +1 -0
  16. package/dist/click-triggers.js +1 -0
  17. package/dist/click-triggers.mjs +1 -0
  18. package/dist/index-B3dzYzIM.d.mts +122 -0
  19. package/dist/index-B3dzYzIM.d.ts +122 -0
  20. package/dist/index-DEfkJIjF.d.mts +114 -0
  21. package/dist/index-DEfkJIjF.d.ts +114 -0
  22. package/dist/index.d.mts +162 -1
  23. package/dist/index.d.ts +162 -1
  24. package/dist/index.global.js +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/index.mjs +1 -1
  27. package/dist/outbound.global.js +1 -1
  28. package/dist/outbound.js +1 -1
  29. package/dist/outbound.mjs +1 -1
  30. package/dist/pageview/index.d.mts +1 -0
  31. package/dist/pageview/index.d.ts +1 -0
  32. package/dist/pageview/index.global.js +1 -0
  33. package/dist/pageview/index.js +1 -0
  34. package/dist/pageview/index.mjs +1 -0
  35. package/dist/toolbar/index.d.mts +17 -0
  36. package/dist/toolbar/index.d.ts +17 -0
  37. package/dist/toolbar/index.global.js +20 -0
  38. package/dist/toolbar/index.js +20 -0
  39. package/dist/toolbar/index.mjs +20 -0
  40. package/package.json +60 -39
  41. package/dist/index.global2.js +0 -1
package/dist/index.d.ts CHANGED
@@ -1,9 +1,98 @@
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
3
  export { AnalyticsSettings, AutoEvent, ConditionOperator, ConditionType, EventAction, EventActionType, EventTrigger, TriggerCondition, TriggerType } from './auto-events.js';
4
+ export { ClickTrackerConfig } from './click-tracker/index.js';
5
+
6
+ /**
7
+ * Batch sender for click interaction events.
8
+ * Same pattern as pageview BatchSender but sends to /api/v1/track/interaction.
9
+ */
10
+ interface InteractionEvent {
11
+ /** Client-generated session ID */
12
+ session_id: string;
13
+ /** Persistent visitor ID */
14
+ visitor_id: string;
15
+ /** Li2 click ID if visitor came from short link */
16
+ li2_cid: string | null;
17
+ /** Full page URL */
18
+ page_url: string;
19
+ /** URL path only */
20
+ page_path: string;
21
+ /** Absolute X position (scroll-adjusted unless fixed) */
22
+ x: number;
23
+ /** Absolute Y position (scroll-adjusted unless fixed) */
24
+ y: number;
25
+ /** Whether clicked element has position: fixed/sticky */
26
+ target_fixed: boolean;
27
+ /** Browser viewport dimensions */
28
+ viewport_width: number;
29
+ viewport_height: number;
30
+ /** Total scrollable page height */
31
+ page_height: number;
32
+ /** Scroll Y at click time */
33
+ scroll_y: number;
34
+ /** Element tag name (lowercase) */
35
+ element_tag: string;
36
+ /** Element innerText (truncated to 256 chars) */
37
+ element_text: string;
38
+ /** href attribute if link element */
39
+ element_href: string | null;
40
+ /** className (truncated to 512 chars) */
41
+ element_class: string;
42
+ /** id attribute */
43
+ element_id: string | null;
44
+ /** Stable CSS selector path */
45
+ selector_path: string;
46
+ /** Interaction type (click, scroll, etc.) */
47
+ interaction_type: string;
48
+ /** Unix timestamp in milliseconds */
49
+ timestamp: number;
50
+ }
51
+ interface InteractionBatchPayload {
52
+ interactions: InteractionEvent[];
53
+ }
54
+
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
+ /**
77
+ * Coordinate calculation for click capture.
78
+ * Handles fixed/sticky element positioning and scroll adjustment.
79
+ */
80
+ interface ClickCoordinates {
81
+ /** Absolute X position (scroll-adjusted unless fixed) */
82
+ x: number;
83
+ /** Absolute Y position (scroll-adjusted unless fixed) */
84
+ y: number;
85
+ /** Current scroll Y at click time */
86
+ scrollY: number;
87
+ /** Total scrollable page height */
88
+ pageHeight: number;
89
+ }
2
90
 
3
91
  /**
4
92
  * Li2 Analytics SDK
5
93
  * Conversion tracking for li2.ai
6
94
  */
95
+
7
96
  interface Li2Config {
8
97
  /** Publishable key from your organization's analytics settings */
9
98
  publishableKey?: string;
@@ -142,12 +231,66 @@ declare class Li2Analytics {
142
231
  private clickId;
143
232
  private cookieOptions;
144
233
  private autoEventTracker;
234
+ private clickTracker;
235
+ pageview: PageviewTracker | null;
145
236
  constructor(config?: Li2Config);
146
237
  private log;
147
238
  /**
148
239
  * Initialize auto-event tracking
149
240
  */
150
241
  private initAutoEventTracking;
242
+ /**
243
+ * Initialize pageview tracking from data-attributes or config.
244
+ * Uses dynamic import to lazy-load the pageview module only when enabled.
245
+ * @internal Called from auto-init block - not part of public API
246
+ */
247
+ initPageviewTracking(pageviewConfig: Record<string, string>): Promise<void>;
248
+ /**
249
+ * Enable pageview tracking programmatically (for users not using data-attributes)
250
+ */
251
+ enablePageviewTracking(options?: {
252
+ spaMode?: "auto" | "manual" | "disabled";
253
+ excludePatterns?: string[];
254
+ trackHashChanges?: boolean;
255
+ sessionTimeout?: number;
256
+ cookieLessMode?: boolean;
257
+ batchInterval?: number;
258
+ searchParams?: string[];
259
+ cookieDomain?: string;
260
+ cookiePath?: string;
261
+ }): Promise<void>;
262
+ /**
263
+ * Initialize click tracking from data-attributes.
264
+ * Uses dynamic import to lazy-load the click-tracker module only when enabled.
265
+ * @internal Called from auto-init block - not part of public API
266
+ */
267
+ initClickTracking(clickConfig: Record<string, string>): Promise<void>;
268
+ /**
269
+ * Enable click tracking programmatically (for users not using data-attributes)
270
+ */
271
+ enableClickTracking(options?: {
272
+ batchInterval?: number;
273
+ excludeSelector?: string;
274
+ sessionTimeout?: number;
275
+ cookieLessMode?: boolean;
276
+ cookieDomain?: string;
277
+ cookiePath?: string;
278
+ }): Promise<void>;
279
+ /**
280
+ * Manually track a pageview (convenience method)
281
+ */
282
+ trackPageview(options?: {
283
+ pageUrl?: string;
284
+ pageTitle?: string;
285
+ customData?: Record<string, unknown>;
286
+ }): void;
287
+ /**
288
+ * Track a named event (sent through the pageview pipeline with event_name set)
289
+ * Auto-initializes PageviewTracker if not already running.
290
+ */
291
+ trackEvent(eventName: string, options?: {
292
+ category?: string;
293
+ }): Promise<void>;
151
294
  /**
152
295
  * Set cookie options for customizing cookie behavior
153
296
  * If a clickId already exists, the cookie will be re-set with the new options
@@ -269,6 +412,22 @@ declare function identify(params: {
269
412
  customerId?: string;
270
413
  message?: string;
271
414
  }>;
415
+ /**
416
+ * Track a pageview manually
417
+ * Convenience function that uses the singleton instance
418
+ */
419
+ declare function trackPageview(options?: {
420
+ pageUrl?: string;
421
+ pageTitle?: string;
422
+ customData?: Record<string, unknown>;
423
+ }): void;
424
+ /**
425
+ * Track a named event
426
+ * Convenience function that uses the singleton instance
427
+ */
428
+ declare function trackEvent(eventName: string, options?: {
429
+ category?: string;
430
+ }): Promise<void>;
272
431
 
273
432
  /**
274
433
  * Initialize the server-side Li2 Analytics SDK
@@ -280,10 +439,12 @@ declare const _default: {
280
439
  getInstance: typeof getInstance;
281
440
  trackLead: typeof trackLead;
282
441
  trackSale: typeof trackSale;
442
+ trackEvent: typeof trackEvent;
283
443
  identify: typeof identify;
284
444
  isTrackingAvailable: typeof isTrackingAvailable;
285
445
  getClickId: typeof getClickId;
446
+ trackPageview: typeof trackPageview;
286
447
  initServer: typeof initServer;
287
448
  };
288
449
 
289
- export { type CookieOptions, 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, trackLead, trackSale };
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 };