@v-tilt/browser 1.0.5 → 1.0.7

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/dist/array.js +1 -1
  3. package/dist/array.js.map +1 -1
  4. package/dist/array.no-external.js +1 -1
  5. package/dist/array.no-external.js.map +1 -1
  6. package/dist/constants.d.ts +2 -0
  7. package/dist/extensions/history-autocapture.d.ts +19 -0
  8. package/dist/main.js +1 -1
  9. package/dist/main.js.map +1 -1
  10. package/dist/module.d.ts +192 -18
  11. package/dist/module.js +1 -1
  12. package/dist/module.js.map +1 -1
  13. package/dist/module.no-external.d.ts +192 -18
  14. package/dist/module.no-external.js +1 -1
  15. package/dist/module.no-external.js.map +1 -1
  16. package/dist/session.d.ts +61 -4
  17. package/dist/tracking.d.ts +12 -4
  18. package/dist/types.d.ts +1 -1
  19. package/dist/utils/event-utils.d.ts +35 -0
  20. package/dist/utils/patch.d.ts +8 -0
  21. package/dist/utils/user-agent-utils.d.ts +18 -0
  22. package/dist/vtilt.d.ts +58 -20
  23. package/lib/constants.d.ts +2 -0
  24. package/lib/constants.js +3 -1
  25. package/lib/extensions/history-autocapture.d.ts +19 -0
  26. package/lib/extensions/history-autocapture.js +107 -0
  27. package/lib/session.d.ts +61 -4
  28. package/lib/session.js +197 -41
  29. package/lib/tracking.d.ts +12 -4
  30. package/lib/tracking.js +65 -70
  31. package/lib/types.d.ts +1 -1
  32. package/lib/utils/event-utils.d.ts +35 -0
  33. package/lib/utils/event-utils.js +178 -0
  34. package/lib/utils/patch.d.ts +8 -0
  35. package/lib/utils/patch.js +44 -0
  36. package/lib/utils/user-agent-utils.d.ts +18 -0
  37. package/lib/utils/user-agent-utils.js +423 -0
  38. package/lib/vtilt.d.ts +58 -20
  39. package/lib/vtilt.js +168 -142
  40. package/package.json +12 -13
  41. package/dist/utils.d.ts +0 -21
  42. package/lib/utils.d.ts +0 -21
  43. package/lib/utils.js +0 -57
