@li2/analytics 0.3.0-beta.0 → 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.
- 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-6RUMMSEZ.mjs +1 -1
- package/dist/chunk-LZDMBCUK.mjs +1 -0
- package/dist/chunk-MURA7RU5.mjs +1 -1
- package/dist/click-tracker/index.d.mts +52 -0
- package/dist/click-tracker/index.d.ts +52 -0
- package/dist/click-tracker/index.global.js +1 -0
- package/dist/click-tracker/index.js +1 -0
- package/dist/click-tracker/index.mjs +1 -0
- package/dist/click-triggers.global.js +1 -1
- package/dist/click-triggers.js +1 -1
- package/dist/click-triggers.mjs +1 -1
- package/dist/index-B3dzYzIM.d.mts +122 -0
- package/dist/index-B3dzYzIM.d.ts +122 -0
- package/dist/index.d.mts +122 -3
- package/dist/index.d.ts +122 -3
- 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/dist/toolbar/index.d.mts +17 -0
- package/dist/toolbar/index.d.ts +17 -0
- package/dist/toolbar/index.global.js +20 -0
- package/dist/toolbar/index.js +20 -0
- package/dist/toolbar/index.mjs +20 -0
- package/package.json +14 -4
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Configuration for PageviewTracker */
|
|
2
|
+
interface PageviewConfig {
|
|
3
|
+
/** API endpoint base URL */
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
/** Publishable key for authentication */
|
|
6
|
+
publishableKey: string;
|
|
7
|
+
/** Enable/disable pageview tracking */
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
/** SPA detection mode: 'auto' | 'manual' | 'disabled' */
|
|
10
|
+
spaMode: 'auto' | 'manual' | 'disabled';
|
|
11
|
+
/** Batch send interval in milliseconds (default: 5000) */
|
|
12
|
+
batchInterval: number;
|
|
13
|
+
/** Max pageviews per batch (default: 50) */
|
|
14
|
+
batchSize: number;
|
|
15
|
+
/** URL patterns to exclude from tracking (glob-like) */
|
|
16
|
+
excludePatterns: string[];
|
|
17
|
+
/** Track hash changes as separate pageviews (default: false) */
|
|
18
|
+
trackHashChanges: boolean;
|
|
19
|
+
/** Session timeout in minutes (default: 30) */
|
|
20
|
+
sessionTimeout: number;
|
|
21
|
+
/** Cookie-less mode: use only sessionStorage (default: false) */
|
|
22
|
+
cookieLessMode: boolean;
|
|
23
|
+
/** Enable debug logging (default: false) */
|
|
24
|
+
debug: boolean;
|
|
25
|
+
/** Respect Do Not Track header (default: true) */
|
|
26
|
+
respectDnt: boolean;
|
|
27
|
+
/** Cookie domain (default: auto-detect) */
|
|
28
|
+
cookieDomain?: string;
|
|
29
|
+
/** Cookie path (default: '/') */
|
|
30
|
+
cookiePath: string;
|
|
31
|
+
/** Search query URL parameters to detect (default: ['q', 'query', 'search', 's']) */
|
|
32
|
+
searchParams: string[];
|
|
33
|
+
}
|
|
34
|
+
/** A single pageview event to be sent to the server */
|
|
35
|
+
interface PageviewEvent {
|
|
36
|
+
/** Client-generated session ID */
|
|
37
|
+
session_id: string;
|
|
38
|
+
/** Persistent visitor ID */
|
|
39
|
+
visitor_id: string;
|
|
40
|
+
/** Li2 click ID if visitor came from short link */
|
|
41
|
+
li2_cid: string | null;
|
|
42
|
+
/** Full page URL */
|
|
43
|
+
page_url: string;
|
|
44
|
+
/** URL path only */
|
|
45
|
+
page_path: string;
|
|
46
|
+
/** Document title */
|
|
47
|
+
page_title: string;
|
|
48
|
+
/** Previous page URL (internal referrer) */
|
|
49
|
+
page_referrer: string;
|
|
50
|
+
/** URL hash/fragment */
|
|
51
|
+
page_hash: string;
|
|
52
|
+
/** Search query (if detected from URL params) */
|
|
53
|
+
search_query: string | null;
|
|
54
|
+
/** Unix timestamp in milliseconds */
|
|
55
|
+
timestamp: number;
|
|
56
|
+
/** Time spent on previous page in milliseconds */
|
|
57
|
+
time_on_page: number | null;
|
|
58
|
+
/** Screen dimensions */
|
|
59
|
+
screen_width: number;
|
|
60
|
+
screen_height: number;
|
|
61
|
+
viewport_width: number;
|
|
62
|
+
viewport_height: number;
|
|
63
|
+
/** Event name (when this record represents a named event, not a pageview) */
|
|
64
|
+
event_name?: string;
|
|
65
|
+
/** Event category for grouping (optional, only with event_name) */
|
|
66
|
+
event_category?: string;
|
|
67
|
+
}
|
|
68
|
+
/** Batch payload sent to the server */
|
|
69
|
+
interface PageviewBatchPayload {
|
|
70
|
+
pageviews: PageviewEvent[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class PageviewTracker {
|
|
74
|
+
private config;
|
|
75
|
+
private pageDetector;
|
|
76
|
+
private sessionManager;
|
|
77
|
+
private batchSender;
|
|
78
|
+
private enabled;
|
|
79
|
+
private lastPageUrl;
|
|
80
|
+
private lastPageTimestamp;
|
|
81
|
+
constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, 'apiUrl' | 'publishableKey'>);
|
|
82
|
+
/** Start tracking pageviews */
|
|
83
|
+
start(): void;
|
|
84
|
+
/** Stop tracking pageviews */
|
|
85
|
+
stop(): void;
|
|
86
|
+
/** Enable pageview tracking */
|
|
87
|
+
enable(): void;
|
|
88
|
+
/** Disable pageview tracking */
|
|
89
|
+
disable(): void;
|
|
90
|
+
/** Force start a new session */
|
|
91
|
+
newSession(): void;
|
|
92
|
+
/** Manually track a pageview (for advanced use cases) */
|
|
93
|
+
trackPageview(options?: {
|
|
94
|
+
pageUrl?: string;
|
|
95
|
+
pageTitle?: string;
|
|
96
|
+
customData?: Record<string, unknown>;
|
|
97
|
+
}): void;
|
|
98
|
+
/** Track a named event (sent through the pageview pipeline with event_name set) */
|
|
99
|
+
trackEvent(eventName: string, options?: {
|
|
100
|
+
category?: string;
|
|
101
|
+
}): void;
|
|
102
|
+
/** Handle page change event from PageDetector */
|
|
103
|
+
private handlePageChange;
|
|
104
|
+
/** Build a PageviewEvent from current state */
|
|
105
|
+
private buildPageviewEvent;
|
|
106
|
+
/** Track the current page (called on init) */
|
|
107
|
+
private trackCurrentPage;
|
|
108
|
+
/** Check if a path matches any exclude pattern */
|
|
109
|
+
private isExcluded;
|
|
110
|
+
/** Extract search query from URL params */
|
|
111
|
+
private extractSearchQuery;
|
|
112
|
+
/**
|
|
113
|
+
* Get Li2 click ID from existing SDK cookie management.
|
|
114
|
+
* Priority: URL param `uid` → cookie `li_cid` → legacy cookie `li2_id`
|
|
115
|
+
* This matches the exact resolution order in li2-analytics/src/index.ts
|
|
116
|
+
*/
|
|
117
|
+
private getLi2Cid;
|
|
118
|
+
/** Debug logger */
|
|
119
|
+
private log;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { PageviewTracker as P, type PageviewConfig as a, type PageviewEvent as b, type PageviewBatchPayload as c };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Configuration for PageviewTracker */
|
|
2
|
+
interface PageviewConfig {
|
|
3
|
+
/** API endpoint base URL */
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
/** Publishable key for authentication */
|
|
6
|
+
publishableKey: string;
|
|
7
|
+
/** Enable/disable pageview tracking */
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
/** SPA detection mode: 'auto' | 'manual' | 'disabled' */
|
|
10
|
+
spaMode: 'auto' | 'manual' | 'disabled';
|
|
11
|
+
/** Batch send interval in milliseconds (default: 5000) */
|
|
12
|
+
batchInterval: number;
|
|
13
|
+
/** Max pageviews per batch (default: 50) */
|
|
14
|
+
batchSize: number;
|
|
15
|
+
/** URL patterns to exclude from tracking (glob-like) */
|
|
16
|
+
excludePatterns: string[];
|
|
17
|
+
/** Track hash changes as separate pageviews (default: false) */
|
|
18
|
+
trackHashChanges: boolean;
|
|
19
|
+
/** Session timeout in minutes (default: 30) */
|
|
20
|
+
sessionTimeout: number;
|
|
21
|
+
/** Cookie-less mode: use only sessionStorage (default: false) */
|
|
22
|
+
cookieLessMode: boolean;
|
|
23
|
+
/** Enable debug logging (default: false) */
|
|
24
|
+
debug: boolean;
|
|
25
|
+
/** Respect Do Not Track header (default: true) */
|
|
26
|
+
respectDnt: boolean;
|
|
27
|
+
/** Cookie domain (default: auto-detect) */
|
|
28
|
+
cookieDomain?: string;
|
|
29
|
+
/** Cookie path (default: '/') */
|
|
30
|
+
cookiePath: string;
|
|
31
|
+
/** Search query URL parameters to detect (default: ['q', 'query', 'search', 's']) */
|
|
32
|
+
searchParams: string[];
|
|
33
|
+
}
|
|
34
|
+
/** A single pageview event to be sent to the server */
|
|
35
|
+
interface PageviewEvent {
|
|
36
|
+
/** Client-generated session ID */
|
|
37
|
+
session_id: string;
|
|
38
|
+
/** Persistent visitor ID */
|
|
39
|
+
visitor_id: string;
|
|
40
|
+
/** Li2 click ID if visitor came from short link */
|
|
41
|
+
li2_cid: string | null;
|
|
42
|
+
/** Full page URL */
|
|
43
|
+
page_url: string;
|
|
44
|
+
/** URL path only */
|
|
45
|
+
page_path: string;
|
|
46
|
+
/** Document title */
|
|
47
|
+
page_title: string;
|
|
48
|
+
/** Previous page URL (internal referrer) */
|
|
49
|
+
page_referrer: string;
|
|
50
|
+
/** URL hash/fragment */
|
|
51
|
+
page_hash: string;
|
|
52
|
+
/** Search query (if detected from URL params) */
|
|
53
|
+
search_query: string | null;
|
|
54
|
+
/** Unix timestamp in milliseconds */
|
|
55
|
+
timestamp: number;
|
|
56
|
+
/** Time spent on previous page in milliseconds */
|
|
57
|
+
time_on_page: number | null;
|
|
58
|
+
/** Screen dimensions */
|
|
59
|
+
screen_width: number;
|
|
60
|
+
screen_height: number;
|
|
61
|
+
viewport_width: number;
|
|
62
|
+
viewport_height: number;
|
|
63
|
+
/** Event name (when this record represents a named event, not a pageview) */
|
|
64
|
+
event_name?: string;
|
|
65
|
+
/** Event category for grouping (optional, only with event_name) */
|
|
66
|
+
event_category?: string;
|
|
67
|
+
}
|
|
68
|
+
/** Batch payload sent to the server */
|
|
69
|
+
interface PageviewBatchPayload {
|
|
70
|
+
pageviews: PageviewEvent[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class PageviewTracker {
|
|
74
|
+
private config;
|
|
75
|
+
private pageDetector;
|
|
76
|
+
private sessionManager;
|
|
77
|
+
private batchSender;
|
|
78
|
+
private enabled;
|
|
79
|
+
private lastPageUrl;
|
|
80
|
+
private lastPageTimestamp;
|
|
81
|
+
constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, 'apiUrl' | 'publishableKey'>);
|
|
82
|
+
/** Start tracking pageviews */
|
|
83
|
+
start(): void;
|
|
84
|
+
/** Stop tracking pageviews */
|
|
85
|
+
stop(): void;
|
|
86
|
+
/** Enable pageview tracking */
|
|
87
|
+
enable(): void;
|
|
88
|
+
/** Disable pageview tracking */
|
|
89
|
+
disable(): void;
|
|
90
|
+
/** Force start a new session */
|
|
91
|
+
newSession(): void;
|
|
92
|
+
/** Manually track a pageview (for advanced use cases) */
|
|
93
|
+
trackPageview(options?: {
|
|
94
|
+
pageUrl?: string;
|
|
95
|
+
pageTitle?: string;
|
|
96
|
+
customData?: Record<string, unknown>;
|
|
97
|
+
}): void;
|
|
98
|
+
/** Track a named event (sent through the pageview pipeline with event_name set) */
|
|
99
|
+
trackEvent(eventName: string, options?: {
|
|
100
|
+
category?: string;
|
|
101
|
+
}): void;
|
|
102
|
+
/** Handle page change event from PageDetector */
|
|
103
|
+
private handlePageChange;
|
|
104
|
+
/** Build a PageviewEvent from current state */
|
|
105
|
+
private buildPageviewEvent;
|
|
106
|
+
/** Track the current page (called on init) */
|
|
107
|
+
private trackCurrentPage;
|
|
108
|
+
/** Check if a path matches any exclude pattern */
|
|
109
|
+
private isExcluded;
|
|
110
|
+
/** Extract search query from URL params */
|
|
111
|
+
private extractSearchQuery;
|
|
112
|
+
/**
|
|
113
|
+
* Get Li2 click ID from existing SDK cookie management.
|
|
114
|
+
* Priority: URL param `uid` → cookie `li_cid` → legacy cookie `li2_id`
|
|
115
|
+
* This matches the exact resolution order in li2-analytics/src/index.ts
|
|
116
|
+
*/
|
|
117
|
+
private getLi2Cid;
|
|
118
|
+
/** Debug logger */
|
|
119
|
+
private log;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { PageviewTracker as P, type PageviewConfig as a, type PageviewEvent as b, type PageviewBatchPayload as c };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,92 @@
|
|
|
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-B3dzYzIM.mjs';
|
|
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
|
+
export { ClickTrackerConfig } from './click-tracker/index.mjs';
|
|
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
|
+
}
|
|
4
90
|
|
|
5
91
|
/**
|
|
6
92
|
* Li2 Analytics SDK
|
|
@@ -145,6 +231,7 @@ declare class Li2Analytics {
|
|
|
145
231
|
private clickId;
|
|
146
232
|
private cookieOptions;
|
|
147
233
|
private autoEventTracker;
|
|
234
|
+
private clickTracker;
|
|
148
235
|
pageview: PageviewTracker | null;
|
|
149
236
|
constructor(config?: Li2Config);
|
|
150
237
|
private log;
|
|
@@ -172,6 +259,23 @@ declare class Li2Analytics {
|
|
|
172
259
|
cookieDomain?: string;
|
|
173
260
|
cookiePath?: string;
|
|
174
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>;
|
|
175
279
|
/**
|
|
176
280
|
* Manually track a pageview (convenience method)
|
|
177
281
|
*/
|
|
@@ -180,6 +284,13 @@ declare class Li2Analytics {
|
|
|
180
284
|
pageTitle?: string;
|
|
181
285
|
customData?: Record<string, unknown>;
|
|
182
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>;
|
|
183
294
|
/**
|
|
184
295
|
* Set cookie options for customizing cookie behavior
|
|
185
296
|
* If a clickId already exists, the cookie will be re-set with the new options
|
|
@@ -310,6 +421,13 @@ declare function trackPageview(options?: {
|
|
|
310
421
|
pageTitle?: string;
|
|
311
422
|
customData?: Record<string, unknown>;
|
|
312
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>;
|
|
313
431
|
|
|
314
432
|
/**
|
|
315
433
|
* Initialize the server-side Li2 Analytics SDK
|
|
@@ -321,6 +439,7 @@ declare const _default: {
|
|
|
321
439
|
getInstance: typeof getInstance;
|
|
322
440
|
trackLead: typeof trackLead;
|
|
323
441
|
trackSale: typeof trackSale;
|
|
442
|
+
trackEvent: typeof trackEvent;
|
|
324
443
|
identify: typeof identify;
|
|
325
444
|
isTrackingAvailable: typeof isTrackingAvailable;
|
|
326
445
|
getClickId: typeof getClickId;
|
|
@@ -328,4 +447,4 @@ declare const _default: {
|
|
|
328
447
|
initServer: typeof initServer;
|
|
329
448
|
};
|
|
330
449
|
|
|
331
|
-
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, trackPageview, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,92 @@
|
|
|
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-B3dzYzIM.js';
|
|
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
|
+
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
|
+
}
|
|
4
90
|
|
|
5
91
|
/**
|
|
6
92
|
* Li2 Analytics SDK
|
|
@@ -145,6 +231,7 @@ declare class Li2Analytics {
|
|
|
145
231
|
private clickId;
|
|
146
232
|
private cookieOptions;
|
|
147
233
|
private autoEventTracker;
|
|
234
|
+
private clickTracker;
|
|
148
235
|
pageview: PageviewTracker | null;
|
|
149
236
|
constructor(config?: Li2Config);
|
|
150
237
|
private log;
|
|
@@ -172,6 +259,23 @@ declare class Li2Analytics {
|
|
|
172
259
|
cookieDomain?: string;
|
|
173
260
|
cookiePath?: string;
|
|
174
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>;
|
|
175
279
|
/**
|
|
176
280
|
* Manually track a pageview (convenience method)
|
|
177
281
|
*/
|
|
@@ -180,6 +284,13 @@ declare class Li2Analytics {
|
|
|
180
284
|
pageTitle?: string;
|
|
181
285
|
customData?: Record<string, unknown>;
|
|
182
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>;
|
|
183
294
|
/**
|
|
184
295
|
* Set cookie options for customizing cookie behavior
|
|
185
296
|
* If a clickId already exists, the cookie will be re-set with the new options
|
|
@@ -310,6 +421,13 @@ declare function trackPageview(options?: {
|
|
|
310
421
|
pageTitle?: string;
|
|
311
422
|
customData?: Record<string, unknown>;
|
|
312
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>;
|
|
313
431
|
|
|
314
432
|
/**
|
|
315
433
|
* Initialize the server-side Li2 Analytics SDK
|
|
@@ -321,6 +439,7 @@ declare const _default: {
|
|
|
321
439
|
getInstance: typeof getInstance;
|
|
322
440
|
trackLead: typeof trackLead;
|
|
323
441
|
trackSale: typeof trackSale;
|
|
442
|
+
trackEvent: typeof trackEvent;
|
|
324
443
|
identify: typeof identify;
|
|
325
444
|
isTrackingAvailable: typeof isTrackingAvailable;
|
|
326
445
|
getClickId: typeof getClickId;
|
|
@@ -328,4 +447,4 @@ declare const _default: {
|
|
|
328
447
|
initServer: typeof initServer;
|
|
329
448
|
};
|
|
330
449
|
|
|
331
|
-
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, trackPageview, 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 };
|