@li2/analytics 0.2.2 → 0.3.0-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/README.md +69 -0
- package/dist/auto-events.d.mts +1 -0
- package/dist/auto-events.d.ts +1 -0
- 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-MURA7RU5.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-DEfkJIjF.d.mts +114 -0
- package/dist/index-DEfkJIjF.d.ts +114 -0
- package/dist/index.d.mts +43 -1
- package/dist/index.d.ts +43 -1
- 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 -0
- package/dist/pageview/index.d.ts +1 -0
- package/dist/pageview/index.global.js +1 -0
- package/dist/pageview/index.js +1 -0
- package/dist/pageview/index.mjs +1 -0
- package/package.json +50 -39
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
}
|
|
64
|
+
/** Batch payload sent to the server */
|
|
65
|
+
interface PageviewBatchPayload {
|
|
66
|
+
pageviews: PageviewEvent[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare class PageviewTracker {
|
|
70
|
+
private config;
|
|
71
|
+
private pageDetector;
|
|
72
|
+
private sessionManager;
|
|
73
|
+
private batchSender;
|
|
74
|
+
private enabled;
|
|
75
|
+
private lastPageUrl;
|
|
76
|
+
private lastPageTimestamp;
|
|
77
|
+
constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, 'apiUrl' | 'publishableKey'>);
|
|
78
|
+
/** Start tracking pageviews */
|
|
79
|
+
start(): void;
|
|
80
|
+
/** Stop tracking pageviews */
|
|
81
|
+
stop(): void;
|
|
82
|
+
/** Enable pageview tracking */
|
|
83
|
+
enable(): void;
|
|
84
|
+
/** Disable pageview tracking */
|
|
85
|
+
disable(): void;
|
|
86
|
+
/** Force start a new session */
|
|
87
|
+
newSession(): void;
|
|
88
|
+
/** Manually track a pageview (for advanced use cases) */
|
|
89
|
+
trackPageview(options?: {
|
|
90
|
+
pageUrl?: string;
|
|
91
|
+
pageTitle?: string;
|
|
92
|
+
customData?: Record<string, unknown>;
|
|
93
|
+
}): void;
|
|
94
|
+
/** Handle page change event from PageDetector */
|
|
95
|
+
private handlePageChange;
|
|
96
|
+
/** Build a PageviewEvent from current state */
|
|
97
|
+
private buildPageviewEvent;
|
|
98
|
+
/** Track the current page (called on init) */
|
|
99
|
+
private trackCurrentPage;
|
|
100
|
+
/** Check if a path matches any exclude pattern */
|
|
101
|
+
private isExcluded;
|
|
102
|
+
/** Extract search query from URL params */
|
|
103
|
+
private extractSearchQuery;
|
|
104
|
+
/**
|
|
105
|
+
* Get Li2 click ID from existing SDK cookie management.
|
|
106
|
+
* Priority: URL param `uid` → cookie `li_cid` → legacy cookie `li2_id`
|
|
107
|
+
* This matches the exact resolution order in li2-analytics/src/index.ts
|
|
108
|
+
*/
|
|
109
|
+
private getLi2Cid;
|
|
110
|
+
/** Debug logger */
|
|
111
|
+
private log;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { PageviewTracker as P, type PageviewConfig as a, type PageviewEvent as b, type PageviewBatchPayload as c };
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
}
|
|
64
|
+
/** Batch payload sent to the server */
|
|
65
|
+
interface PageviewBatchPayload {
|
|
66
|
+
pageviews: PageviewEvent[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare class PageviewTracker {
|
|
70
|
+
private config;
|
|
71
|
+
private pageDetector;
|
|
72
|
+
private sessionManager;
|
|
73
|
+
private batchSender;
|
|
74
|
+
private enabled;
|
|
75
|
+
private lastPageUrl;
|
|
76
|
+
private lastPageTimestamp;
|
|
77
|
+
constructor(config: Partial<PageviewConfig> & Pick<PageviewConfig, 'apiUrl' | 'publishableKey'>);
|
|
78
|
+
/** Start tracking pageviews */
|
|
79
|
+
start(): void;
|
|
80
|
+
/** Stop tracking pageviews */
|
|
81
|
+
stop(): void;
|
|
82
|
+
/** Enable pageview tracking */
|
|
83
|
+
enable(): void;
|
|
84
|
+
/** Disable pageview tracking */
|
|
85
|
+
disable(): void;
|
|
86
|
+
/** Force start a new session */
|
|
87
|
+
newSession(): void;
|
|
88
|
+
/** Manually track a pageview (for advanced use cases) */
|
|
89
|
+
trackPageview(options?: {
|
|
90
|
+
pageUrl?: string;
|
|
91
|
+
pageTitle?: string;
|
|
92
|
+
customData?: Record<string, unknown>;
|
|
93
|
+
}): void;
|
|
94
|
+
/** Handle page change event from PageDetector */
|
|
95
|
+
private handlePageChange;
|
|
96
|
+
/** Build a PageviewEvent from current state */
|
|
97
|
+
private buildPageviewEvent;
|
|
98
|
+
/** Track the current page (called on init) */
|
|
99
|
+
private trackCurrentPage;
|
|
100
|
+
/** Check if a path matches any exclude pattern */
|
|
101
|
+
private isExcluded;
|
|
102
|
+
/** Extract search query from URL params */
|
|
103
|
+
private extractSearchQuery;
|
|
104
|
+
/**
|
|
105
|
+
* Get Li2 click ID from existing SDK cookie management.
|
|
106
|
+
* Priority: URL param `uid` → cookie `li_cid` → legacy cookie `li2_id`
|
|
107
|
+
* This matches the exact resolution order in li2-analytics/src/index.ts
|
|
108
|
+
*/
|
|
109
|
+
private getLi2Cid;
|
|
110
|
+
/** Debug logger */
|
|
111
|
+
private log;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { PageviewTracker as P, type PageviewConfig as a, type PageviewEvent as b, type PageviewBatchPayload as c };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { P as PageviewTracker } from './index-DEfkJIjF.mjs';
|
|
2
|
+
export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-DEfkJIjF.mjs';
|
|
1
3
|
export { AnalyticsSettings, AutoEvent, ConditionOperator, ConditionType, EventAction, EventActionType, EventTrigger, TriggerCondition, TriggerType } from './auto-events.mjs';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Li2 Analytics SDK
|
|
5
7
|
* Conversion tracking for li2.ai
|
|
6
8
|
*/
|
|
9
|
+
|
|
7
10
|
interface Li2Config {
|
|
8
11
|
/** Publishable key from your organization's analytics settings */
|
|
9
12
|
publishableKey?: string;
|
|
@@ -142,12 +145,41 @@ declare class Li2Analytics {
|
|
|
142
145
|
private clickId;
|
|
143
146
|
private cookieOptions;
|
|
144
147
|
private autoEventTracker;
|
|
148
|
+
pageview: PageviewTracker | null;
|
|
145
149
|
constructor(config?: Li2Config);
|
|
146
150
|
private log;
|
|
147
151
|
/**
|
|
148
152
|
* Initialize auto-event tracking
|
|
149
153
|
*/
|
|
150
154
|
private initAutoEventTracking;
|
|
155
|
+
/**
|
|
156
|
+
* Initialize pageview tracking from data-attributes or config.
|
|
157
|
+
* Uses dynamic import to lazy-load the pageview module only when enabled.
|
|
158
|
+
* @internal Called from auto-init block - not part of public API
|
|
159
|
+
*/
|
|
160
|
+
initPageviewTracking(pageviewConfig: Record<string, string>): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Enable pageview tracking programmatically (for users not using data-attributes)
|
|
163
|
+
*/
|
|
164
|
+
enablePageviewTracking(options?: {
|
|
165
|
+
spaMode?: "auto" | "manual" | "disabled";
|
|
166
|
+
excludePatterns?: string[];
|
|
167
|
+
trackHashChanges?: boolean;
|
|
168
|
+
sessionTimeout?: number;
|
|
169
|
+
cookieLessMode?: boolean;
|
|
170
|
+
batchInterval?: number;
|
|
171
|
+
searchParams?: string[];
|
|
172
|
+
cookieDomain?: string;
|
|
173
|
+
cookiePath?: string;
|
|
174
|
+
}): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Manually track a pageview (convenience method)
|
|
177
|
+
*/
|
|
178
|
+
trackPageview(options?: {
|
|
179
|
+
pageUrl?: string;
|
|
180
|
+
pageTitle?: string;
|
|
181
|
+
customData?: Record<string, unknown>;
|
|
182
|
+
}): void;
|
|
151
183
|
/**
|
|
152
184
|
* Set cookie options for customizing cookie behavior
|
|
153
185
|
* If a clickId already exists, the cookie will be re-set with the new options
|
|
@@ -269,6 +301,15 @@ declare function identify(params: {
|
|
|
269
301
|
customerId?: string;
|
|
270
302
|
message?: string;
|
|
271
303
|
}>;
|
|
304
|
+
/**
|
|
305
|
+
* Track a pageview manually
|
|
306
|
+
* Convenience function that uses the singleton instance
|
|
307
|
+
*/
|
|
308
|
+
declare function trackPageview(options?: {
|
|
309
|
+
pageUrl?: string;
|
|
310
|
+
pageTitle?: string;
|
|
311
|
+
customData?: Record<string, unknown>;
|
|
312
|
+
}): void;
|
|
272
313
|
|
|
273
314
|
/**
|
|
274
315
|
* Initialize the server-side Li2 Analytics SDK
|
|
@@ -283,7 +324,8 @@ declare const _default: {
|
|
|
283
324
|
identify: typeof identify;
|
|
284
325
|
isTrackingAvailable: typeof isTrackingAvailable;
|
|
285
326
|
getClickId: typeof getClickId;
|
|
327
|
+
trackPageview: typeof trackPageview;
|
|
286
328
|
initServer: typeof initServer;
|
|
287
329
|
};
|
|
288
330
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { P as PageviewTracker } from './index-DEfkJIjF.js';
|
|
2
|
+
export { c as PageviewBatchPayload, a as PageviewConfig, b as PageviewEvent } from './index-DEfkJIjF.js';
|
|
1
3
|
export { AnalyticsSettings, AutoEvent, ConditionOperator, ConditionType, EventAction, EventActionType, EventTrigger, TriggerCondition, TriggerType } from './auto-events.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Li2 Analytics SDK
|
|
5
7
|
* Conversion tracking for li2.ai
|
|
6
8
|
*/
|
|
9
|
+
|
|
7
10
|
interface Li2Config {
|
|
8
11
|
/** Publishable key from your organization's analytics settings */
|
|
9
12
|
publishableKey?: string;
|
|
@@ -142,12 +145,41 @@ declare class Li2Analytics {
|
|
|
142
145
|
private clickId;
|
|
143
146
|
private cookieOptions;
|
|
144
147
|
private autoEventTracker;
|
|
148
|
+
pageview: PageviewTracker | null;
|
|
145
149
|
constructor(config?: Li2Config);
|
|
146
150
|
private log;
|
|
147
151
|
/**
|
|
148
152
|
* Initialize auto-event tracking
|
|
149
153
|
*/
|
|
150
154
|
private initAutoEventTracking;
|
|
155
|
+
/**
|
|
156
|
+
* Initialize pageview tracking from data-attributes or config.
|
|
157
|
+
* Uses dynamic import to lazy-load the pageview module only when enabled.
|
|
158
|
+
* @internal Called from auto-init block - not part of public API
|
|
159
|
+
*/
|
|
160
|
+
initPageviewTracking(pageviewConfig: Record<string, string>): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Enable pageview tracking programmatically (for users not using data-attributes)
|
|
163
|
+
*/
|
|
164
|
+
enablePageviewTracking(options?: {
|
|
165
|
+
spaMode?: "auto" | "manual" | "disabled";
|
|
166
|
+
excludePatterns?: string[];
|
|
167
|
+
trackHashChanges?: boolean;
|
|
168
|
+
sessionTimeout?: number;
|
|
169
|
+
cookieLessMode?: boolean;
|
|
170
|
+
batchInterval?: number;
|
|
171
|
+
searchParams?: string[];
|
|
172
|
+
cookieDomain?: string;
|
|
173
|
+
cookiePath?: string;
|
|
174
|
+
}): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Manually track a pageview (convenience method)
|
|
177
|
+
*/
|
|
178
|
+
trackPageview(options?: {
|
|
179
|
+
pageUrl?: string;
|
|
180
|
+
pageTitle?: string;
|
|
181
|
+
customData?: Record<string, unknown>;
|
|
182
|
+
}): void;
|
|
151
183
|
/**
|
|
152
184
|
* Set cookie options for customizing cookie behavior
|
|
153
185
|
* If a clickId already exists, the cookie will be re-set with the new options
|
|
@@ -269,6 +301,15 @@ declare function identify(params: {
|
|
|
269
301
|
customerId?: string;
|
|
270
302
|
message?: string;
|
|
271
303
|
}>;
|
|
304
|
+
/**
|
|
305
|
+
* Track a pageview manually
|
|
306
|
+
* Convenience function that uses the singleton instance
|
|
307
|
+
*/
|
|
308
|
+
declare function trackPageview(options?: {
|
|
309
|
+
pageUrl?: string;
|
|
310
|
+
pageTitle?: string;
|
|
311
|
+
customData?: Record<string, unknown>;
|
|
312
|
+
}): void;
|
|
272
313
|
|
|
273
314
|
/**
|
|
274
315
|
* Initialize the server-side Li2 Analytics SDK
|
|
@@ -283,7 +324,8 @@ declare const _default: {
|
|
|
283
324
|
identify: typeof identify;
|
|
284
325
|
isTrackingAvailable: typeof isTrackingAvailable;
|
|
285
326
|
getClickId: typeof getClickId;
|
|
327
|
+
trackPageview: typeof trackPageview;
|
|
286
328
|
initServer: typeof initServer;
|
|
287
329
|
};
|
|
288
330
|
|
|
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 };
|
|
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 };
|