package/dist/module.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  interface VTiltConfig {
2
2
  projectId: string;
3
3
  token: string;
4
+ name?: string;
4
5
  host?: string;
5
6
  scriptHost?: string;
6
7
  proxy?: string;
@@ -35,7 +36,6 @@ interface EventPayload {
35
36
  interface TrackingEvent {
36
37
  timestamp: string;
37
38
  event: string;
38
- session_id: string;
39
39
  tenant_id: string;
40
40
  domain: string;
41
41
  payload: EventPayload;
@@ -66,16 +66,197 @@ interface AliasEvent {
66
66
  original: string;
67
67
  }
68
68
 
69
+ interface QueuedRequest {
70
+ url: string;
71
+ event: any;
72
+ }
73
+ declare class TrackingManager {
74
+ private config;
75
+ private sessionManager;
76
+ private userManager;
77
+ __request_queue: QueuedRequest[];
78
+ private _hasWarnedAboutConfig;
79
+ constructor(config: VTiltConfig);
80
+ /**
81
+ * Get current domain from location
82
+ * Returns full URL format for consistency with dashboard
83
+ */
84
+ private getCurrentDomain;
85
+ /**
86
+ * Check if tracking is properly configured
87
+ * Returns true if projectId and token are present, false otherwise
88
+ * Logs a warning only once per instance if not configured
89
+ */
90
+ private _isConfigured;
91
+ /**
92
+ * Send event to endpoint
93
+ * PostHog-style: Automatically adds common properties to all events
94
+ * ($current_url, $host, $pathname, $referrer, $referring_domain, $browser_language, etc.)
95
+ * Also adds title property for $pageview events only
96
+ */
97
+ sendEvent(name: string, payload: EventPayload): Promise<void>;
98
+ /**
99
+ * Build the tracking URL with token in query parameters (PostHog style)
100
+ */
101
+ private buildUrl;
102
+ /**
103
+ * Send HTTP request
104
+ * This is the central entry point for all tracking requests
105
+ */
106
+ private sendRequest;
107
+ /**
108
+ * Send a queued request (called after DOM is loaded)
109
+ */
110
+ _send_retriable_request(item: QueuedRequest): void;
111
+ /**
112
+ * Get current session ID
113
+ */
114
+ getSessionId(): string | null;
115
+ /**
116
+ * Identify a user with PostHog-style property operations
117
+ * Copied from PostHog's identify method signature
118
+ */
119
+ identify(distinctId?: string, userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
120
+ /**
121
+ * Set user properties (PostHog-style)
122
+ */
123
+ setUserProperties(userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
124
+ /**
125
+ * Reset user identity (logout)
126
+ * PostHog behavior: Clears all user data, generates new anonymous ID, resets session
127
+ *
128
+ * @param reset_device_id - If true, also resets device_id. Default: false
129
+ */
130
+ resetUser(reset_device_id?: boolean): void;
131
+ /**
132
+ * Get current user identity
133
+ */
134
+ getUserIdentity(): UserIdentity;
135
+ /**
136
+ * Get current device ID
137
+ */
138
+ getDeviceId(): string;
139
+ /**
140
+ * Get current user state
141
+ */
142
+ getUserState(): "anonymous" | "identified";
143
+ /**
144
+ * Create an alias to link two distinct IDs
145
+ * PostHog behavior: Links anonymous session to account on signup
146
+ *
147
+ * @param alias - A unique identifier that you want to use for this user in the future
148
+ * @param original - The current identifier being used for this user (optional, defaults to current distinct_id)
149
+ *
150
+ * @example
151
+ * // Link anonymous user to account on signup
152
+ * vtilt.createAlias('user_12345')
153
+ *
154
+ * @example
155
+ * // Explicit alias with original ID
156
+ * vtilt.createAlias('user_12345', 'anonymous_abc123')
157
+ */
158
+ createAlias(alias: string, original?: string): void;
159
+ /**
160
+ * Setup listener for identify, set, and alias events
161
+ */
162
+ private setupIdentifyListener;
163
+ /**
164
+ * Get session and window IDs (PostHog-style)
165
+ * Both methods ensure IDs always exist (generate if needed)
166
+ */
167
+ private _getSessionAndWindowIds;
168
+ /**
169
+ * Create base tracking event structure
170
+ */
171
+ private _createTrackingEvent;
172
+ /**
173
+ * Send identify event for session merging
174
+ */
175
+ private sendIdentifyEvent;
176
+ /**
177
+ * Send $set event for property updates (PostHog behavior)
178
+ * This notifies Tinybird when user properties are updated
179
+ */
180
+ private sendSetEvent;
181
+ /**
182
+ * Send alias event for identity linking
183
+ * PostHog format: { alias: alias, distinct_id: original }
184
+ */
185
+ private sendAliasEvent;
186
+ }
187
+
188
+ /**
189
+ * This class is used to capture pageview events when the user navigates using the history API (pushState, replaceState)
190
+ * and when the user navigates using the browser's back/forward buttons.
191
+ *
192
+ * Based on PostHog's HistoryAutocapture implementation
193
+ */
194
+ declare class HistoryAutocapture {
195
+ private _instance;
196
+ private _popstateListener;
197
+ private _lastPathname;
198
+ constructor(instance: VTilt);
199
+ get isEnabled(): boolean;
200
+ startIfEnabled(): void;
201
+ stop(): void;
202
+ monitorHistoryChanges(): void;
203
+ private _capturePageview;
204
+ private _setupPopstateListener;
205
+ }
206
+
69
207
  declare class VTilt {
70
208
  private configManager;
71
- private trackingManager;
209
+ trackingManager: TrackingManager;
72
210
  private webVitalsManager;
73
- private initialized;
211
+ historyAutocapture?: HistoryAutocapture;
212
+ __loaded: boolean;
213
+ private _initialPageviewCaptured;
214
+ private _visibilityStateListener;
74
215
  constructor(config?: Partial<VTiltConfig>);
75
216
  /**
76
- * Initialize VTilt tracking
217
+ * Initializes a new instance of the VTilt tracking object.
218
+ *
219
+ * @remarks
220
+ * All new instances are added to the main vt object as sub properties (such as
221
+ * `vt.library_name`) and also returned by this function.
222
+ *
223
+ * @example
224
+ * ```js
225
+ * // basic initialization
226
+ * vt.init('<project_id>', {
227
+ * api_host: '<client_api_host>'
228
+ * })
229
+ * ```
230
+ *
231
+ * @example
232
+ * ```js
233
+ * // multiple instances
234
+ * vt.init('<project_id>', {}, 'project1')
235
+ * vt.init('<project_id>', {}, 'project2')
236
+ * ```
237
+ *
238
+ * @public
239
+ *
240
+ * @param projectId - Your VTilt project ID
241
+ * @param config - A dictionary of config options to override
242
+ * @param name - The name for the new VTilt instance that you want created
243
+ *
244
+ * @returns The newly initialized VTilt instance
245
+ */
246
+ init(projectId: string, config?: Partial<VTiltConfig>, name?: string): VTilt;
247
+ /**
248
+ * Handles the actual initialization logic for a VTilt instance.
249
+ * This internal method should only be called by `init()`.
250
+ * Follows the PostHog convention of using a private `_init()` method for instance setup.
251
+ */
252
+ private _init;
253
+ /**
254
+ * Returns a string representation of the instance name (PostHog-style)
255
+ * Used for debugging and logging
256
+ *
257
+ * @internal
77
258
  */
78
- init(): void;
259
+ toString(): string;
79
260
  /**
80
261
  * Track a custom event
81
262
  */
@@ -167,17 +348,10 @@ declare class VTilt {
167
348
  */
168
349
  createAlias(alias: string, original?: string): void;
169
350
  /**
170
- * Setup page tracking with history API support
171
- */
172
- private setupPageTracking;
173
- /**
174
- * Track page hit
175
- */
176
- private trackPageHit;
177
- /**
178
- * Setup visibility change tracking for prerendered pages
351
+ * Capture initial pageview with visibility check
352
+ * Based on PostHog's _captureInitialPageview implementation
179
353
  */
180
- private setupVisibilityTracking;
354
+ private _captureInitialPageview;
181
355
  /**
182
356
  * Get current configuration
183
357
  */
@@ -191,11 +365,11 @@ declare class VTilt {
191
365
  */
192
366
  updateConfig(config: Partial<VTiltConfig>): void;
193
367
  /**
194
- * _execute_array() deals with processing any VTilt function
195
- * calls that were called before the VTilt library was loaded
368
+ * _execute_array() deals with processing any vTilt function
369
+ * calls that were called before the vTilt library was loaded
196
370
  * (and are thus stored in an array so they can be called later)
197
371
  *
198
- * Note: we fire off all the VTilt function calls BEFORE we fire off
372
+ * Note: we fire off all the vTilt function calls BEFORE we fire off
199
373
  * tracking calls. This is so identify/setUserProperties/updateConfig calls
200
374
  * can properly modify early tracking calls.
201
375
  *
package/dist/module.js CHANGED
@@ -1,2 +1,2 @@
1
- function i(i,a,e,t,r,s,n){try{var o=i[s](n),c=o.value}catch(i){return void e(i)}o.done?a(c):Promise.resolve(c).then(t,r)}function a(){return a=Object.assign?Object.assign.bind():function(i){for(var a=1;a<arguments.length;a++){var e=arguments[a];for(var t in e)({}).hasOwnProperty.call(e,t)&&(i[t]=e[t])}return i},a.apply(null,arguments)}class e{constructor(i){void 0===i&&(i={}),this.config=this.parseConfigFromScript(i)}parseConfigFromScript(i){if(!document.currentScript)return a({projectId:i.projectId||"",token:i.token||""},i);var e=document.currentScript,t=a({projectId:"",token:""},i);if(t.host=e.getAttribute("data-host")||i.host,t.proxy=e.getAttribute("data-proxy")||i.proxy,t.proxyUrl=e.getAttribute("data-proxy-url")||i.proxyUrl,t.token=e.getAttribute("data-token")||i.token||"",t.projectId=e.getAttribute("data-project-id")||i.projectId||"",t.domain=e.getAttribute("data-domain")||i.domain,t.storage=e.getAttribute("data-storage")||i.storage,t.stringifyPayload="false"!==e.getAttribute("data-stringify-payload"),t.webVitals="true"===e.getAttribute("web-vitals")||"true"===e.getAttribute("data-web-vitals")||i.webVitals,t.proxy&&t.proxyUrl)throw console.error("Error: Both data-proxy and data-proxy-url are specified. Please use only one of them."),new Error("Both data-proxy and data-proxy-url are specified. Please use only one of them.");for(var r of(t.globalAttributes=a({},i.globalAttributes),Array.from(e.attributes)))r.name.startsWith("tb_")&&(t.globalAttributes[r.name.slice(3).replace(/-/g,"_")]=r.value),r.name.startsWith("data-tb-")&&(t.globalAttributes[r.name.slice(8).replace(/-/g,"_")]=r.value);return t}getConfig(){return a({},this.config)}updateConfig(i){this.config=a({},this.config,i)}}var t="vt_session_id",r="vt_anonymous_id",s="vt_distinct_id",n="vt_device_id",o="vt_user_properties",c="vt_user_state",A="localStorage",u="sessionStorage",l={"Asia/Barnaul":"RU","Africa/Nouakchott":"MR","Africa/Lusaka":"ZM","Asia/Pyongyang":"KP","Europe/Bratislava":"SK","America/Belize":"BZ","America/Maceio":"BR","Pacific/Chuuk":"FM","Indian/Comoro":"KM","Pacific/Palau":"PW","Asia/Jakarta":"ID","Africa/Windhoek":"NA","America/Chihuahua":"MX","America/Nome":"US","Africa/Mbabane":"SZ","Africa/Porto-Novo":"BJ","Europe/San_Marino":"SM","Pacific/Fakaofo":"TK","America/Denver":"US","Europe/Belgrade":"RS","America/Indiana/Tell_City":"US","America/Fortaleza":"BR","America/Halifax":"CA","Europe/Bucharest":"RO","America/Indiana/Petersburg":"US","Europe/Kirov":"RU","Europe/Athens":"GR","America/Argentina/Ushuaia":"AR","Europe/Monaco":"MC","Europe/Vilnius":"LT","Europe/Copenhagen":"DK","Pacific/Kanton":"KI","America/Caracas":"VE","Asia/Almaty":"KZ","Europe/Paris":"FR","Africa/Blantyre":"MW","Asia/Muscat":"OM","America/North_Dakota/Beulah":"US","America/Matamoros":"MX","Asia/Irkutsk":"RU","America/Costa_Rica":"CR","America/Araguaina":"BR","Atlantic/Canary":"ES","America/Santo_Domingo":"DO","America/Vancouver":"CA","Africa/Addis_Ababa":"ET","Africa/Accra":"GH","Pacific/Kwajalein":"MH","Asia/Baghdad":"IQ","Australia/Adelaide":"AU","Australia/Hobart":"AU","America/Guayaquil":"EC","America/Argentina/Tucuman":"AR","Australia/Lindeman":"AU","America/New_York":"US","Pacific/Fiji":"FJ","America/Antigua":"AG","Africa/Casablanca":"MA","America/Paramaribo":"SR","Africa/Cairo":"EG","America/Cayenne":"GF","America/Detroit":"US","Antarctica/Syowa":"AQ","Africa/Douala":"CM","America/Argentina/La_Rioja":"AR","Africa/Lagos":"NG","America/St_Barthelemy":"BL","Asia/Nicosia":"CY","Asia/Macau":"MO","Europe/Riga":"LV","Asia/Ashgabat":"TM","Indian/Antananarivo":"MG","America/Argentina/San_Juan":"AR","Asia/Aden":"YE","Asia/Tomsk":"RU","America/Asuncion":"PY","Pacific/Bougainville":"PG","Asia/Vientiane":"LA","America/Mazatlan":"MX","Africa/Luanda":"AO","Europe/Oslo":"NO","Africa/Kinshasa":"CD","Europe/Warsaw":"PL","America/Grand_Turk":"TC","Asia/Seoul":"KR","Africa/Tripoli":"LY","America/St_Thomas":"VI","Asia/Kathmandu":"NP","Pacific/Pitcairn":"PN","Pacific/Nauru":"NR","America/Curacao":"CW","Asia/Kabul":"AF","Pacific/Tongatapu":"TO","Europe/Simferopol":"UA","Asia/Ust-Nera":"RU","Africa/Mogadishu":"SO","Indian/Mayotte":"YT","Pacific/Niue":"NU","America/Thunder_Bay":"CA","Atlantic/Azores":"PT","Pacific/Gambier":"PF","Europe/Stockholm":"SE","Africa/Libreville":"GA","America/Punta_Arenas":"CL","America/Guatemala":"GT","America/Noronha":"BR","Europe/Helsinki":"FI","Asia/Gaza":"PS","Pacific/Kosrae":"FM","America/Aruba":"AW","America/Nassau":"BS","Asia/Choibalsan":"MN","America/Winnipeg":"CA","America/Anguilla":"AI","Asia/Thimphu":"BT","Asia/Beirut":"LB","Atlantic/Faroe":"FO","Europe/Berlin":"DE","Europe/Amsterdam":"NL","Pacific/Honolulu":"US","America/Regina":"CA","America/Scoresbysund":"GL","Europe/Vienna":"AT","Europe/Tirane":"AL","Africa/El_Aaiun":"EH","America/Creston":"CA","Asia/Qostanay":"KZ","Asia/Ho_Chi_Minh":"VN","Europe/Samara":"RU","Europe/Rome":"IT","Australia/Eucla":"AU","America/El_Salvador":"SV","America/Chicago":"US","Africa/Abidjan":"CI","Asia/Kamchatka":"RU","Pacific/Tarawa":"KI","America/Santiago":"CL","America/Bahia":"BR","Indian/Christmas":"CX","Asia/Atyrau":"KZ","Asia/Dushanbe":"TJ","Europe/Ulyanovsk":"RU","America/Yellowknife":"CA","America/Recife":"BR","Australia/Sydney":"AU","America/Fort_Nelson":"CA","Pacific/Efate":"VU","Europe/Saratov":"RU","Africa/Banjul":"GM","Asia/Omsk":"RU","Europe/Ljubljana":"SI","Europe/Budapest":"HU","Europe/Astrakhan":"RU","America/Argentina/Buenos_Aires":"AR","Pacific/Chatham":"NZ","America/Argentina/Salta":"AR","Africa/Niamey":"NE","Asia/Pontianak":"ID","Indian/Reunion":"RE","Asia/Hong_Kong":"HK","Antarctica/McMurdo":"AQ","Africa/Malabo":"GQ","America/Los_Angeles":"US","America/Argentina/Cordoba":"AR","Pacific/Pohnpei":"FM","America/Tijuana":"MX","America/Campo_Grande":"BR","America/Dawson_Creek":"CA","Asia/Novosibirsk":"RU","Pacific/Pago_Pago":"AS","Asia/Jerusalem":"IL","Europe/Sarajevo":"BA","Africa/Freetown":"SL","Asia/Yekaterinburg":"RU","America/Juneau":"US","Africa/Ouagadougou":"BF","Africa/Monrovia":"LR","Europe/Kiev":"UA","America/Argentina/San_Luis":"AR","Asia/Tokyo":"JP","Asia/Qatar":"QA","America/La_Paz":"BO","America/Bogota":"CO","America/Thule":"GL","Asia/Manila":"PH","Asia/Hovd":"MN","Asia/Tehran":"IR","Atlantic/Madeira":"PT","America/Metlakatla":"US","Europe/Vatican":"VA","Asia/Bishkek":"KG","Asia/Dili":"TL","Antarctica/Palmer":"AQ","Atlantic/Cape_Verde":"CV","Indian/Chagos":"IO","America/Kentucky/Monticello":"US","Africa/Algiers":"DZ","Africa/Maseru":"LS","Asia/Kuala_Lumpur":"MY","Africa/Khartoum":"SD","America/Argentina/Rio_Gallegos":"AR","America/Blanc-Sablon":"CA","Africa/Maputo":"MZ","America/Tortola":"VG","Atlantic/Bermuda":"BM","America/Argentina/Catamarca":"AR","America/Cayman":"KY","America/Puerto_Rico":"PR","Pacific/Majuro":"MH","Europe/Busingen":"DE","Pacific/Midway":"UM","Indian/Cocos":"CC","Asia/Singapore":"SG","America/Boise":"US","America/Nuuk":"GL","America/Goose_Bay":"CA","Australia/Broken_Hill":"AU","Africa/Dar_es_Salaam":"TZ","Africa/Asmara":"ER","Asia/Samarkand":"UZ","Asia/Tbilisi":"GE","America/Argentina/Jujuy":"AR","America/Indiana/Winamac":"US","America/Porto_Velho":"BR","Asia/Magadan":"RU","Europe/Zaporozhye":"UA","Antarctica/Casey":"AQ","Asia/Shanghai":"CN","Pacific/Norfolk":"NF","Europe/Guernsey":"GG","Australia/Brisbane":"AU","Antarctica/DumontDUrville":"AQ","America/Havana":"CU","America/Atikokan":"CA","America/Mexico_City":"MX","America/Rankin_Inlet":"CA","America/Cuiaba":"BR","America/Resolute":"CA","Africa/Ceuta":"ES","Arctic/Longyearbyen":"SJ","Pacific/Guam":"GU","Asia/Damascus":"SY","Asia/Colombo":"LK","Asia/Yerevan":"AM","America/Montserrat":"MS","America/Belem":"BR","Europe/Kaliningrad":"RU","Atlantic/South_Georgia":"GS","Asia/Tashkent":"UZ","Asia/Kolkata":"IN","America/St_Johns":"CA","Asia/Srednekolymsk":"RU","Asia/Yakutsk":"RU","Europe/Prague":"CZ","Africa/Djibouti":"DJ","Asia/Dubai":"AE","Europe/Uzhgorod":"UA","America/Edmonton":"CA","Asia/Famagusta":"CY","America/Indiana/Knox":"US","Asia/Hebron":"PS","Asia/Taipei":"TW","Europe/London":"GB","Africa/Dakar":"SN","Australia/Darwin":"AU","America/Glace_Bay":"CA","Antarctica/Vostok":"AQ","America/Indiana/Vincennes":"US","America/Nipigon":"CA","Asia/Kuwait":"KW","Pacific/Guadalcanal":"SB","America/Toronto":"CA","Africa/Gaborone":"BW","Africa/Bujumbura":"BI","Africa/Lubumbashi":"CD","America/Merida":"MX","America/Marigot":"MF","Europe/Zagreb":"HR","Pacific/Easter":"CL","America/Santarem":"BR","Pacific/Noumea":"NC","America/Sitka":"US","Atlantic/Stanley":"FK","Pacific/Funafuti":"TV","America/Iqaluit":"CA","America/Rainy_River":"CA","America/Anchorage":"US","America/Lima":"PE","Asia/Baku":"AZ","America/Indiana/Vevay":"US","Asia/Ulaanbaatar":"MN","America/Managua":"NI","Asia/Krasnoyarsk":"RU","Asia/Qyzylorda":"KZ","America/Eirunepe":"BR","Europe/Podgorica":"ME","Europe/Chisinau":"MD","Europe/Mariehamn":"AX","Europe/Volgograd":"RU","Africa/Nairobi":"KE","Europe/Isle_of_Man":"IM","America/Menominee":"US","Africa/Harare":"ZW","Asia/Anadyr":"RU","America/Moncton":"CA","Indian/Maldives":"MV","America/Whitehorse":"CA","Antarctica/Mawson":"AQ","Europe/Madrid":"ES","America/Argentina/Mendoza":"AR","America/Manaus":"BR","Africa/Bangui":"CF","Indian/Mauritius":"MU","Africa/Tunis":"TN","Australia/Lord_Howe":"AU","America/Kentucky/Louisville":"US","America/North_Dakota/Center":"US","Asia/Novokuznetsk":"RU","Asia/Makassar":"ID","America/Port_of_Spain":"TT","America/Bahia_Banderas":"MX","Pacific/Auckland":"NZ","America/Sao_Paulo":"BR","Asia/Dhaka":"BD","America/Pangnirtung":"CA","Europe/Dublin":"IE","Asia/Brunei":"BN","Africa/Brazzaville":"CG","America/Montevideo":"UY","America/Jamaica":"JM","America/Indiana/Indianapolis":"US","America/Kralendijk":"BQ","Europe/Gibraltar":"GI","Pacific/Marquesas":"PF","Pacific/Apia":"WS","Europe/Jersey":"JE","America/Phoenix":"US","Africa/Ndjamena":"TD","Asia/Karachi":"PK","Africa/Kampala":"UG","Asia/Sakhalin":"RU","America/Martinique":"MQ","Europe/Moscow":"RU","Africa/Conakry":"GN","America/Barbados":"BB","Africa/Lome":"TG","America/Ojinaga":"MX","America/Tegucigalpa":"HN","Asia/Bangkok":"TH","Africa/Johannesburg":"ZA","Europe/Vaduz":"LI","Africa/Sao_Tome":"ST","America/Cambridge_Bay":"CA","America/Lower_Princes":"SX","America/Miquelon":"PM","America/St_Kitts":"KN","Australia/Melbourne":"AU","Europe/Minsk":"BY","Asia/Vladivostok":"RU","Europe/Sofia":"BG","Antarctica/Davis":"AQ","Pacific/Galapagos":"EC","America/North_Dakota/New_Salem":"US","Asia/Amman":"JO","Pacific/Wallis":"WF","America/Hermosillo":"MX","Pacific/Kiritimati":"KI","Antarctica/Macquarie":"AU","America/Guyana":"GY","Asia/Riyadh":"SA","Pacific/Tahiti":"PF","America/St_Vincent":"VC","America/Cancun":"MX","America/Grenada":"GD","Pacific/Wake":"UM","America/Dawson":"CA","Europe/Brussels":"BE","Indian/Kerguelen":"TF","America/Yakutat":"US","Indian/Mahe":"SC","Atlantic/Reykjavik":"IS","America/Panama":"PA","America/Guadeloupe":"GP","Europe/Malta":"MT","Antarctica/Troll":"AQ","Asia/Jayapura":"ID","Asia/Bahrain":"BH","Asia/Chita":"RU","Europe/Tallinn":"EE","Asia/Khandyga":"RU","America/Rio_Branco":"BR","Atlantic/St_Helena":"SH","Africa/Juba":"SS","America/Adak":"US","Pacific/Saipan":"MP","America/St_Lucia":"LC","America/Inuvik":"CA","Europe/Luxembourg":"LU","Africa/Bissau":"GW","Asia/Oral":"KZ","America/Boa_Vista":"BR","Europe/Skopje":"MK","America/Port-au-Prince":"HT","Pacific/Port_Moresby":"PG","Europe/Andorra":"AD","America/Indiana/Marengo":"US","Africa/Kigali":"RW","Africa/Bamako":"ML","America/Dominica":"DM","Asia/Aqtobe":"KZ","Europe/Istanbul":"TR","Pacific/Rarotonga":"CK","America/Danmarkshavn":"GL","Europe/Zurich":"CH","Asia/Yangon":"MM","America/Monterrey":"MX","Europe/Lisbon":"PT","Asia/Kuching":"MY","Antarctica/Rothera":"AQ","Australia/Perth":"AU","Asia/Phnom_Penh":"KH","America/Swift_Current":"CA","Asia/Aqtau":"KZ","Asia/Urumqi":"CN","Asia/Calcutta":"IN"},h=["username","user","user_id","userid","password","pass","pin","passcode","token","api_token","email","address","phone","sex","gender","order","order_id","orderid","payment","credit_card"];function d(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,i=>(+i^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+i/4).toString(16))}function m(i){return!(!i||"string"!=typeof i)&&!(i.length<2||i.length>10240)}function f(i){var a=JSON.stringify(i);return h.forEach(i=>{a=a.replace(new RegExp('("'+i+'"):(".+?"|\\d+)',"gmi"),'$1:"********"')}),a}function p(){return!!("__nightmare"in window||window.navigator.webdriver||"Cypress"in window)}class v{constructor(i,a){void 0===i&&(i="cookie"),this.storageMethod=i,this.domain=a}getSessionIdFromCookie(){var i={};return document.cookie.split(";").forEach(function(a){var[e,t]=a.split("=");i[e.trim()]=t}),i[t]||null}getSessionId(){if(this.storageMethod===A||this.storageMethod===u){var i=this.storageMethod===A?localStorage:sessionStorage,a=i.getItem(t);if(!a)return null;var e=null;try{e=JSON.parse(a)}catch(i){return null}return"object"!=typeof e||null===e?null:(new Date).getTime()>e.expiry?(i.removeItem(t),null):e.value}return this.getSessionIdFromCookie()}setSessionIdFromCookie(i){var a=t+"="+i+"; Max-Age=1800; path=/; secure";this.domain&&(a+="; domain="+this.domain),document.cookie=a}setSessionId(){var i=this.getSessionId()||d();if(this.storageMethod===A||this.storageMethod===u){var a={value:i,expiry:(new Date).getTime()+18e5},e=JSON.stringify(a);(this.storageMethod===A?localStorage:sessionStorage).setItem(t,e)}else this.setSessionIdFromCookie(i);return i}resetSessionId(){this.storageMethod===A||this.storageMethod===u?(this.storageMethod===A?localStorage:sessionStorage).removeItem(t):(document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",this.domain&&(document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain="+this.domain+";"));this.setSessionId()}}class g{constructor(i,a){void 0===i&&(i="localStorage"),this.i=null,this.storageMethod=i,this.domain=a,this.userIdentity=this.loadUserIdentity()}getUserIdentity(){return a({},this.userIdentity)}getDistinctId(){return this.userIdentity.distinct_id}getAnonymousId(){return this.userIdentity.anonymous_id||(this.userIdentity.anonymous_id=this.generateAnonymousId(),this.saveUserIdentity()),this.userIdentity.anonymous_id}getUserProperties(){return a({},this.userIdentity.properties)}identify(i,e,t){if("number"==typeof i&&(i=i.toString(),console.warn("The first argument to vTilt.identify was a number, but it should be a string. It has been converted to a string.")),i)if(this.isDistinctIdStringLike(i))console.error('The string "'+i+'" was set in vTilt.identify which indicates an error. This ID should be unique to the user and not a hardcoded string.');else if("COOKIELESS_SENTINEL_VALUE"!==i){var r=this.userIdentity.distinct_id,s=this.userIdentity.anonymous_id,n=this.userIdentity.device_id;if(this.userIdentity.distinct_id=i,!this.userIdentity.device_id){var o=r||this.userIdentity.anonymous_id;this.userIdentity.device_id=o,this.userIdentity.properties=a({},this.userIdentity.properties,{$had_persisted_distinct_id:!0,$device_id:o})}i!==r&&(this.userIdentity.distinct_id=i);var c="anonymous"===this.userIdentity.user_state;i!==r&&c?(this.userIdentity.user_state="identified",e&&(this.userIdentity.properties=a({},this.userIdentity.properties,e)),t&&Object.keys(t).forEach(i=>{i in this.userIdentity.properties||(this.userIdentity.properties[i]=t[i])}),this.saveUserIdentity(),this.sendIdentifyEvent(i,s,n,{$set:e||{},$set_once:t||{}})):e||t?("anonymous"===this.userIdentity.user_state&&(this.userIdentity.user_state="identified"),e&&(this.userIdentity.properties=a({},this.userIdentity.properties,e)),t&&Object.keys(t).forEach(i=>{i in this.userIdentity.properties||(this.userIdentity.properties[i]=t[i])}),this.saveUserIdentity(),this.sendSetEvent(e||{},t||{})):i!==r&&(this.userIdentity.user_state="identified",this.saveUserIdentity())}else console.error('The string "'+i+'" was set in vTilt.identify which indicates an error. This ID is only used as a sentinel value.');else console.error("Unique user id has not been set in vTilt.identify")}setUserProperties(i,e){if(i||e){var t=this.userIdentity.distinct_id||this.userIdentity.anonymous_id,r=this.getPersonPropertiesHash(t,i,e);this.i!==r?(i&&(this.userIdentity.properties=a({},this.userIdentity.properties,i)),e&&Object.keys(e).forEach(i=>{i in this.userIdentity.properties||(this.userIdentity.properties[i]=e[i])}),this.saveUserIdentity(),this.sendSetEvent(i||{},e||{}),this.i=r):console.info("VTilt: A duplicate setUserProperties call was made with the same properties. It has been ignored.")}}getPersonPropertiesHash(i,a,e){return JSON.stringify({distinct_id:i,userPropertiesToSet:a,userPropertiesToSetOnce:e})}sendSetEvent(i,a){var e=new CustomEvent("vtilt:set",{detail:{$set:i||{},$set_once:a||{}}});window.dispatchEvent(e)}reset(i){var e=this.generateAnonymousId(),t=this.userIdentity.device_id,r=i?this.generateDeviceId():t;this.userIdentity={distinct_id:null,anonymous_id:e,device_id:r,properties:{},user_state:"anonymous"},this.i=null,this.saveUserIdentity(),this.userIdentity.properties=a({},this.userIdentity.properties,{$last_posthog_reset:(new Date).toISOString()}),this.saveUserIdentity()}getEffectiveId(){return this.userIdentity.distinct_id||this.getAnonymousId()}getDeviceId(){return this.userIdentity.device_id}getUserState(){return this.userIdentity.user_state}createAlias(i,a){if(this.isValidDistinctId(i))if(void 0===a&&(a=this.getDistinctId()||this.getAnonymousId()),this.isValidDistinctId(a)){if(i===a)return console.warn("alias matches current distinct_id - calling identify instead"),void this.identify(i);var e=new CustomEvent("vtilt:alias",{detail:{distinct_id:i,original:a}});window.dispatchEvent(e)}else console.warn("Invalid original distinct ID");else console.warn("Invalid alias provided")}isValidDistinctId(i){if(!i||"string"!=typeof i)return!1;var a=i.toLowerCase().trim();return!["null","undefined","false","true","anonymous","anon","user","test","guest","visitor","unknown","none"].includes(a)&&0!==i.trim().length}isDistinctIdStringLike(i){if(!i||"string"!=typeof i)return!1;var a=i.toLowerCase().trim();return["null","undefined","false","true","anonymous","anon","user","test","guest","visitor","unknown","none","demo","example","sample","placeholder"].includes(a)}loadUserIdentity(){var i=this.getStoredValue(r)||this.generateAnonymousId(),a=this.getStoredValue(s)||null,e=this.getStoredValue(n)||this.generateDeviceId(),t=this.getStoredUserProperties(),o=this.getStoredValue(c)||"anonymous";return{distinct_id:a,anonymous_id:i||this.generateAnonymousId(),device_id:e,properties:t,user_state:o}}saveUserIdentity(){this.setStoredValue(r,this.userIdentity.anonymous_id),this.setStoredValue(n,this.userIdentity.device_id),this.setStoredValue(c,this.userIdentity.user_state),this.userIdentity.distinct_id?this.setStoredValue(s,this.userIdentity.distinct_id):this.removeStoredValue(s),this.setStoredUserProperties(this.userIdentity.properties)}generateAnonymousId(){return"anon_"+d()}generateDeviceId(){return"device_"+d()}sendIdentifyEvent(i,e,t,r){var s=new CustomEvent("vtilt:identify",{detail:{distinct_id:i,anonymous_id:e,device_id:t,properties:a({$anon_distinct_id:e,$device_id:t},r)}});window.dispatchEvent(s)}getStoredValue(i){try{return this.storageMethod===A?localStorage.getItem(i):this.storageMethod===u?sessionStorage.getItem(i):this.getCookieValue(i)}catch(i){return console.warn("Failed to access storage:",i),null}}setStoredValue(i,a){try{this.storageMethod===A?localStorage.setItem(i,a):this.storageMethod===u?sessionStorage.setItem(i,a):this.setCookieValue(i,a)}catch(i){console.warn("Failed to save to storage:",i)}}removeStoredValue(i){this.storageMethod===A?localStorage.removeItem(i):this.storageMethod===u?sessionStorage.removeItem(i):this.removeCookieValue(i)}getStoredUserProperties(){var i=this.getStoredValue(o);if(!i)return{};try{return JSON.parse(i)}catch(i){return{}}}setStoredUserProperties(i){this.setStoredValue(o,JSON.stringify(i))}getCookieValue(i){var a=document.cookie.split(";");for(var e of a){var[t,r]=e.trim().split("=");if(t===i)return decodeURIComponent(r)}return null}setCookieValue(i,a){var e=i+"="+encodeURIComponent(a)+"; Max-Age=31536000; path=/; secure; SameSite=Lax";this.domain&&(e+="; domain="+this.domain),document.cookie=e}removeCookieValue(i){var a=i+"=; Max-Age=0; path=/";this.domain&&(a+="; domain="+this.domain),document.cookie=a}}var S="undefined"!=typeof window?window:void 0,_="undefined"!=typeof globalThis?globalThis:S,y=null==_?void 0:_.navigator,C=null==_?void 0:_.document,E=null==_?void 0:_.location,U=null==_?void 0:_.fetch,M=(null==_?void 0:_.XMLHttpRequest)&&"withCredentials"in new _.XMLHttpRequest?_.XMLHttpRequest:void 0;null==_||_.AbortController;var P=null==y?void 0:y.userAgent;function k(){var i,a;if(!y)return{country:i,locale:a};try{var e=Intl.DateTimeFormat().resolvedOptions().timeZone;i=l[e],a=y.languages&&y.languages.length?y.languages[0]:y.userLanguage||y.language||y.browserLanguage||"en"}catch(i){}return{country:i,locale:a}}class b{constructor(i){this.__request_queue=[],this.t=!1,this.config=i,!this.config.domain&&E&&(this.config.domain=this.getCurrentDomain()),this.sessionManager=new v(i.storage||"cookie",this.config.domain),this.userManager=new g(i.persistence||"localStorage",this.config.domain),this.setupIdentifyListener()}getCurrentDomain(){if(!E)return"";var i=E.protocol,a=E.hostname,e=E.port;return i+"//"+a+(e?":"+e:"")}o(){return!(!this.config.projectId||!this.config.token)||(this.t||(console.warn("VTilt: projectId and token are required for tracking. Events will be skipped until init() or updateConfig() is called with these fields."),this.t=!0),!1)}sendEvent(a,e){var t,r=this;return(t=function*(){if(r.sessionManager.setSessionId(),y&&y.userAgent&&function(i){return!(i&&"string"==typeof i&&i.length>500)}(y.userAgent)){var i,t=r.buildUrl();if(!1!==r.config.stringifyPayload){if(i=f(e),i=Object.assign({},JSON.parse(i),r.config.globalAttributes),!m(i=JSON.stringify(i)))return}else{var s=f(i=Object.assign({},e,r.config.globalAttributes));if(!m(s))return;i=JSON.parse(s)}var n=r.sessionManager.getSessionId()||d(),o=r.userManager.getDistinctId(),c=r.userManager.getAnonymousId(),A={timestamp:(new Date).toISOString(),event:a,session_id:n,tenant_id:r.config.projectId||"",domain:r.config.domain||r.getCurrentDomain(),payload:i,distinct_id:o||c};r.sendRequest(t,A,!0)}},function(){var a=this,e=arguments;return new Promise(function(r,s){var n=t.apply(a,e);function o(a){i(n,r,s,o,c,"next",a)}function c(a){i(n,r,s,o,c,"throw",a)}o(void 0)})})()}buildUrl(){var{proxyUrl:i,proxy:a,host:e,token:t}=this.config;return i||(a?a+"/api/tracking?token="+t:e?e.replace(/\/+$/gm,"")+"/api/tracking?token="+t:"/api/tracking?token="+t)}sendRequest(i,a,e){if(this.o()){if(e&&void 0!==S)if(S.__VTILT_ENQUEUE_REQUESTS)return void this.__request_queue.push({url:i,event:a});var t=new XMLHttpRequest;t.open("POST",i,!0),t.setRequestHeader("Content-Type","application/json"),t.send(JSON.stringify(a))}}A(i){this.sendRequest(i.url,i.event,!1)}trackPageHit(){if(!p()&&S&&C&&y&&E){var{country:i,locale:a}=k();setTimeout(()=>{S&&C&&y&&E&&this.sendEvent("page_hit",{"user-agent":y.userAgent,locale:a,location:i,referrer:C.referrer,pathname:E.pathname,href:E.href})},300)}}getSessionId(){return this.sessionManager.getSessionId()}identify(i,a,e){this.userManager.identify(i,a,e)}setUserProperties(i,a){this.userManager.setUserProperties(i,a)}resetUser(i){this.sessionManager.resetSessionId(),this.userManager.reset(i)}getUserIdentity(){return this.userManager.getUserIdentity()}getDeviceId(){return this.userManager.getDeviceId()}getUserState(){return this.userManager.getUserState()}createAlias(i,a){this.userManager.createAlias(i,a)}setupIdentifyListener(){S&&(S.addEventListener("vtilt:identify",i=>{var a=i,{distinct_id:e,anonymous_id:t,device_id:r,properties:s}=a.detail;this.sendIdentifyEvent(e,t,r,s)}),S.addEventListener("vtilt:set",i=>{var a=i,{$set:e,$set_once:t}=a.detail;this.sendSetEvent(e||{},t||{})}),S.addEventListener("vtilt:alias",i=>{var a=i.detail;this.sendAliasEvent(a)}))}sendIdentifyEvent(i,e,t,r){var s=this.buildUrl(),n=this.sessionManager.getSessionId()||d(),o=a({$anon_distinct_id:e,$device_id:t},r),c={timestamp:(new Date).toISOString(),event:"$identify",session_id:n,tenant_id:this.config.projectId||"",domain:this.config.domain||this.getCurrentDomain(),payload:o,distinct_id:i};this.sendRequest(s,c,!0)}sendSetEvent(i,a){var e=this.buildUrl(),t=this.sessionManager.getSessionId()||d(),r=this.userManager.getDistinctId(),s=this.userManager.getAnonymousId(),n={$set:i||{},$set_once:a||{}},o={timestamp:(new Date).toISOString(),event:"$set",session_id:t,tenant_id:this.config.projectId||"",domain:this.config.domain||this.getCurrentDomain(),payload:n,distinct_id:r||s};this.sendRequest(e,o,!0)}sendAliasEvent(i){var a=this.buildUrl(),e=this.sessionManager.getSessionId()||d(),t={$original_id:i.original,$alias_id:i.distinct_id},r={timestamp:(new Date).toISOString(),event:"$alias",session_id:e,tenant_id:this.config.projectId||"",domain:this.config.domain||this.getCurrentDomain(),payload:t,distinct_id:i.distinct_id};this.sendRequest(a,r,!0)}}class R{constructor(i,a){if(this.trackingManager=a,i.webVitals&&S)try{this.webVitals=require("web-vitals"),this.initializeWebVitals()}catch(i){console.warn("web-vitals library not found. Please install it to enable web vitals tracking.",i)}}initializeWebVitals(){if(this.webVitals){var i=i=>{try{if(!(S&&C&&y&&E))return;var{country:a,locale:e}=k();this.trackingManager.sendEvent("web_vital",{name:i.name,value:i.value,delta:i.delta,rating:i.rating,id:i.id,navigationType:i.navigationType,pathname:E.pathname,href:E.href,"user-agent":y.userAgent,locale:e,location:a,referrer:C.referrer})}catch(i){console.error("Error sending web vital:",i)}};this.webVitals.onCLS&&this.webVitals.onCLS(i),this.webVitals.onFCP&&this.webVitals.onFCP(i),this.webVitals.onLCP&&this.webVitals.onLCP(i),this.webVitals.onTTFB&&this.webVitals.onTTFB(i),this.webVitals.onINP&&this.webVitals.onINP(i)}}}class I{constructor(i){void 0===i&&(i={}),this.initialized=!1,this.configManager=new e(i),this.trackingManager=new b(this.configManager.getConfig()),this.webVitalsManager=new R(this.configManager.getConfig(),this.trackingManager)}init(){this.initialized||S&&C&&(this.setupPageTracking(),this.initialized=!0)}trackEvent(i,a){void 0===a&&(a={}),this.trackingManager.sendEvent(i,a)}identify(i,a,e){this.trackingManager.identify(i,a,e)}setUserProperties(i,a){this.trackingManager.setUserProperties(i,a)}resetUser(i){this.trackingManager.resetUser(i)}getUserIdentity(){return this.trackingManager.getUserIdentity()}getDeviceId(){return this.trackingManager.getDeviceId()}getUserState(){return this.trackingManager.getUserState()}createAlias(i,a){this.trackingManager.createAlias(i,a)}setupPageTracking(){if(S&&C){this.trackPageHit(),S.addEventListener("hashchange",()=>this.trackPageHit());var i=S.history;if(i.pushState){var a=i.pushState,e=i.replaceState,t=this;Object.defineProperty(i,"pushState",{value:function(i,e,r){a.call(this,i,e,r),setTimeout(()=>{t.trackPageHit()},0)},writable:!0,configurable:!0}),e&&Object.defineProperty(i,"replaceState",{value:function(i,a,r){e.call(this,i,a,r),setTimeout(()=>{t.trackPageHit()},0)},writable:!0,configurable:!0}),S.addEventListener("popstate",()=>this.trackPageHit())}this.setupVisibilityTracking()}}trackPageHit(){p()||this.trackingManager.trackPageHit()}setupVisibilityTracking(){if(C){var i=C;"prerender"===i.visibilityState&&i.addEventListener("visibilitychange",()=>{"visible"===i.visibilityState&&this.trackPageHit()})}}getConfig(){return this.configManager.getConfig()}getSessionId(){return this.trackingManager.getSessionId()}updateConfig(i){this.configManager.updateConfig(i),this.trackingManager=new b(this.configManager.getConfig()),this.webVitalsManager=new R(this.configManager.getConfig(),this.trackingManager)}_execute_array(i){Array.isArray(i)&&i.forEach(i=>{if(i&&Array.isArray(i)&&i.length>0){var a=i[0],e=i.slice(1);if("function"==typeof this[a])try{this[a](...e)}catch(i){console.error("VTilt: Error executing queued call "+a+":",i)}}})}_dom_loaded(){this.trackingManager&&(this.trackingManager.__request_queue.forEach(i=>{this.trackingManager.A(i)}),this.trackingManager.__request_queue=[])}}var B={},T=!(void 0!==M||void 0!==U)&&-1===(null==P?void 0:P.indexOf("MSIE"))&&-1===(null==P?void 0:P.indexOf("Mozilla"));S&&(S.__VTILT_ENQUEUE_REQUESTS=T);var w=function(){function i(){i.done||(i.done=!0,T=!1,void 0!==S&&(S.__VTILT_ENQUEUE_REQUESTS=!1),function(i,a,e){if(i)if(Array.isArray(i))i.forEach((i,t)=>{a.call(e,i,t)});else for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&a.call(e,i[t],t)}(B,function(i){i._dom_loaded()}))}C&&"function"==typeof C.addEventListener?"complete"===C.readyState?i():function(i,a,e,t){var{capture:r=!1,passive:s=!0}=null!=t?t:{};null==i||i.addEventListener(a,e,{capture:r,passive:s})}(C,"DOMContentLoaded",i,{capture:!1}):S&&console.error("Browser doesn't support `document.addEventListener` so VTilt couldn't be initialized")};var N,D=(N=B.vTilt=new I,w(),N);export{I as VTilt,D as default,D as vt};
1
+ function i(i,e,a,t,r,n,s){try{var o=i[n](s),c=o.value}catch(i){return void a(i)}o.done?e(c):Promise.resolve(c).then(t,r)}function e(){return e=Object.assign?Object.assign.bind():function(i){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var t in a)({}).hasOwnProperty.call(a,t)&&(i[t]=a[t])}return i},e.apply(null,arguments)}class a{constructor(i){void 0===i&&(i={}),this.config=this.parseConfigFromScript(i)}parseConfigFromScript(i){if(!document.currentScript)return e({projectId:i.projectId||"",token:i.token||""},i);var a=document.currentScript,t=e({projectId:"",token:""},i);if(t.host=a.getAttribute("data-host")||i.host,t.proxy=a.getAttribute("data-proxy")||i.proxy,t.proxyUrl=a.getAttribute("data-proxy-url")||i.proxyUrl,t.token=a.getAttribute("data-token")||i.token||"",t.projectId=a.getAttribute("data-project-id")||i.projectId||"",t.domain=a.getAttribute("data-domain")||i.domain,t.storage=a.getAttribute("data-storage")||i.storage,t.stringifyPayload="false"!==a.getAttribute("data-stringify-payload"),t.webVitals="true"===a.getAttribute("web-vitals")||"true"===a.getAttribute("data-web-vitals")||i.webVitals,t.proxy&&t.proxyUrl)throw console.error("Error: Both data-proxy and data-proxy-url are specified. Please use only one of them."),new Error("Both data-proxy and data-proxy-url are specified. Please use only one of them.");for(var r of(t.globalAttributes=e({},i.globalAttributes),Array.from(a.attributes)))r.name.startsWith("tb_")&&(t.globalAttributes[r.name.slice(3).replace(/-/g,"_")]=r.value),r.name.startsWith("data-tb-")&&(t.globalAttributes[r.name.slice(8).replace(/-/g,"_")]=r.value);return t}getConfig(){return e({},this.config)}updateConfig(i){this.config=e({},this.config,i)}}var t="vt_session_id",r="vt_window_id",n="vt_primary_window_exists",s="vt_anonymous_id",o="vt_distinct_id",c="vt_device_id",u="vt_user_properties",A="vt_user_state",d="localStorage",l="sessionStorage",h={"Asia/Barnaul":"RU","Africa/Nouakchott":"MR","Africa/Lusaka":"ZM","Asia/Pyongyang":"KP","Europe/Bratislava":"SK","America/Belize":"BZ","America/Maceio":"BR","Pacific/Chuuk":"FM","Indian/Comoro":"KM","Pacific/Palau":"PW","Asia/Jakarta":"ID","Africa/Windhoek":"NA","America/Chihuahua":"MX","America/Nome":"US","Africa/Mbabane":"SZ","Africa/Porto-Novo":"BJ","Europe/San_Marino":"SM","Pacific/Fakaofo":"TK","America/Denver":"US","Europe/Belgrade":"RS","America/Indiana/Tell_City":"US","America/Fortaleza":"BR","America/Halifax":"CA","Europe/Bucharest":"RO","America/Indiana/Petersburg":"US","Europe/Kirov":"RU","Europe/Athens":"GR","America/Argentina/Ushuaia":"AR","Europe/Monaco":"MC","Europe/Vilnius":"LT","Europe/Copenhagen":"DK","Pacific/Kanton":"KI","America/Caracas":"VE","Asia/Almaty":"KZ","Europe/Paris":"FR","Africa/Blantyre":"MW","Asia/Muscat":"OM","America/North_Dakota/Beulah":"US","America/Matamoros":"MX","Asia/Irkutsk":"RU","America/Costa_Rica":"CR","America/Araguaina":"BR","Atlantic/Canary":"ES","America/Santo_Domingo":"DO","America/Vancouver":"CA","Africa/Addis_Ababa":"ET","Africa/Accra":"GH","Pacific/Kwajalein":"MH","Asia/Baghdad":"IQ","Australia/Adelaide":"AU","Australia/Hobart":"AU","America/Guayaquil":"EC","America/Argentina/Tucuman":"AR","Australia/Lindeman":"AU","America/New_York":"US","Pacific/Fiji":"FJ","America/Antigua":"AG","Africa/Casablanca":"MA","America/Paramaribo":"SR","Africa/Cairo":"EG","America/Cayenne":"GF","America/Detroit":"US","Antarctica/Syowa":"AQ","Africa/Douala":"CM","America/Argentina/La_Rioja":"AR","Africa/Lagos":"NG","America/St_Barthelemy":"BL","Asia/Nicosia":"CY","Asia/Macau":"MO","Europe/Riga":"LV","Asia/Ashgabat":"TM","Indian/Antananarivo":"MG","America/Argentina/San_Juan":"AR","Asia/Aden":"YE","Asia/Tomsk":"RU","America/Asuncion":"PY","Pacific/Bougainville":"PG","Asia/Vientiane":"LA","America/Mazatlan":"MX","Africa/Luanda":"AO","Europe/Oslo":"NO","Africa/Kinshasa":"CD","Europe/Warsaw":"PL","America/Grand_Turk":"TC","Asia/Seoul":"KR","Africa/Tripoli":"LY","America/St_Thomas":"VI","Asia/Kathmandu":"NP","Pacific/Pitcairn":"PN","Pacific/Nauru":"NR","America/Curacao":"CW","Asia/Kabul":"AF","Pacific/Tongatapu":"TO","Europe/Simferopol":"UA","Asia/Ust-Nera":"RU","Africa/Mogadishu":"SO","Indian/Mayotte":"YT","Pacific/Niue":"NU","America/Thunder_Bay":"CA","Atlantic/Azores":"PT","Pacific/Gambier":"PF","Europe/Stockholm":"SE","Africa/Libreville":"GA","America/Punta_Arenas":"CL","America/Guatemala":"GT","America/Noronha":"BR","Europe/Helsinki":"FI","Asia/Gaza":"PS","Pacific/Kosrae":"FM","America/Aruba":"AW","America/Nassau":"BS","Asia/Choibalsan":"MN","America/Winnipeg":"CA","America/Anguilla":"AI","Asia/Thimphu":"BT","Asia/Beirut":"LB","Atlantic/Faroe":"FO","Europe/Berlin":"DE","Europe/Amsterdam":"NL","Pacific/Honolulu":"US","America/Regina":"CA","America/Scoresbysund":"GL","Europe/Vienna":"AT","Europe/Tirane":"AL","Africa/El_Aaiun":"EH","America/Creston":"CA","Asia/Qostanay":"KZ","Asia/Ho_Chi_Minh":"VN","Europe/Samara":"RU","Europe/Rome":"IT","Australia/Eucla":"AU","America/El_Salvador":"SV","America/Chicago":"US","Africa/Abidjan":"CI","Asia/Kamchatka":"RU","Pacific/Tarawa":"KI","America/Santiago":"CL","America/Bahia":"BR","Indian/Christmas":"CX","Asia/Atyrau":"KZ","Asia/Dushanbe":"TJ","Europe/Ulyanovsk":"RU","America/Yellowknife":"CA","America/Recife":"BR","Australia/Sydney":"AU","America/Fort_Nelson":"CA","Pacific/Efate":"VU","Europe/Saratov":"RU","Africa/Banjul":"GM","Asia/Omsk":"RU","Europe/Ljubljana":"SI","Europe/Budapest":"HU","Europe/Astrakhan":"RU","America/Argentina/Buenos_Aires":"AR","Pacific/Chatham":"NZ","America/Argentina/Salta":"AR","Africa/Niamey":"NE","Asia/Pontianak":"ID","Indian/Reunion":"RE","Asia/Hong_Kong":"HK","Antarctica/McMurdo":"AQ","Africa/Malabo":"GQ","America/Los_Angeles":"US","America/Argentina/Cordoba":"AR","Pacific/Pohnpei":"FM","America/Tijuana":"MX","America/Campo_Grande":"BR","America/Dawson_Creek":"CA","Asia/Novosibirsk":"RU","Pacific/Pago_Pago":"AS","Asia/Jerusalem":"IL","Europe/Sarajevo":"BA","Africa/Freetown":"SL","Asia/Yekaterinburg":"RU","America/Juneau":"US","Africa/Ouagadougou":"BF","Africa/Monrovia":"LR","Europe/Kiev":"UA","America/Argentina/San_Luis":"AR","Asia/Tokyo":"JP","Asia/Qatar":"QA","America/La_Paz":"BO","America/Bogota":"CO","America/Thule":"GL","Asia/Manila":"PH","Asia/Hovd":"MN","Asia/Tehran":"IR","Atlantic/Madeira":"PT","America/Metlakatla":"US","Europe/Vatican":"VA","Asia/Bishkek":"KG","Asia/Dili":"TL","Antarctica/Palmer":"AQ","Atlantic/Cape_Verde":"CV","Indian/Chagos":"IO","America/Kentucky/Monticello":"US","Africa/Algiers":"DZ","Africa/Maseru":"LS","Asia/Kuala_Lumpur":"MY","Africa/Khartoum":"SD","America/Argentina/Rio_Gallegos":"AR","America/Blanc-Sablon":"CA","Africa/Maputo":"MZ","America/Tortola":"VG","Atlantic/Bermuda":"BM","America/Argentina/Catamarca":"AR","America/Cayman":"KY","America/Puerto_Rico":"PR","Pacific/Majuro":"MH","Europe/Busingen":"DE","Pacific/Midway":"UM","Indian/Cocos":"CC","Asia/Singapore":"SG","America/Boise":"US","America/Nuuk":"GL","America/Goose_Bay":"CA","Australia/Broken_Hill":"AU","Africa/Dar_es_Salaam":"TZ","Africa/Asmara":"ER","Asia/Samarkand":"UZ","Asia/Tbilisi":"GE","America/Argentina/Jujuy":"AR","America/Indiana/Winamac":"US","America/Porto_Velho":"BR","Asia/Magadan":"RU","Europe/Zaporozhye":"UA","Antarctica/Casey":"AQ","Asia/Shanghai":"CN","Pacific/Norfolk":"NF","Europe/Guernsey":"GG","Australia/Brisbane":"AU","Antarctica/DumontDUrville":"AQ","America/Havana":"CU","America/Atikokan":"CA","America/Mexico_City":"MX","America/Rankin_Inlet":"CA","America/Cuiaba":"BR","America/Resolute":"CA","Africa/Ceuta":"ES","Arctic/Longyearbyen":"SJ","Pacific/Guam":"GU","Asia/Damascus":"SY","Asia/Colombo":"LK","Asia/Yerevan":"AM","America/Montserrat":"MS","America/Belem":"BR","Europe/Kaliningrad":"RU","Atlantic/South_Georgia":"GS","Asia/Tashkent":"UZ","Asia/Kolkata":"IN","America/St_Johns":"CA","Asia/Srednekolymsk":"RU","Asia/Yakutsk":"RU","Europe/Prague":"CZ","Africa/Djibouti":"DJ","Asia/Dubai":"AE","Europe/Uzhgorod":"UA","America/Edmonton":"CA","Asia/Famagusta":"CY","America/Indiana/Knox":"US","Asia/Hebron":"PS","Asia/Taipei":"TW","Europe/London":"GB","Africa/Dakar":"SN","Australia/Darwin":"AU","America/Glace_Bay":"CA","Antarctica/Vostok":"AQ","America/Indiana/Vincennes":"US","America/Nipigon":"CA","Asia/Kuwait":"KW","Pacific/Guadalcanal":"SB","America/Toronto":"CA","Africa/Gaborone":"BW","Africa/Bujumbura":"BI","Africa/Lubumbashi":"CD","America/Merida":"MX","America/Marigot":"MF","Europe/Zagreb":"HR","Pacific/Easter":"CL","America/Santarem":"BR","Pacific/Noumea":"NC","America/Sitka":"US","Atlantic/Stanley":"FK","Pacific/Funafuti":"TV","America/Iqaluit":"CA","America/Rainy_River":"CA","America/Anchorage":"US","America/Lima":"PE","Asia/Baku":"AZ","America/Indiana/Vevay":"US","Asia/Ulaanbaatar":"MN","America/Managua":"NI","Asia/Krasnoyarsk":"RU","Asia/Qyzylorda":"KZ","America/Eirunepe":"BR","Europe/Podgorica":"ME","Europe/Chisinau":"MD","Europe/Mariehamn":"AX","Europe/Volgograd":"RU","Africa/Nairobi":"KE","Europe/Isle_of_Man":"IM","America/Menominee":"US","Africa/Harare":"ZW","Asia/Anadyr":"RU","America/Moncton":"CA","Indian/Maldives":"MV","America/Whitehorse":"CA","Antarctica/Mawson":"AQ","Europe/Madrid":"ES","America/Argentina/Mendoza":"AR","America/Manaus":"BR","Africa/Bangui":"CF","Indian/Mauritius":"MU","Africa/Tunis":"TN","Australia/Lord_Howe":"AU","America/Kentucky/Louisville":"US","America/North_Dakota/Center":"US","Asia/Novokuznetsk":"RU","Asia/Makassar":"ID","America/Port_of_Spain":"TT","America/Bahia_Banderas":"MX","Pacific/Auckland":"NZ","America/Sao_Paulo":"BR","Asia/Dhaka":"BD","America/Pangnirtung":"CA","Europe/Dublin":"IE","Asia/Brunei":"BN","Africa/Brazzaville":"CG","America/Montevideo":"UY","America/Jamaica":"JM","America/Indiana/Indianapolis":"US","America/Kralendijk":"BQ","Europe/Gibraltar":"GI","Pacific/Marquesas":"PF","Pacific/Apia":"WS","Europe/Jersey":"JE","America/Phoenix":"US","Africa/Ndjamena":"TD","Asia/Karachi":"PK","Africa/Kampala":"UG","Asia/Sakhalin":"RU","America/Martinique":"MQ","Europe/Moscow":"RU","Africa/Conakry":"GN","America/Barbados":"BB","Africa/Lome":"TG","America/Ojinaga":"MX","America/Tegucigalpa":"HN","Asia/Bangkok":"TH","Africa/Johannesburg":"ZA","Europe/Vaduz":"LI","Africa/Sao_Tome":"ST","America/Cambridge_Bay":"CA","America/Lower_Princes":"SX","America/Miquelon":"PM","America/St_Kitts":"KN","Australia/Melbourne":"AU","Europe/Minsk":"BY","Asia/Vladivostok":"RU","Europe/Sofia":"BG","Antarctica/Davis":"AQ","Pacific/Galapagos":"EC","America/North_Dakota/New_Salem":"US","Asia/Amman":"JO","Pacific/Wallis":"WF","America/Hermosillo":"MX","Pacific/Kiritimati":"KI","Antarctica/Macquarie":"AU","America/Guyana":"GY","Asia/Riyadh":"SA","Pacific/Tahiti":"PF","America/St_Vincent":"VC","America/Cancun":"MX","America/Grenada":"GD","Pacific/Wake":"UM","America/Dawson":"CA","Europe/Brussels":"BE","Indian/Kerguelen":"TF","America/Yakutat":"US","Indian/Mahe":"SC","Atlantic/Reykjavik":"IS","America/Panama":"PA","America/Guadeloupe":"GP","Europe/Malta":"MT","Antarctica/Troll":"AQ","Asia/Jayapura":"ID","Asia/Bahrain":"BH","Asia/Chita":"RU","Europe/Tallinn":"EE","Asia/Khandyga":"RU","America/Rio_Branco":"BR","Atlantic/St_Helena":"SH","Africa/Juba":"SS","America/Adak":"US","Pacific/Saipan":"MP","America/St_Lucia":"LC","America/Inuvik":"CA","Europe/Luxembourg":"LU","Africa/Bissau":"GW","Asia/Oral":"KZ","America/Boa_Vista":"BR","Europe/Skopje":"MK","America/Port-au-Prince":"HT","Pacific/Port_Moresby":"PG","Europe/Andorra":"AD","America/Indiana/Marengo":"US","Africa/Kigali":"RW","Africa/Bamako":"ML","America/Dominica":"DM","Asia/Aqtobe":"KZ","Europe/Istanbul":"TR","Pacific/Rarotonga":"CK","America/Danmarkshavn":"GL","Europe/Zurich":"CH","Asia/Yangon":"MM","America/Monterrey":"MX","Europe/Lisbon":"PT","Asia/Kuching":"MY","Antarctica/Rothera":"AQ","Australia/Perth":"AU","Asia/Phnom_Penh":"KH","America/Swift_Current":"CA","Asia/Aqtau":"KZ","Asia/Urumqi":"CN","Asia/Calcutta":"IN"},m=["username","user","user_id","userid","password","pass","pin","passcode","token","api_token","email","address","phone","sex","gender","order","order_id","orderid","payment","credit_card"];function v(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,i=>(+i^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+i/4).toString(16))}function f(i){return!(!i||"string"!=typeof i)&&!(i.length<2||i.length>10240)}function p(i){var e=JSON.stringify(i);return m.forEach(i=>{e=e.replace(new RegExp('("'+i+'"):(".+?"|\\d+)',"gmi"),'$1:"********"')}),e}function g(i,e,a,t){var{capture:r=!1,passive:n=!0}=null!=t?t:{};null==i||i.addEventListener(e,a,{capture:r,passive:n})}var S="undefined"!=typeof window?window:void 0,_="undefined"!=typeof globalThis?globalThis:S,E=null==_?void 0:_.navigator,w=null==_?void 0:_.document,y=null==_?void 0:_.location,C=null==_?void 0:_.fetch,P=(null==_?void 0:_.XMLHttpRequest)&&"withCredentials"in new _.XMLHttpRequest?_.XMLHttpRequest:void 0;null==_||_.AbortController;var M=null==E?void 0:E.userAgent;class R{constructor(i,e){void 0===i&&(i="cookie"),this.storageMethod=i,this.domain=e,this.i=void 0,this.t()}o(){return this.storageMethod===d||this.storageMethod===l}u(){return this.o()?this.storageMethod===d?localStorage:sessionStorage:null}A(i){return{value:i,expiry:(new Date).getTime()+18e5}}l(i){var e=this.u();if(e){var a=this.A(i);e.setItem(t,JSON.stringify(a))}}getSessionIdFromCookie(){var i={};return document.cookie.split(";").forEach(function(e){var[a,t]=e.split("=");i[a.trim()]=t}),i[t]||null}setSessionIdFromCookie(i){var e=t+"="+i+"; Max-Age=1800; path=/; secure";this.domain&&(e+="; domain="+this.domain),document.cookie=e}h(i){this.o()?this.l(i):this.setSessionIdFromCookie(i)}m(){var i=this.u();if(i){var e=i.getItem(t);if(!e)return null;var a=null;try{a=JSON.parse(e)}catch(i){return null}return"object"!=typeof a||null===a?null:(new Date).getTime()>a.expiry?(i.removeItem(t),null):a.value}return this.getSessionIdFromCookie()}getSessionId(){var i=this.m();return i||(i=v(),this.h(i)),i}setSessionId(){var i=this.m()||v();return this.h(i),i}v(){var i=this.u();if(i)i.removeItem(t);else{var e="Thu, 01 Jan 1970 00:00:00 UTC";document.cookie=t+"=; expires="+e+"; path=/;",this.domain&&(document.cookie=t+"=; expires="+e+"; path=/; domain="+this.domain+";")}}resetSessionId(){this.v(),this.setSessionId(),this.p(v())}getWindowId(){if(this.i)return this.i;if(this.S()&&S){var i=S.sessionStorage.getItem(r);if(i)return this.i=i,i}var e=v();return this.p(e),e}p(i){i!==this.i&&(this.i=i,this.S()&&S&&S.sessionStorage.setItem(r,i))}S(){if(void 0===S||!S.sessionStorage)return!1;try{var i="__vt_session_storage_test__";return S.sessionStorage.setItem(i,"test"),S.sessionStorage.removeItem(i),!0}catch(i){return!1}}t(){if(this.S()&&S){var i=S.sessionStorage.getItem(n),e=S.sessionStorage.getItem(r);e&&!i?this.i=e:(e&&S.sessionStorage.removeItem(r),this.p(v())),S.sessionStorage.setItem(n,"true"),this.C()}else this.i=v()}C(){S&&this.S()&&g(S,"beforeunload",()=>{S&&S.sessionStorage&&S.sessionStorage.removeItem(n)},{capture:!1})}}class U{constructor(i,e){void 0===i&&(i="localStorage"),this.P=null,this.storageMethod=i,this.domain=e,this.userIdentity=this.loadUserIdentity()}getUserIdentity(){return e({},this.userIdentity)}getDistinctId(){return this.userIdentity.distinct_id}getAnonymousId(){return this.userIdentity.anonymous_id||(this.userIdentity.anonymous_id=this.generateAnonymousId(),this.saveUserIdentity()),this.userIdentity.anonymous_id}getUserProperties(){return e({},this.userIdentity.properties)}identify(i,a,t){if("number"==typeof i&&(i=i.toString(),console.warn("The first argument to vTilt.identify was a number, but it should be a string. It has been converted to a string.")),i)if(this.isDistinctIdStringLike(i))console.error('The string "'+i+'" was set in vTilt.identify which indicates an error. This ID should be unique to the user and not a hardcoded string.');else if("COOKIELESS_SENTINEL_VALUE"!==i){var r=this.userIdentity.distinct_id,n=this.userIdentity.anonymous_id,s=this.userIdentity.device_id;if(this.userIdentity.distinct_id=i,!this.userIdentity.device_id){var o=r||this.userIdentity.anonymous_id;this.userIdentity.device_id=o,this.userIdentity.properties=e({},this.userIdentity.properties,{$had_persisted_distinct_id:!0,$device_id:o})}i!==r&&(this.userIdentity.distinct_id=i);var c="anonymous"===this.userIdentity.user_state;i!==r&&c?(this.userIdentity.user_state="identified",a&&(this.userIdentity.properties=e({},this.userIdentity.properties,a)),t&&Object.keys(t).forEach(i=>{i in this.userIdentity.properties||(this.userIdentity.properties[i]=t[i])}),this.saveUserIdentity(),this.sendIdentifyEvent(i,n,s,{$set:a||{},$set_once:t||{}})):a||t?("anonymous"===this.userIdentity.user_state&&(this.userIdentity.user_state="identified"),a&&(this.userIdentity.properties=e({},this.userIdentity.properties,a)),t&&Object.keys(t).forEach(i=>{i in this.userIdentity.properties||(this.userIdentity.properties[i]=t[i])}),this.saveUserIdentity(),this.sendSetEvent(a||{},t||{})):i!==r&&(this.userIdentity.user_state="identified",this.saveUserIdentity())}else console.error('The string "'+i+'" was set in vTilt.identify which indicates an error. This ID is only used as a sentinel value.');else console.error("Unique user id has not been set in vTilt.identify")}setUserProperties(i,a){if(i||a){var t=this.userIdentity.distinct_id||this.userIdentity.anonymous_id,r=this.getPersonPropertiesHash(t,i,a);this.P!==r?(i&&(this.userIdentity.properties=e({},this.userIdentity.properties,i)),a&&Object.keys(a).forEach(i=>{i in this.userIdentity.properties||(this.userIdentity.properties[i]=a[i])}),this.saveUserIdentity(),this.sendSetEvent(i||{},a||{}),this.P=r):console.info("VTilt: A duplicate setUserProperties call was made with the same properties. It has been ignored.")}}getPersonPropertiesHash(i,e,a){return JSON.stringify({distinct_id:i,userPropertiesToSet:e,userPropertiesToSetOnce:a})}sendSetEvent(i,e){var a=new CustomEvent("vtilt:set",{detail:{$set:i||{},$set_once:e||{}}});window.dispatchEvent(a)}reset(i){var a=this.generateAnonymousId(),t=this.userIdentity.device_id,r=i?this.generateDeviceId():t;this.userIdentity={distinct_id:null,anonymous_id:a,device_id:r,properties:{},user_state:"anonymous"},this.P=null,this.saveUserIdentity(),this.userIdentity.properties=e({},this.userIdentity.properties,{$last_posthog_reset:(new Date).toISOString()}),this.saveUserIdentity()}getEffectiveId(){return this.userIdentity.distinct_id||this.getAnonymousId()}getDeviceId(){return this.userIdentity.device_id}getUserState(){return this.userIdentity.user_state}createAlias(i,e){if(this.isValidDistinctId(i))if(void 0===e&&(e=this.getDistinctId()||this.getAnonymousId()),this.isValidDistinctId(e)){if(i===e)return console.warn("alias matches current distinct_id - calling identify instead"),void this.identify(i);var a=new CustomEvent("vtilt:alias",{detail:{distinct_id:i,original:e}});window.dispatchEvent(a)}else console.warn("Invalid original distinct ID");else console.warn("Invalid alias provided")}isValidDistinctId(i){if(!i||"string"!=typeof i)return!1;var e=i.toLowerCase().trim();return!["null","undefined","false","true","anonymous","anon","user","test","guest","visitor","unknown","none"].includes(e)&&0!==i.trim().length}isDistinctIdStringLike(i){if(!i||"string"!=typeof i)return!1;var e=i.toLowerCase().trim();return["null","undefined","false","true","anonymous","anon","user","test","guest","visitor","unknown","none","demo","example","sample","placeholder"].includes(e)}loadUserIdentity(){var i=this.getStoredValue(s)||this.generateAnonymousId(),e=this.getStoredValue(o)||null,a=this.getStoredValue(c)||this.generateDeviceId(),t=this.getStoredUserProperties(),r=this.getStoredValue(A)||"anonymous";return{distinct_id:e,anonymous_id:i||this.generateAnonymousId(),device_id:a,properties:t,user_state:r}}saveUserIdentity(){this.setStoredValue(s,this.userIdentity.anonymous_id),this.setStoredValue(c,this.userIdentity.device_id),this.setStoredValue(A,this.userIdentity.user_state),this.userIdentity.distinct_id?this.setStoredValue(o,this.userIdentity.distinct_id):this.removeStoredValue(o),this.setStoredUserProperties(this.userIdentity.properties)}generateAnonymousId(){return"anon_"+v()}generateDeviceId(){return"device_"+v()}sendIdentifyEvent(i,a,t,r){var n=new CustomEvent("vtilt:identify",{detail:{distinct_id:i,anonymous_id:a,device_id:t,properties:e({$anon_distinct_id:a,$device_id:t},r)}});window.dispatchEvent(n)}getStoredValue(i){try{return this.storageMethod===d?localStorage.getItem(i):this.storageMethod===l?sessionStorage.getItem(i):this.getCookieValue(i)}catch(i){return console.warn("Failed to access storage:",i),null}}setStoredValue(i,e){try{this.storageMethod===d?localStorage.setItem(i,e):this.storageMethod===l?sessionStorage.setItem(i,e):this.setCookieValue(i,e)}catch(i){console.warn("Failed to save to storage:",i)}}removeStoredValue(i){this.storageMethod===d?localStorage.removeItem(i):this.storageMethod===l?sessionStorage.removeItem(i):this.removeCookieValue(i)}getStoredUserProperties(){var i=this.getStoredValue(u);if(!i)return{};try{return JSON.parse(i)}catch(i){return{}}}setStoredUserProperties(i){this.setStoredValue(u,JSON.stringify(i))}getCookieValue(i){var e=document.cookie.split(";");for(var a of e){var[t,r]=a.trim().split("=");if(t===i)return decodeURIComponent(r)}return null}setCookieValue(i,e){var a=i+"="+encodeURIComponent(e)+"; Max-Age=31536000; path=/; secure; SameSite=Lax";this.domain&&(a+="; domain="+this.domain),document.cookie=a}removeCookieValue(i){var e=i+"=; Max-Age=0; path=/";this.domain&&(e+="; domain="+this.domain),document.cookie=e}}var I="Mobile",k="iOS",b="Android",B="Tablet",T=b+" "+B,x="iPad",N="Apple",D=N+" Watch",K="Safari",L="BlackBerry",O="Samsung",G=O+"Browser",V=O+" Internet",F="Chrome",W=F+" OS",j=F+" "+k,H="Internet Explorer",J=H+" "+I,Z="Opera",z=Z+" Mini",X="Edge",Y="Microsoft "+X,Q="Firefox",q=Q+" "+k,ii="Nintendo",ei="PlayStation",ai="Xbox",ti=b+" "+I,ri=I+" "+K,ni="Windows",si=ni+" Phone",oi="Nokia",ci="Ouya",ui="Generic",Ai=ui+" "+I.toLowerCase(),di=ui+" "+B.toLowerCase(),li="Konqueror",hi="(\\d+(\\.\\d+)?)",mi=new RegExp("Version/"+hi),vi=new RegExp(ai,"i"),fi=new RegExp(ei+" \\w+","i"),pi=new RegExp(ii+" \\w+","i"),gi=new RegExp(L+"|PlayBook|BB10","i"),Si={"NT3.51":"NT 3.11","NT4.0":"NT 4.0","5.0":"2000",5.1:"XP",5.2:"XP","6.0":"Vista",6.1:"7",6.2:"8",6.3:"8.1",6.4:"10","10.0":"10"};function _i(i,e){return i.toLowerCase().includes(e.toLowerCase())}var Ei=(i,e)=>e&&_i(e,N)||function(i){return _i(i,K)&&!_i(i,F)&&!_i(i,b)}(i),wi=function(i,e){return e=e||"",_i(i," OPR/")&&_i(i,"Mini")?z:_i(i," OPR/")?Z:gi.test(i)?L:_i(i,"IE"+I)||_i(i,"WPDesktop")?J:_i(i,G)?V:_i(i,X)||_i(i,"Edg/")?Y:_i(i,"FBIOS")?"Facebook "+I:_i(i,"UCWEB")||_i(i,"UCBrowser")?"UC Browser":_i(i,"CriOS")?j:_i(i,"CrMo")||_i(i,F)?F:_i(i,b)&&_i(i,K)?ti:_i(i,"FxiOS")?q:_i(i.toLowerCase(),li.toLowerCase())?li:Ei(i,e)?_i(i,I)?ri:K:_i(i,Q)?Q:_i(i,"MSIE")||_i(i,"Trident/")?H:_i(i,"Gecko")?Q:""},yi={[J]:[new RegExp("rv:"+hi)],[Y]:[new RegExp(X+"?\\/"+hi)],[F]:[new RegExp("("+F+"|CrMo)\\/"+hi)],[j]:[new RegExp("CriOS\\/"+hi)],"UC Browser":[new RegExp("(UCBrowser|UCWEB)\\/"+hi)],[K]:[mi],[ri]:[mi],[Z]:[new RegExp("(Opera|OPR)\\/"+hi)],[Q]:[new RegExp(Q+"\\/"+hi)],[q]:[new RegExp("FxiOS\\/"+hi)],[li]:[new RegExp("Konqueror[:/]?"+hi,"i")],[L]:[new RegExp(L+" "+hi),mi],[ti]:[new RegExp("android\\s"+hi,"i")],[V]:[new RegExp(G+"\\/"+hi)],[H]:[new RegExp("(rv:|MSIE )"+hi)],Mozilla:[new RegExp("rv:"+hi)]};function Ci(i){return"function"==typeof i}var Pi=[[new RegExp(ai+"; "+ai+" (.*?)[);]","i"),i=>[ai,i&&i[1]||""]],[new RegExp(ii,"i"),[ii,""]],[new RegExp(ei,"i"),[ei,""]],[gi,[L,""]],[new RegExp(ni,"i"),(i,e)=>{if(/Phone/.test(e)||/WPDesktop/.test(e))return[si,""];if(new RegExp(I).test(e)&&!/IEMobile\b/.test(e))return[ni+" "+I,""];var a=/Windows NT ([0-9.]+)/i.exec(e);if(a&&a[1]){var t=a[1],r=Si[t]||"";return/arm/i.test(e)&&(r="RT"),[ni,r]}return[ni,""]}],[/((iPhone|iPad|iPod).*?OS (\d+)_(\d+)_?(\d+)?|iPhone)/,i=>{if(i&&i[3]){var e=[i[3],i[4],i[5]||"0"];return[k,e.join(".")]}return[k,""]}],[/(watch.*\/(\d+\.\d+\.\d+)|watch os,(\d+\.\d+),)/i,i=>{var e="";return i&&i.length>=3&&(e=void 0===i[2]?i[3]:i[2]),["watchOS",e]}],[new RegExp("("+b+" (\\d+)\\.(\\d+)\\.?(\\d+)?|"+b+")","i"),i=>{if(i&&i[2]){var e=[i[2],i[3],i[4]||"0"];return[b,e.join(".")]}return[b,""]}],[/Mac OS X (\d+)[_.](\d+)[_.]?(\d+)?/i,i=>{var e=["Mac OS X",""];if(i&&i[1]){var a=[i[1],i[2],i[3]||"0"];e[1]=a.join(".")}return e}],[/Mac/i,["Mac OS X",""]],[/CrOS/,[W,""]],[/Linux|debian/i,["Linux",""]]],Mi=function(i){return pi.test(i)?ii:fi.test(i)?ei:vi.test(i)?ai:new RegExp(ci,"i").test(i)?ci:new RegExp("("+si+"|WPDesktop)","i").test(i)?si:/iPad/.test(i)?x:/iPod/.test(i)?"iPod Touch":/iPhone/.test(i)?"iPhone":/(watch)(?: ?os[,/]|\d,\d\/)[\d.]+/i.test(i)?D:gi.test(i)?L:/(kobo)\s(ereader|touch)/i.test(i)?"Kobo":new RegExp(oi,"i").test(i)?oi:/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(i)||/(kf[a-z]+)( bui|\)).+silk\//i.test(i)?"Kindle Fire":/(Android|ZTE)/i.test(i)?!new RegExp(I).test(i)||/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(i)?/pixel[\daxl ]{1,6}/i.test(i)&&!/pixel c/i.test(i)||/(huaweimed-al00|tah-|APA|SM-G92|i980|zte|U304AA)/i.test(i)||/lmy47v/i.test(i)&&!/QTAQZ3/i.test(i)?b:T:b:new RegExp("(pda|"+I+")","i").test(i)?Ai:new RegExp(B,"i").test(i)&&!new RegExp(B+" pc","i").test(i)?di:""};function Ri(){if(void 0!==E)return E.language||E.userLanguage}function Ui(){var i={};if(!M)return i;var[e,a]=function(i){for(var e=0;e<Pi.length;e++){var[a,t]=Pi[e],r=a.exec(i);if(r){var n=void 0;if(n=Ci(t)?t(r,i):t)return n}}return["",""]}(M);e&&(i.$os=e),a&&(i.$os_version=a);var t=wi(M,null==E?void 0:E.vendor);t&&(i.$browser=t);var r=function(i,e){var a=wi(i,e),t=yi[a];if(void 0===t)return null;for(var r=0;r<t.length;r++){var n=t[r],s=i.match(n);if(s)return parseFloat(s[s.length-2])}return null}(M,null==E?void 0:E.vendor);r&&(i.$browser_version=r);var n=Mi(M);n&&(i.$device=n);var s=function(i){var e=Mi(i);return e===x||e===T||"Kobo"===e||"Kindle Fire"===e||e===di?B:e===ii||e===ai||e===ei||e===ci?"Console":e===D?"Wearable":e?I:"Desktop"}(M);s&&(i.$device_type=s);var o=function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(i){return}}();o&&(i.$timezone=o);var c=function(){try{return(new Date).getTimezoneOffset()}catch(i){return}}();void 0!==c&&(i.$timezone_offset=c),y&&(i.$current_url=y.href,i.$host=y.host,i.$pathname=y.pathname),M&&(i.$raw_user_agent=M.length>1e3?M.substring(0,997)+"...":M);var u,A=Ri(),d="string"==typeof(u=Ri())?u.split("-")[0]:void 0;return A&&(i.$browser_language=A),d&&(i.$browser_language_prefix=d),(null==S?void 0:S.screen)&&(S.screen.height&&(i.$screen_height=S.screen.height),S.screen.width&&(i.$screen_width=S.screen.width)),S&&(S.innerHeight&&(i.$viewport_height=S.innerHeight),S.innerWidth&&(i.$viewport_width=S.innerWidth)),i.$lib="web",i.$lib_version="1.0.7",i.$insert_id=Math.random().toString(36).substring(2,10)+Math.random().toString(36).substring(2,10),i.$time=Date.now()/1e3,i.$referrer=(null==w?void 0:w.referrer)||"$direct",i.$referring_domain=function(){if(!(null==w?void 0:w.referrer))return"$direct";try{return new URL(w.referrer).host||"$direct"}catch(i){return"$direct"}}(),i}class Ii{constructor(i){this.__request_queue=[],this.M=!1,this.config=i,!this.config.domain&&y&&(this.config.domain=this.getCurrentDomain()),this.sessionManager=new R(i.storage||"cookie",this.config.domain),this.userManager=new U(i.persistence||"localStorage",this.config.domain),this.setupIdentifyListener()}getCurrentDomain(){if(!y)return"";var i=y.protocol,e=y.hostname,a=y.port;return i+"//"+e+(a?":"+a:"")}R(){return!(!this.config.projectId||!this.config.token)||(this.M||(console.warn("VTilt: projectId and token are required for tracking. Events will be skipped until init() or updateConfig() is called with these fields."),this.M=!0),!1)}sendEvent(a,t){var r,n=this;return(r=function*(){if(n.sessionManager.setSessionId(),E&&E.userAgent&&function(i){return!(i&&"string"==typeof i&&i.length>500)}(E.userAgent)){var i,r=n.buildUrl(),s=e({},Ui(),{$session_id:n.sessionManager.getSessionId(),$window_id:n.sessionManager.getWindowId()},t);if("$pageview"===a&&w&&(s.title=w.title),!1!==n.config.stringifyPayload){if(i=p(s),i=Object.assign({},JSON.parse(i),n.config.globalAttributes),!f(i=JSON.stringify(i)))return}else{var o=p(i=Object.assign({},s,n.config.globalAttributes));if(!f(o))return;i=JSON.parse(o)}var c=n.userManager.getDistinctId(),u=n.userManager.getAnonymousId(),A={timestamp:(new Date).toISOString(),event:a,tenant_id:n.config.projectId||"",domain:n.config.domain||n.getCurrentDomain(),payload:i,distinct_id:c||u};n.sendRequest(r,A,!0)}},function(){var e=this,a=arguments;return new Promise(function(t,n){var s=r.apply(e,a);function o(e){i(s,t,n,o,c,"next",e)}function c(e){i(s,t,n,o,c,"throw",e)}o(void 0)})})()}buildUrl(){var{proxyUrl:i,proxy:e,host:a,token:t}=this.config;return i||(e?e+"/api/tracking?token="+t:a?a.replace(/\/+$/gm,"")+"/api/tracking?token="+t:"/api/tracking?token="+t)}sendRequest(i,e,a){if(this.R()){if(a&&void 0!==S)if(S.__VTILT_ENQUEUE_REQUESTS)return void this.__request_queue.push({url:i,event:e});var t=new XMLHttpRequest;t.open("POST",i,!0),t.setRequestHeader("Content-Type","application/json"),t.send(JSON.stringify(e))}}U(i){this.sendRequest(i.url,i.event,!1)}getSessionId(){return this.sessionManager.getSessionId()}identify(i,e,a){this.userManager.identify(i,e,a)}setUserProperties(i,e){this.userManager.setUserProperties(i,e)}resetUser(i){this.sessionManager.resetSessionId(),this.userManager.reset(i)}getUserIdentity(){return this.userManager.getUserIdentity()}getDeviceId(){return this.userManager.getDeviceId()}getUserState(){return this.userManager.getUserState()}createAlias(i,e){this.userManager.createAlias(i,e)}setupIdentifyListener(){S&&(S.addEventListener("vtilt:identify",i=>{var e=i,{distinct_id:a,anonymous_id:t,device_id:r,properties:n}=e.detail;this.sendIdentifyEvent(a,t,r,n)}),S.addEventListener("vtilt:set",i=>{var e=i,{$set:a,$set_once:t}=e.detail;this.sendSetEvent(a||{},t||{})}),S.addEventListener("vtilt:alias",i=>{var e=i.detail;this.sendAliasEvent(e)}))}I(){return{session_id:this.sessionManager.getSessionId(),window_id:this.sessionManager.getWindowId()}}k(i,e,a){return{timestamp:(new Date).toISOString(),event:i,tenant_id:this.config.projectId||"",domain:this.config.domain||this.getCurrentDomain(),payload:e,distinct_id:a}}sendIdentifyEvent(i,a,t,r){var{session_id:n,window_id:s}=this.I(),o=e({$session_id:n,$window_id:s,$anon_distinct_id:a,$device_id:t},r),c=this.k("$identify",o,i);this.sendRequest(this.buildUrl(),c,!0)}sendSetEvent(i,e){var{session_id:a,window_id:t}=this.I(),r=this.userManager.getDistinctId(),n=this.userManager.getAnonymousId(),s={$session_id:a,$window_id:t,$set:i||{},$set_once:e||{}},o=this.k("$set",s,r||n);this.sendRequest(this.buildUrl(),o,!0)}sendAliasEvent(i){var{session_id:e,window_id:a}=this.I(),t={$session_id:e,$window_id:a,$original_id:i.original,$alias_id:i.distinct_id},r=this.k("$alias",t,i.distinct_id);this.sendRequest(this.buildUrl(),r,!0)}}class ki{constructor(i,e){if(this.trackingManager=e,i.webVitals&&S)try{this.webVitals=require("web-vitals"),this.initializeWebVitals()}catch(i){console.warn("web-vitals library not found. Please install it to enable web vitals tracking.",i)}}initializeWebVitals(){if(this.webVitals){var i=i=>{try{if(!(S&&w&&E&&y))return;var{country:e,locale:a}=function(){var i,e;if(!E)return{country:i,locale:e};try{var a=Intl.DateTimeFormat().resolvedOptions().timeZone;i=h[a],e=E.languages&&E.languages.length?E.languages[0]:E.userLanguage||E.language||E.browserLanguage||"en"}catch(i){}return{country:i,locale:e}}();this.trackingManager.sendEvent("web_vital",{name:i.name,value:i.value,delta:i.delta,rating:i.rating,id:i.id,navigationType:i.navigationType,pathname:y.pathname,href:y.href,"user-agent":E.userAgent,locale:a,location:e,referrer:w.referrer})}catch(i){console.error("Error sending web vital:",i)}};this.webVitals.onCLS&&this.webVitals.onCLS(i),this.webVitals.onFCP&&this.webVitals.onFCP(i),this.webVitals.onLCP&&this.webVitals.onLCP(i),this.webVitals.onTTFB&&this.webVitals.onTTFB(i),this.webVitals.onINP&&this.webVitals.onINP(i)}}}function bi(i,e,a){try{if(!(e in i))return()=>{};var t=i[e],r=a(t);return"function"==typeof r&&(r.prototype=r.prototype||{},Object.defineProperties(r,{__vtilt_wrapped__:{enumerable:!1,value:!0}})),i[e]=r,()=>{i[e]=t}}catch(i){return()=>{}}}class Bi{constructor(i){var e;this._instance=i,this.B=(null===(e=null==S?void 0:S.location)||void 0===e?void 0:e.pathname)||""}get isEnabled(){return!0}startIfEnabled(){this.isEnabled&&this.monitorHistoryChanges()}stop(){this.T&&this.T(),this.T=void 0}monitorHistoryChanges(){var i,e;if(S&&y&&(this.B=y.pathname||"",S.history)){var a=this;(null===(i=S.history.pushState)||void 0===i?void 0:i.__vtilt_wrapped__)||bi(S.history,"pushState",i=>function(e,t,r){i.call(this,e,t,r),a.N("pushState")}),(null===(e=S.history.replaceState)||void 0===e?void 0:e.__vtilt_wrapped__)||bi(S.history,"replaceState",i=>function(e,t,r){i.call(this,e,t,r),a.N("replaceState")}),this.D()}}N(i){var e;try{var a=null===(e=null==S?void 0:S.location)||void 0===e?void 0:e.pathname;if(!a||!y||!w)return;if(a!==this.B&&this.isEnabled){var t={navigation_type:i};this._instance.trackingManager.sendEvent("$pageview",t)}this.B=a}catch(e){console.error("Error capturing "+i+" pageview",e)}}D(){if(!this.T&&S){var i=()=>{this.N("popstate")};g(S,"popstate",i),this.T=()=>{S&&S.removeEventListener("popstate",i)}}}}class Ti{constructor(i){void 0===i&&(i={}),this.__loaded=!1,this.K=!1,this.L=null,this.configManager=new a(i),this.trackingManager=new Ii(this.configManager.getConfig()),this.webVitalsManager=new ki(this.configManager.getConfig(),this.trackingManager)}init(i,e,a){var t;if(a&&a!==Ni){var r=null!==(t=xi[a])&&void 0!==t?t:new Ti;return r._init(i,e,a),xi[a]=r,xi[Ni][a]=r,r}return this._init(i,e,a)}_init(i,a,t){return void 0===a&&(a={}),this.__loaded?(console.warn("vTilt: You have already initialized vTilt! Re-initializing is a no-op"),this):(this.updateConfig(e({},a,{projectId:i||a.projectId,name:t})),this.__loaded=!0,this.historyAutocapture=new Bi(this),this.historyAutocapture.startIfEnabled(),this.O(),this)}toString(){var i,e=null!==(i=this.configManager.getConfig().name)&&void 0!==i?i:Ni;return e!==Ni&&(e=Ni+"."+e),e}trackEvent(i,e){void 0===e&&(e={}),this.trackingManager.sendEvent(i,e)}identify(i,e,a){this.trackingManager.identify(i,e,a)}setUserProperties(i,e){this.trackingManager.setUserProperties(i,e)}resetUser(i){this.trackingManager.resetUser(i)}getUserIdentity(){return this.trackingManager.getUserIdentity()}getDeviceId(){return this.trackingManager.getDeviceId()}getUserState(){return this.trackingManager.getUserState()}createAlias(i,e){this.trackingManager.createAlias(i,e)}O(){w&&("visible"===w.visibilityState?this.K||(this.K=!0,setTimeout(()=>{if(w&&y){this.trackingManager.sendEvent("$pageview",{navigation_type:"initial_load"})}},300),this.L&&(w.removeEventListener("visibilitychange",this.L),this.L=null)):this.L||(this.L=()=>{this.O()},g(w,"visibilitychange",this.L)))}getConfig(){return this.configManager.getConfig()}getSessionId(){return this.trackingManager.getSessionId()}updateConfig(i){this.configManager.updateConfig(i),this.trackingManager=new Ii(this.configManager.getConfig()),this.webVitalsManager=new ki(this.configManager.getConfig(),this.trackingManager)}_execute_array(i){Array.isArray(i)&&i.forEach(i=>{if(i&&Array.isArray(i)&&i.length>0){var e=i[0],a=i.slice(1);if("function"==typeof this[e])try{this[e](...a)}catch(i){console.error("vTilt: Error executing queued call "+e+":",i)}}})}_dom_loaded(){this.trackingManager&&(this.trackingManager.__request_queue.forEach(i=>{this.trackingManager.U(i)}),this.trackingManager.__request_queue=[])}}var xi={},Ni="vt",Di=!(void 0!==P||void 0!==C)&&-1===(null==M?void 0:M.indexOf("MSIE"))&&-1===(null==M?void 0:M.indexOf("Mozilla"));S&&(S.__VTILT_ENQUEUE_REQUESTS=Di);var Ki=function(){function i(){i.done||(i.done=!0,Di=!1,void 0!==S&&(S.__VTILT_ENQUEUE_REQUESTS=!1),function(i,e,a){if(i)if(Array.isArray(i))i.forEach((i,t)=>{e.call(a,i,t)});else for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.call(a,i[t],t)}(xi,function(i){i._dom_loaded()}))}w&&"function"==typeof w.addEventListener?"complete"===w.readyState?i():g(w,"DOMContentLoaded",i,{capture:!1}):S&&console.error("Browser doesn't support `document.addEventListener` so vTilt couldn't be initialized")};var Li,Oi=(Li=xi[Ni]=new Ti,Ki(),Li);export{Ti as VTilt,Oi as default,Oi as vt};
2
2
  //# sourceMappingURL=module.js.map