@v-tilt/browser 1.1.0 → 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.
@@ -1,72 +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
- projectId: string;
17
+ /** Project identifier (required) */
3
18
  token: string;
4
- name?: string;
5
- host?: string;
6
- scriptHost?: string;
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
- storage?: "cookie" | "localStorage" | "sessionStorage";
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
- webVitals?: boolean;
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
- persistence?: "localStorage" | "cookie";
15
- crossSubdomainCookie?: boolean;
16
- disable_compression?: boolean;
17
- }
18
- interface SessionData {
19
- value: string;
20
- expiry: number;
21
- }
22
- interface WebVitalMetric {
23
- name: string;
24
- value: number;
25
- delta: number;
26
- rating: string;
27
- id: string;
28
- navigationType: string;
29
- }
30
- interface GeolocationData {
31
- country?: string;
32
- 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;
33
82
  }
34
83
  interface EventPayload {
35
84
  [key: string]: any;
36
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
+ }
37
104
  interface TrackingEvent {
38
105
  timestamp: string;
39
106
  event: string;
40
107
  project_id: string;
41
108
  domain: string;
42
- payload: EventPayload;
43
- distinct_id?: string;
109
+ distinct_id: string;
44
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;
45
116
  }
46
- type StorageMethod = "cookie" | "localStorage" | "sessionStorage";
47
- interface StorageMethods {
48
- cookie: "cookie";
49
- localStorage: "localStorage";
50
- sessionStorage: "sessionStorage";
117
+ interface PropertyOperations {
118
+ $set?: Properties;
119
+ $set_once?: Properties;
120
+ $unset?: string[];
51
121
  }
122
+ interface SessionData {
123
+ value: string;
124
+ expiry: number;
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 */
52
137
  interface UserIdentity {
138
+ /** Current distinct ID (null if anonymous) */
53
139
  distinct_id: string | null;
140
+ /** Anonymous ID (always present) */
54
141
  anonymous_id: string;
142
+ /** Device ID (persists across sessions) */
55
143
  device_id: string;
56
- properties: Record<string, any>;
57
- user_state: "anonymous" | "identified";
144
+ /** User properties */
145
+ properties: Properties;
146
+ /** Identity state */
147
+ user_state: 'anonymous' | 'identified';
58
148
  }
59
149
  interface UserProperties {
60
150
  [key: string]: any;
61
151
  }
62
- interface PropertyOperations {
63
- $set?: Record<string, any>;
64
- $set_once?: Record<string, any>;
65
- }
66
152
  interface AliasEvent {
67
153
  distinct_id: string;
68
154
  original: string;
69
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
+ }
70
194
 
71
195
  /**
72
196
  * This class is used to capture pageview events when the user navigates using the history API (pushState, replaceState)
@@ -115,11 +239,11 @@ declare class VTilt {
115
239
  private rateLimiter;
116
240
  historyAutocapture?: HistoryAutocapture;
117
241
  __loaded: boolean;
118
- private _initialPageviewCaptured;
119
- private _visibilityStateListener;
242
+ private _initial_pageview_captured;
243
+ private _visibility_state_listener;
120
244
  __request_queue: QueuedRequest[];
121
- private _hasWarnedAboutConfig;
122
- private _setOncePropertiesSent;
245
+ private _has_warned_about_config;
246
+ private _set_once_properties_sent;
123
247
  constructor(config?: Partial<VTiltConfig>);
124
248
  /**
125
249
  * Initializes a new instance of the VTilt tracking object.
@@ -157,11 +281,17 @@ declare class VTilt {
157
281
  * This internal method should only be called by `init()`.
158
282
  */
159
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;
160
290
  /**
161
291
  * Set up handler to flush event queue on page unload
162
292
  * Uses both beforeunload and pagehide for maximum compatibility
163
293
  */
164
- private _setupUnloadHandler;
294
+ private _setup_unload_handler;
165
295
  /**
166
296
  * Returns a string representation of the instance name
167
297
  * Used for debugging and logging
@@ -179,7 +309,7 @@ declare class VTilt {
179
309
  * Returns true if projectId and token are present, false otherwise
180
310
  * Logs a warning only once per instance if not configured
181
311
  */
182
- private _isConfigured;
312
+ private _is_configured;
183
313
  /**
184
314
  * Build the tracking URL with token in query parameters
185
315
  */
@@ -195,18 +325,18 @@ declare class VTilt {
195
325
  * Called by RequestQueue when flushing
196
326
  * Uses RetryQueue for automatic retry on failure
197
327
  */
198
- private _sendBatchedRequest;
328
+ private _send_batched_request;
199
329
  /**
200
330
  * Send HTTP request and return status code
201
331
  * Uses GZip compression for payloads > 1KB
202
332
  * Used by RetryQueue for retryable requests
203
333
  */
204
- private _sendHttpRequest;
334
+ private _send_http_request;
205
335
  /**
206
336
  * Send request using sendBeacon for reliable delivery on page unload
207
337
  * Uses GZip compression for payloads > 1KB
208
338
  */
209
- private _sendBeaconRequest;
339
+ private _send_beacon_request;
210
340
  /**
211
341
  * Send a queued request (called after DOM is loaded)
212
342
  */
@@ -229,7 +359,7 @@ declare class VTilt {
229
359
  * Internal capture method that bypasses rate limiting
230
360
  * Used for system events like rate limit warnings
231
361
  */
232
- private _captureInternal;
362
+ private _capture_internal;
233
363
  /**
234
364
  * Track a custom event (alias for capture)
235
365
  */
@@ -323,8 +453,9 @@ declare class VTilt {
323
453
  createAlias(alias: string, original?: string): void;
324
454
  /**
325
455
  * Capture initial pageview with visibility check
456
+ * Note: The capture_pageview config check happens at the call site (in _init)
326
457
  */
327
- private _captureInitialPageview;
458
+ private _capture_initial_pageview;
328
459
  /**
329
460
  * Get current configuration
330
461
  */
@@ -351,6 +482,7 @@ declare class VTilt {
351
482
  _execute_array(array: any[]): void;
352
483
  /**
353
484
  * Called when DOM is loaded - processes queued requests and enables batching
485
+ * Following PostHog's pattern in _dom_loaded()
354
486
  */
355
487
  _dom_loaded(): void;
356
488
  }
@@ -358,4 +490,4 @@ declare class VTilt {
358
490
  declare const vt: VTilt;
359
491
 
360
492
  export { VTilt, vt as default, vt };
361
- export type { AliasEvent, EventPayload, GeolocationData, PropertyOperations, SessionData, StorageMethod, StorageMethods, TrackingEvent, UserIdentity, UserProperties, VTiltConfig, WebVitalMetric };
493
+ export type { AliasEvent, CaptureOptions, CaptureResult, EventPayload, FeatureFlagsConfig, GeolocationData, GroupsConfig, PersistenceMethod, Properties, Property, PropertyOperations, RemoteConfig, RequestOptions, SessionData, SessionIdChangedCallback, TrackingEvent, UserIdentity, UserProperties, VTiltConfig, WebVitalMetric };