@v-tilt/browser 1.0.11 → 1.1.1
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/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/constants.d.ts +172 -10
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +230 -46
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +230 -46
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/rate-limiter.d.ts +52 -0
- package/dist/request-queue.d.ts +78 -0
- package/dist/request.d.ts +54 -0
- package/dist/retry-queue.d.ts +64 -0
- package/dist/session.d.ts +2 -2
- package/dist/types.d.ts +154 -37
- package/dist/user-manager.d.ts +2 -2
- package/dist/vtilt.d.ts +51 -12
- package/lib/config.js +6 -13
- package/lib/constants.d.ts +172 -10
- package/lib/constants.js +644 -439
- package/lib/rate-limiter.d.ts +52 -0
- package/lib/rate-limiter.js +80 -0
- package/lib/request-queue.d.ts +78 -0
- package/lib/request-queue.js +156 -0
- package/lib/request.d.ts +54 -0
- package/lib/request.js +265 -0
- package/lib/retry-queue.d.ts +64 -0
- package/lib/retry-queue.js +182 -0
- package/lib/session.d.ts +2 -2
- package/lib/session.js +3 -3
- package/lib/types.d.ts +154 -37
- package/lib/types.js +6 -0
- package/lib/user-manager.d.ts +2 -2
- package/lib/user-manager.js +38 -11
- package/lib/utils/event-utils.js +88 -82
- package/lib/utils/index.js +2 -2
- package/lib/utils/request-utils.js +21 -19
- package/lib/vtilt.d.ts +51 -12
- package/lib/vtilt.js +199 -40
- package/lib/web-vitals.js +1 -1
- package/package.json +2 -1
|
@@ -1,71 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Person profiles configuration mode
|
|
3
|
+
* - 'always': Always create person profiles (default)
|
|
4
|
+
* - 'identified_only': Only create profiles when user is identified
|
|
5
|
+
* - 'never': Never create person profiles (events only)
|
|
6
|
+
*/
|
|
7
|
+
type PersonProfilesMode = 'always' | 'identified_only' | 'never';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* VTilt Types
|
|
11
|
+
*
|
|
12
|
+
* Type definitions for the VTilt tracking SDK.
|
|
13
|
+
* Following PostHog's patterns where applicable.
|
|
14
|
+
*/
|
|
15
|
+
|
|
1
16
|
interface VTiltConfig {
|
|
2
|
-
|
|
17
|
+
/** Project identifier (required) */
|
|
3
18
|
token: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
19
|
+
/** API host for tracking (default: https://api.vtilt.io) */
|
|
20
|
+
api_host?: string;
|
|
21
|
+
/** UI host for dashboard links */
|
|
22
|
+
ui_host?: string | null;
|
|
23
|
+
/** Proxy domain for tracking requests */
|
|
7
24
|
proxy?: string;
|
|
25
|
+
/** Full proxy URL for tracking requests */
|
|
8
26
|
proxyUrl?: string;
|
|
27
|
+
/** Instance name (for multiple instances) */
|
|
28
|
+
name?: string;
|
|
29
|
+
/** Project ID (set via init() first argument) */
|
|
30
|
+
projectId?: string;
|
|
31
|
+
/** Domain to track (auto-detected if not provided) */
|
|
9
32
|
domain?: string;
|
|
10
|
-
|
|
33
|
+
/** Storage method for session data */
|
|
34
|
+
storage?: PersistenceMethod;
|
|
35
|
+
/** Persistence method for user data */
|
|
36
|
+
persistence?: PersistenceMethod;
|
|
37
|
+
/** Persistence name prefix */
|
|
38
|
+
persistence_name?: string;
|
|
39
|
+
/** Enable cross-subdomain cookies */
|
|
40
|
+
cross_subdomain_cookie?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Person profiles mode:
|
|
43
|
+
* - 'always': Always create person profiles (default)
|
|
44
|
+
* - 'identified_only': Only create when user is identified
|
|
45
|
+
* - 'never': Never create person profiles
|
|
46
|
+
*/
|
|
47
|
+
person_profiles?: PersonProfilesMode;
|
|
48
|
+
/** Enable autocapture */
|
|
49
|
+
autocapture?: boolean;
|
|
50
|
+
/** Enable web vitals tracking */
|
|
51
|
+
capture_performance?: boolean;
|
|
52
|
+
/** Enable page view tracking */
|
|
53
|
+
capture_pageview?: boolean | 'auto';
|
|
54
|
+
/** Enable page leave tracking */
|
|
55
|
+
capture_pageleave?: boolean | 'if_capture_pageview';
|
|
56
|
+
/** Disable compression */
|
|
57
|
+
disable_compression?: boolean;
|
|
58
|
+
/** Whether to stringify payload before sending */
|
|
11
59
|
stringifyPayload?: boolean;
|
|
12
|
-
|
|
60
|
+
/** Properties to exclude from events */
|
|
61
|
+
property_denylist?: string[];
|
|
62
|
+
/** Mask text in autocapture */
|
|
63
|
+
mask_all_text?: boolean;
|
|
64
|
+
/** Mask all element attributes */
|
|
65
|
+
mask_all_element_attributes?: boolean;
|
|
66
|
+
/** Respect Do Not Track browser setting */
|
|
67
|
+
respect_dnt?: boolean;
|
|
68
|
+
/** Opt users out by default */
|
|
69
|
+
opt_out_capturing_by_default?: boolean;
|
|
70
|
+
/** Global attributes added to all events */
|
|
13
71
|
globalAttributes?: Record<string, string>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
delta: number;
|
|
25
|
-
rating: string;
|
|
26
|
-
id: string;
|
|
27
|
-
navigationType: string;
|
|
28
|
-
}
|
|
29
|
-
interface GeolocationData {
|
|
30
|
-
country?: string;
|
|
31
|
-
locale?: string;
|
|
72
|
+
/** Bootstrap data for initialization */
|
|
73
|
+
bootstrap?: {
|
|
74
|
+
distinctID?: string;
|
|
75
|
+
isIdentifiedID?: boolean;
|
|
76
|
+
featureFlags?: Record<string, boolean | string>;
|
|
77
|
+
};
|
|
78
|
+
/** Before send hook for modifying events */
|
|
79
|
+
before_send?: (event: CaptureResult) => CaptureResult | null;
|
|
80
|
+
/** Loaded callback */
|
|
81
|
+
loaded?: (vtilt: any) => void;
|
|
32
82
|
}
|
|
33
83
|
interface EventPayload {
|
|
34
84
|
[key: string]: any;
|
|
35
85
|
}
|
|
86
|
+
interface CaptureResult {
|
|
87
|
+
uuid: string;
|
|
88
|
+
event: string;
|
|
89
|
+
properties: Properties;
|
|
90
|
+
$set?: Properties;
|
|
91
|
+
$set_once?: Properties;
|
|
92
|
+
timestamp?: string;
|
|
93
|
+
}
|
|
94
|
+
interface CaptureOptions {
|
|
95
|
+
/** Override timestamp */
|
|
96
|
+
timestamp?: Date;
|
|
97
|
+
/** Properties to $set on person */
|
|
98
|
+
$set?: Properties;
|
|
99
|
+
/** Properties to $set_once on person */
|
|
100
|
+
$set_once?: Properties;
|
|
101
|
+
/** Send immediately (skip batching) */
|
|
102
|
+
send_instantly?: boolean;
|
|
103
|
+
}
|
|
36
104
|
interface TrackingEvent {
|
|
37
105
|
timestamp: string;
|
|
38
106
|
event: string;
|
|
39
107
|
project_id: string;
|
|
40
108
|
domain: string;
|
|
41
|
-
|
|
42
|
-
distinct_id?: string;
|
|
109
|
+
distinct_id: string;
|
|
43
110
|
anonymous_id?: string;
|
|
111
|
+
payload: EventPayload;
|
|
112
|
+
}
|
|
113
|
+
type Property = string | number | boolean | null | undefined | Date | any[] | Record<string, any>;
|
|
114
|
+
interface Properties {
|
|
115
|
+
[key: string]: Property;
|
|
44
116
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
117
|
+
interface PropertyOperations {
|
|
118
|
+
$set?: Properties;
|
|
119
|
+
$set_once?: Properties;
|
|
120
|
+
$unset?: string[];
|
|
121
|
+
}
|
|
122
|
+
interface SessionData {
|
|
123
|
+
value: string;
|
|
124
|
+
expiry: number;
|
|
50
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Persistence method for user/session data
|
|
128
|
+
* Following PostHog's approach:
|
|
129
|
+
* - 'localStorage+cookie': Stores limited data in cookies, rest in localStorage (default)
|
|
130
|
+
* - 'cookie': Stores all data in cookies
|
|
131
|
+
* - 'localStorage': Stores all data in localStorage
|
|
132
|
+
* - 'sessionStorage': Stores all data in sessionStorage
|
|
133
|
+
* - 'memory': Stores all data in memory only (no persistence)
|
|
134
|
+
*/
|
|
135
|
+
type PersistenceMethod = 'localStorage+cookie' | 'cookie' | 'localStorage' | 'sessionStorage' | 'memory';
|
|
136
|
+
/** User identity state */
|
|
51
137
|
interface UserIdentity {
|
|
138
|
+
/** Current distinct ID (null if anonymous) */
|
|
52
139
|
distinct_id: string | null;
|
|
140
|
+
/** Anonymous ID (always present) */
|
|
53
141
|
anonymous_id: string;
|
|
142
|
+
/** Device ID (persists across sessions) */
|
|
54
143
|
device_id: string;
|
|
55
|
-
properties
|
|
56
|
-
|
|
144
|
+
/** User properties */
|
|
145
|
+
properties: Properties;
|
|
146
|
+
/** Identity state */
|
|
147
|
+
user_state: 'anonymous' | 'identified';
|
|
57
148
|
}
|
|
58
149
|
interface UserProperties {
|
|
59
150
|
[key: string]: any;
|
|
60
151
|
}
|
|
61
|
-
interface PropertyOperations {
|
|
62
|
-
$set?: Record<string, any>;
|
|
63
|
-
$set_once?: Record<string, any>;
|
|
64
|
-
}
|
|
65
152
|
interface AliasEvent {
|
|
66
153
|
distinct_id: string;
|
|
67
154
|
original: string;
|
|
68
155
|
}
|
|
156
|
+
interface WebVitalMetric {
|
|
157
|
+
name: string;
|
|
158
|
+
value: number;
|
|
159
|
+
delta: number;
|
|
160
|
+
rating: 'good' | 'needs-improvement' | 'poor';
|
|
161
|
+
id: string;
|
|
162
|
+
navigationType: string;
|
|
163
|
+
}
|
|
164
|
+
interface GeolocationData {
|
|
165
|
+
country?: string;
|
|
166
|
+
locale?: string;
|
|
167
|
+
}
|
|
168
|
+
interface GroupsConfig {
|
|
169
|
+
[groupType: string]: string;
|
|
170
|
+
}
|
|
171
|
+
interface FeatureFlagsConfig {
|
|
172
|
+
[flagKey: string]: boolean | string;
|
|
173
|
+
}
|
|
174
|
+
type SessionIdChangedCallback = (newSessionId: string, previousSessionId: string | null, changeInfo: {
|
|
175
|
+
reason: 'timeout' | 'new_session' | 'reset';
|
|
176
|
+
}) => void;
|
|
177
|
+
interface RequestOptions {
|
|
178
|
+
method?: 'POST' | 'GET';
|
|
179
|
+
headers?: Record<string, string>;
|
|
180
|
+
timeout?: number;
|
|
181
|
+
retry?: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface RemoteConfig {
|
|
184
|
+
/** Default to identified_only mode */
|
|
185
|
+
defaultIdentifiedOnly?: boolean;
|
|
186
|
+
/** Feature flags */
|
|
187
|
+
featureFlags?: FeatureFlagsConfig;
|
|
188
|
+
/** Session recording config */
|
|
189
|
+
sessionRecording?: {
|
|
190
|
+
enabled?: boolean;
|
|
191
|
+
sampleRate?: number;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
69
194
|
|
|
70
195
|
/**
|
|
71
196
|
* This class is used to capture pageview events when the user navigates using the history API (pushState, replaceState)
|
|
@@ -84,21 +209,41 @@ declare class HistoryAutocapture {
|
|
|
84
209
|
private _setupPopstateListener;
|
|
85
210
|
}
|
|
86
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Request Queue - Event Batching (PostHog-style)
|
|
214
|
+
*
|
|
215
|
+
* Batches multiple events together and sends them at configurable intervals.
|
|
216
|
+
* This reduces the number of HTTP requests significantly for active users.
|
|
217
|
+
*
|
|
218
|
+
* Features:
|
|
219
|
+
* - Configurable flush interval (default 3 seconds)
|
|
220
|
+
* - Batches events by URL/batchKey
|
|
221
|
+
* - Uses sendBeacon on page unload for reliable delivery
|
|
222
|
+
* - Converts absolute timestamps to relative offsets before sending
|
|
223
|
+
*/
|
|
224
|
+
|
|
87
225
|
interface QueuedRequest {
|
|
88
226
|
url: string;
|
|
89
|
-
event:
|
|
227
|
+
event: TrackingEvent;
|
|
228
|
+
batchKey?: string;
|
|
229
|
+
transport?: "xhr" | "sendBeacon";
|
|
90
230
|
}
|
|
231
|
+
|
|
91
232
|
declare class VTilt {
|
|
92
233
|
private configManager;
|
|
93
234
|
private sessionManager;
|
|
94
235
|
private userManager;
|
|
95
236
|
private webVitalsManager;
|
|
237
|
+
private requestQueue;
|
|
238
|
+
private retryQueue;
|
|
239
|
+
private rateLimiter;
|
|
96
240
|
historyAutocapture?: HistoryAutocapture;
|
|
97
241
|
__loaded: boolean;
|
|
98
|
-
private
|
|
99
|
-
private
|
|
242
|
+
private _initial_pageview_captured;
|
|
243
|
+
private _visibility_state_listener;
|
|
100
244
|
__request_queue: QueuedRequest[];
|
|
101
|
-
private
|
|
245
|
+
private _has_warned_about_config;
|
|
246
|
+
private _set_once_properties_sent;
|
|
102
247
|
constructor(config?: Partial<VTiltConfig>);
|
|
103
248
|
/**
|
|
104
249
|
* Initializes a new instance of the VTilt tracking object.
|
|
@@ -136,6 +281,17 @@ declare class VTilt {
|
|
|
136
281
|
* This internal method should only be called by `init()`.
|
|
137
282
|
*/
|
|
138
283
|
private _init;
|
|
284
|
+
/**
|
|
285
|
+
* Start the request queue if user hasn't opted out
|
|
286
|
+
* Following PostHog's pattern - called from both _init() and _dom_loaded()
|
|
287
|
+
* Safe to call multiple times as enable() is idempotent
|
|
288
|
+
*/
|
|
289
|
+
private _start_queue_if_opted_in;
|
|
290
|
+
/**
|
|
291
|
+
* Set up handler to flush event queue on page unload
|
|
292
|
+
* Uses both beforeunload and pagehide for maximum compatibility
|
|
293
|
+
*/
|
|
294
|
+
private _setup_unload_handler;
|
|
139
295
|
/**
|
|
140
296
|
* Returns a string representation of the instance name
|
|
141
297
|
* Used for debugging and logging
|
|
@@ -153,7 +309,7 @@ declare class VTilt {
|
|
|
153
309
|
* Returns true if projectId and token are present, false otherwise
|
|
154
310
|
* Logs a warning only once per instance if not configured
|
|
155
311
|
*/
|
|
156
|
-
private
|
|
312
|
+
private _is_configured;
|
|
157
313
|
/**
|
|
158
314
|
* Build the tracking URL with token in query parameters
|
|
159
315
|
*/
|
|
@@ -161,8 +317,26 @@ declare class VTilt {
|
|
|
161
317
|
/**
|
|
162
318
|
* Send HTTP request
|
|
163
319
|
* This is the central entry point for all tracking requests
|
|
320
|
+
* Events are batched and sent every 3 seconds for better performance
|
|
164
321
|
*/
|
|
165
322
|
private sendRequest;
|
|
323
|
+
/**
|
|
324
|
+
* Send a batched request with multiple events
|
|
325
|
+
* Called by RequestQueue when flushing
|
|
326
|
+
* Uses RetryQueue for automatic retry on failure
|
|
327
|
+
*/
|
|
328
|
+
private _send_batched_request;
|
|
329
|
+
/**
|
|
330
|
+
* Send HTTP request and return status code
|
|
331
|
+
* Uses GZip compression for payloads > 1KB
|
|
332
|
+
* Used by RetryQueue for retryable requests
|
|
333
|
+
*/
|
|
334
|
+
private _send_http_request;
|
|
335
|
+
/**
|
|
336
|
+
* Send request using sendBeacon for reliable delivery on page unload
|
|
337
|
+
* Uses GZip compression for payloads > 1KB
|
|
338
|
+
*/
|
|
339
|
+
private _send_beacon_request;
|
|
166
340
|
/**
|
|
167
341
|
* Send a queued request (called after DOM is loaded)
|
|
168
342
|
*/
|
|
@@ -176,8 +350,16 @@ declare class VTilt {
|
|
|
176
350
|
*
|
|
177
351
|
* @param name - Event name
|
|
178
352
|
* @param payload - Event payload
|
|
353
|
+
* @param options - Optional capture options
|
|
354
|
+
*/
|
|
355
|
+
capture(name: string, payload: EventPayload, options?: {
|
|
356
|
+
skip_client_rate_limiting?: boolean;
|
|
357
|
+
}): void;
|
|
358
|
+
/**
|
|
359
|
+
* Internal capture method that bypasses rate limiting
|
|
360
|
+
* Used for system events like rate limit warnings
|
|
179
361
|
*/
|
|
180
|
-
|
|
362
|
+
private _capture_internal;
|
|
181
363
|
/**
|
|
182
364
|
* Track a custom event (alias for capture)
|
|
183
365
|
*/
|
|
@@ -271,8 +453,9 @@ declare class VTilt {
|
|
|
271
453
|
createAlias(alias: string, original?: string): void;
|
|
272
454
|
/**
|
|
273
455
|
* Capture initial pageview with visibility check
|
|
456
|
+
* Note: The capture_pageview config check happens at the call site (in _init)
|
|
274
457
|
*/
|
|
275
|
-
private
|
|
458
|
+
private _capture_initial_pageview;
|
|
276
459
|
/**
|
|
277
460
|
* Get current configuration
|
|
278
461
|
*/
|
|
@@ -298,7 +481,8 @@ declare class VTilt {
|
|
|
298
481
|
*/
|
|
299
482
|
_execute_array(array: any[]): void;
|
|
300
483
|
/**
|
|
301
|
-
* Called when DOM is loaded - processes queued requests
|
|
484
|
+
* Called when DOM is loaded - processes queued requests and enables batching
|
|
485
|
+
* Following PostHog's pattern in _dom_loaded()
|
|
302
486
|
*/
|
|
303
487
|
_dom_loaded(): void;
|
|
304
488
|
}
|
|
@@ -306,4 +490,4 @@ declare class VTilt {
|
|
|
306
490
|
declare const vt: VTilt;
|
|
307
491
|
|
|
308
492
|
export { VTilt, vt as default, vt };
|
|
309
|
-
export type { AliasEvent, EventPayload, GeolocationData, PropertyOperations,
|
|
493
|
+
export type { AliasEvent, CaptureOptions, CaptureResult, EventPayload, FeatureFlagsConfig, GeolocationData, GroupsConfig, PersistenceMethod, Properties, Property, PropertyOperations, RemoteConfig, RequestOptions, SessionData, SessionIdChangedCallback, TrackingEvent, UserIdentity, UserProperties, VTiltConfig, WebVitalMetric };
|