@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.
- package/LICENSE +21 -0
- 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 +2 -0
- package/dist/extensions/history-autocapture.d.ts +19 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +192 -18
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +192 -18
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/session.d.ts +61 -4
- package/dist/tracking.d.ts +12 -4
- package/dist/types.d.ts +1 -1
- package/dist/utils/event-utils.d.ts +35 -0
- package/dist/utils/patch.d.ts +8 -0
- package/dist/utils/user-agent-utils.d.ts +18 -0
- package/dist/vtilt.d.ts +58 -20
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +3 -1
- package/lib/extensions/history-autocapture.d.ts +19 -0
- package/lib/extensions/history-autocapture.js +107 -0
- package/lib/session.d.ts +61 -4
- package/lib/session.js +197 -41
- package/lib/tracking.d.ts +12 -4
- package/lib/tracking.js +65 -70
- package/lib/types.d.ts +1 -1
- package/lib/utils/event-utils.d.ts +35 -0
- package/lib/utils/event-utils.js +178 -0
- package/lib/utils/patch.d.ts +8 -0
- package/lib/utils/patch.js +44 -0
- package/lib/utils/user-agent-utils.d.ts +18 -0
- package/lib/utils/user-agent-utils.js +423 -0
- package/lib/vtilt.d.ts +58 -20
- package/lib/vtilt.js +168 -142
- package/package.json +12 -13
- package/dist/utils.d.ts +0 -21
- package/lib/utils.d.ts +0 -21
- package/lib/utils.js +0 -57
package/lib/tracking.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.TrackingManager = void 0;
|
|
|
4
4
|
const session_1 = require("./session");
|
|
5
5
|
const user_manager_1 = require("./user-manager");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
const
|
|
7
|
+
const event_utils_1 = require("./utils/event-utils");
|
|
8
8
|
const globals_1 = require("./utils/globals");
|
|
9
9
|
class TrackingManager {
|
|
10
10
|
constructor(config) {
|
|
@@ -53,6 +53,9 @@ class TrackingManager {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Send event to endpoint
|
|
56
|
+
* PostHog-style: Automatically adds common properties to all events
|
|
57
|
+
* ($current_url, $host, $pathname, $referrer, $referring_domain, $browser_language, etc.)
|
|
58
|
+
* Also adds title property for $pageview events only
|
|
56
59
|
*/
|
|
57
60
|
async sendEvent(name, payload) {
|
|
58
61
|
this.sessionManager.setSessionId();
|
|
@@ -64,9 +67,26 @@ class TrackingManager {
|
|
|
64
67
|
return;
|
|
65
68
|
}
|
|
66
69
|
const url = this.buildUrl();
|
|
70
|
+
// Add properties to all events (PostHog-style)
|
|
71
|
+
// This includes: $current_url, $host, $pathname, $referrer, $referring_domain, $browser_language, etc.
|
|
72
|
+
const eventProperties = (0, event_utils_1.getEventProperties)();
|
|
73
|
+
// Get session and window IDs (PostHog-style)
|
|
74
|
+
// Both methods ensure IDs always exist (generate if needed)
|
|
75
|
+
const session_id = this.sessionManager.getSessionId();
|
|
76
|
+
const window_id = this.sessionManager.getWindowId();
|
|
77
|
+
const enrichedPayload = {
|
|
78
|
+
...eventProperties, // Base properties for all events
|
|
79
|
+
$session_id: session_id, // PostHog-style: session ID in properties
|
|
80
|
+
$window_id: window_id, // PostHog-style: window ID in properties
|
|
81
|
+
...payload, // User-provided payload (can override base properties)
|
|
82
|
+
};
|
|
83
|
+
// Add title only to $pageview events (PostHog-style)
|
|
84
|
+
if (name === "$pageview" && globals_1.document) {
|
|
85
|
+
enrichedPayload.title = globals_1.document.title;
|
|
86
|
+
}
|
|
67
87
|
let processedPayload;
|
|
68
88
|
if (this.config.stringifyPayload !== false) {
|
|
69
|
-
processedPayload = (0, utils_1.maskSuspiciousAttributes)(
|
|
89
|
+
processedPayload = (0, utils_1.maskSuspiciousAttributes)(enrichedPayload);
|
|
70
90
|
processedPayload = Object.assign({}, JSON.parse(processedPayload), this.config.globalAttributes);
|
|
71
91
|
processedPayload = JSON.stringify(processedPayload);
|
|
72
92
|
if (!(0, utils_1.isValidPayload)(processedPayload)) {
|
|
@@ -74,20 +94,19 @@ class TrackingManager {
|
|
|
74
94
|
}
|
|
75
95
|
}
|
|
76
96
|
else {
|
|
77
|
-
processedPayload = Object.assign({},
|
|
97
|
+
processedPayload = Object.assign({}, enrichedPayload, this.config.globalAttributes);
|
|
78
98
|
const maskedStr = (0, utils_1.maskSuspiciousAttributes)(processedPayload);
|
|
79
99
|
if (!(0, utils_1.isValidPayload)(maskedStr)) {
|
|
80
100
|
return;
|
|
81
101
|
}
|
|
82
102
|
processedPayload = JSON.parse(maskedStr);
|
|
83
103
|
}
|
|
84
|
-
|
|
104
|
+
// session_id is already in payload as $session_id (PostHog-style)
|
|
85
105
|
const distinct_id = this.userManager.getDistinctId();
|
|
86
106
|
const anonymous_id = this.userManager.getAnonymousId();
|
|
87
107
|
const trackingEvent = {
|
|
88
108
|
timestamp: new Date().toISOString(),
|
|
89
109
|
event: name,
|
|
90
|
-
session_id,
|
|
91
110
|
tenant_id: this.config.projectId || "",
|
|
92
111
|
domain: this.config.domain || this.getCurrentDomain(), // Use config domain or current domain
|
|
93
112
|
payload: processedPayload,
|
|
@@ -148,35 +167,6 @@ class TrackingManager {
|
|
|
148
167
|
_send_retriable_request(item) {
|
|
149
168
|
this.sendRequest(item.url, item.event, false);
|
|
150
169
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Track page hit
|
|
153
|
-
*/
|
|
154
|
-
trackPageHit() {
|
|
155
|
-
// If test environment
|
|
156
|
-
if ((0, utils_1.isTestEnvironment)()) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
// Only track page hits in browser environment (not SSR)
|
|
160
|
-
if (!globals_1.window || !globals_1.document || !globals_1.navigator || !globals_1.location) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const { country, locale } = (0, geolocation_1.getCountryAndLocale)();
|
|
164
|
-
// Wait a bit for SPA routers
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
// Double-check we're still in browser environment (defensive check)
|
|
167
|
-
if (!globals_1.window || !globals_1.document || !globals_1.navigator || !globals_1.location) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
this.sendEvent("page_hit", {
|
|
171
|
-
"user-agent": globals_1.navigator.userAgent,
|
|
172
|
-
locale,
|
|
173
|
-
location: country,
|
|
174
|
-
referrer: globals_1.document.referrer,
|
|
175
|
-
pathname: globals_1.location.pathname,
|
|
176
|
-
href: globals_1.location.href,
|
|
177
|
-
});
|
|
178
|
-
}, 300);
|
|
179
|
-
}
|
|
180
170
|
/**
|
|
181
171
|
* Get current session ID
|
|
182
172
|
*/
|
|
@@ -270,74 +260,79 @@ class TrackingManager {
|
|
|
270
260
|
this.sendAliasEvent(aliasEvent);
|
|
271
261
|
});
|
|
272
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Get session and window IDs (PostHog-style)
|
|
265
|
+
* Both methods ensure IDs always exist (generate if needed)
|
|
266
|
+
*/
|
|
267
|
+
_getSessionAndWindowIds() {
|
|
268
|
+
return {
|
|
269
|
+
session_id: this.sessionManager.getSessionId(),
|
|
270
|
+
window_id: this.sessionManager.getWindowId(),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Create base tracking event structure
|
|
275
|
+
*/
|
|
276
|
+
_createTrackingEvent(event, payload, distinct_id) {
|
|
277
|
+
return {
|
|
278
|
+
timestamp: new Date().toISOString(),
|
|
279
|
+
event,
|
|
280
|
+
tenant_id: this.config.projectId || "",
|
|
281
|
+
domain: this.config.domain || this.getCurrentDomain(),
|
|
282
|
+
payload,
|
|
283
|
+
distinct_id,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
273
286
|
/**
|
|
274
287
|
* Send identify event for session merging
|
|
275
288
|
*/
|
|
276
289
|
sendIdentifyEvent(distinctId, anonymousId, deviceId, properties) {
|
|
277
|
-
const
|
|
278
|
-
const session_id = this.sessionManager.getSessionId() || (0, utils_1.uuidv4)();
|
|
290
|
+
const { session_id, window_id } = this._getSessionAndWindowIds();
|
|
279
291
|
// Payload contains only properties, not event or distinct_id (those are in trackingEvent)
|
|
292
|
+
// Add $session_id and $window_id to payload (PostHog-style)
|
|
280
293
|
const identifyPayload = {
|
|
294
|
+
$session_id: session_id,
|
|
295
|
+
$window_id: window_id,
|
|
281
296
|
$anon_distinct_id: anonymousId,
|
|
282
297
|
$device_id: deviceId,
|
|
283
298
|
...properties,
|
|
284
299
|
};
|
|
285
|
-
const trackingEvent =
|
|
286
|
-
|
|
287
|
-
event: "$identify",
|
|
288
|
-
session_id,
|
|
289
|
-
tenant_id: this.config.projectId || "",
|
|
290
|
-
domain: this.config.domain || this.getCurrentDomain(),
|
|
291
|
-
payload: identifyPayload,
|
|
292
|
-
distinct_id: distinctId,
|
|
293
|
-
};
|
|
294
|
-
this.sendRequest(url, trackingEvent, true);
|
|
300
|
+
const trackingEvent = this._createTrackingEvent("$identify", identifyPayload, distinctId);
|
|
301
|
+
this.sendRequest(this.buildUrl(), trackingEvent, true);
|
|
295
302
|
}
|
|
296
303
|
/**
|
|
297
304
|
* Send $set event for property updates (PostHog behavior)
|
|
298
305
|
* This notifies Tinybird when user properties are updated
|
|
299
306
|
*/
|
|
300
307
|
sendSetEvent(userPropertiesToSet, userPropertiesToSetOnce) {
|
|
301
|
-
const
|
|
302
|
-
const session_id = this.sessionManager.getSessionId() || (0, utils_1.uuidv4)();
|
|
308
|
+
const { session_id, window_id } = this._getSessionAndWindowIds();
|
|
303
309
|
const distinct_id = this.userManager.getDistinctId();
|
|
304
310
|
const anonymous_id = this.userManager.getAnonymousId();
|
|
311
|
+
// Add $session_id and $window_id to payload (PostHog-style)
|
|
305
312
|
const setEventPayload = {
|
|
313
|
+
$session_id: session_id,
|
|
314
|
+
$window_id: window_id,
|
|
306
315
|
$set: userPropertiesToSet || {},
|
|
307
316
|
$set_once: userPropertiesToSetOnce || {},
|
|
308
317
|
};
|
|
309
|
-
const trackingEvent =
|
|
310
|
-
|
|
311
|
-
event: "$set",
|
|
312
|
-
session_id,
|
|
313
|
-
tenant_id: this.config.projectId || "",
|
|
314
|
-
domain: this.config.domain || this.getCurrentDomain(),
|
|
315
|
-
payload: setEventPayload,
|
|
316
|
-
distinct_id: distinct_id || anonymous_id,
|
|
317
|
-
};
|
|
318
|
-
this.sendRequest(url, trackingEvent, true);
|
|
318
|
+
const trackingEvent = this._createTrackingEvent("$set", setEventPayload, distinct_id || anonymous_id);
|
|
319
|
+
this.sendRequest(this.buildUrl(), trackingEvent, true);
|
|
319
320
|
}
|
|
320
321
|
/**
|
|
321
322
|
* Send alias event for identity linking
|
|
322
323
|
* PostHog format: { alias: alias, distinct_id: original }
|
|
323
324
|
*/
|
|
324
325
|
sendAliasEvent(aliasEvent) {
|
|
325
|
-
const
|
|
326
|
-
|
|
326
|
+
const { session_id, window_id } = this._getSessionAndWindowIds();
|
|
327
|
+
// Add $session_id and $window_id to payload (PostHog-style)
|
|
327
328
|
const aliasPayload = {
|
|
329
|
+
$session_id: session_id,
|
|
330
|
+
$window_id: window_id,
|
|
328
331
|
$original_id: aliasEvent.original,
|
|
329
332
|
$alias_id: aliasEvent.distinct_id,
|
|
330
333
|
};
|
|
331
|
-
const trackingEvent =
|
|
332
|
-
|
|
333
|
-
event: "$alias",
|
|
334
|
-
session_id,
|
|
335
|
-
tenant_id: this.config.projectId || "",
|
|
336
|
-
domain: this.config.domain || this.getCurrentDomain(),
|
|
337
|
-
payload: aliasPayload,
|
|
338
|
-
distinct_id: aliasEvent.distinct_id,
|
|
339
|
-
};
|
|
340
|
-
this.sendRequest(url, trackingEvent, true);
|
|
334
|
+
const trackingEvent = this._createTrackingEvent("$alias", aliasPayload, aliasEvent.distinct_id);
|
|
335
|
+
this.sendRequest(this.buildUrl(), trackingEvent, true);
|
|
341
336
|
}
|
|
342
337
|
}
|
|
343
338
|
exports.TrackingManager = TrackingManager;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export 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 @@ export interface EventPayload {
|
|
|
35
36
|
export 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;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get browser language (PostHog-style)
|
|
3
|
+
* Returns the browser's language setting (e.g., "en-US")
|
|
4
|
+
*/
|
|
5
|
+
export declare function getBrowserLanguage(): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Get browser language prefix (PostHog-style)
|
|
8
|
+
* Returns the language code without region (e.g., "en" from "en-US")
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBrowserLanguagePrefix(): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Get referrer (PostHog-style)
|
|
13
|
+
* Returns document.referrer or '$direct' if no referrer
|
|
14
|
+
*/
|
|
15
|
+
export declare function getReferrer(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Get referring domain (PostHog-style)
|
|
18
|
+
* Returns the hostname of the referrer URL or '$direct' if no referrer
|
|
19
|
+
*/
|
|
20
|
+
export declare function getReferringDomain(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get timezone (PostHog-style)
|
|
23
|
+
* Returns the timezone (e.g., "America/New_York")
|
|
24
|
+
*/
|
|
25
|
+
export declare function getTimezone(): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Get timezone offset (PostHog-style)
|
|
28
|
+
* Returns the timezone offset in minutes
|
|
29
|
+
*/
|
|
30
|
+
export declare function getTimezoneOffset(): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get event properties that should be added to all events (PostHog-style)
|
|
33
|
+
* Matches PostHog's getEventProperties() implementation
|
|
34
|
+
*/
|
|
35
|
+
export declare function getEventProperties(): Record<string, any>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrowserLanguage = getBrowserLanguage;
|
|
4
|
+
exports.getBrowserLanguagePrefix = getBrowserLanguagePrefix;
|
|
5
|
+
exports.getReferrer = getReferrer;
|
|
6
|
+
exports.getReferringDomain = getReferringDomain;
|
|
7
|
+
exports.getTimezone = getTimezone;
|
|
8
|
+
exports.getTimezoneOffset = getTimezoneOffset;
|
|
9
|
+
exports.getEventProperties = getEventProperties;
|
|
10
|
+
const globals_1 = require("./globals");
|
|
11
|
+
const user_agent_utils_1 = require("./user-agent-utils");
|
|
12
|
+
// Library version - should match package.json version
|
|
13
|
+
const LIB_VERSION = "1.0.7"; // TODO: Auto-import from package.json
|
|
14
|
+
/**
|
|
15
|
+
* Get browser language (PostHog-style)
|
|
16
|
+
* Returns the browser's language setting (e.g., "en-US")
|
|
17
|
+
*/
|
|
18
|
+
function getBrowserLanguage() {
|
|
19
|
+
if (typeof globals_1.navigator === "undefined") {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return (globals_1.navigator.language || // Any modern browser
|
|
23
|
+
globals_1.navigator.userLanguage // IE11
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get browser language prefix (PostHog-style)
|
|
28
|
+
* Returns the language code without region (e.g., "en" from "en-US")
|
|
29
|
+
*/
|
|
30
|
+
function getBrowserLanguagePrefix() {
|
|
31
|
+
const lang = getBrowserLanguage();
|
|
32
|
+
return typeof lang === "string" ? lang.split("-")[0] : undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get referrer (PostHog-style)
|
|
36
|
+
* Returns document.referrer or '$direct' if no referrer
|
|
37
|
+
*/
|
|
38
|
+
function getReferrer() {
|
|
39
|
+
return (globals_1.document === null || globals_1.document === void 0 ? void 0 : globals_1.document.referrer) || "$direct";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get referring domain (PostHog-style)
|
|
43
|
+
* Returns the hostname of the referrer URL or '$direct' if no referrer
|
|
44
|
+
*/
|
|
45
|
+
function getReferringDomain() {
|
|
46
|
+
if (!(globals_1.document === null || globals_1.document === void 0 ? void 0 : globals_1.document.referrer)) {
|
|
47
|
+
return "$direct";
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const url = new URL(globals_1.document.referrer);
|
|
51
|
+
return url.host || "$direct";
|
|
52
|
+
}
|
|
53
|
+
catch (_a) {
|
|
54
|
+
return "$direct";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get timezone (PostHog-style)
|
|
59
|
+
* Returns the timezone (e.g., "America/New_York")
|
|
60
|
+
*/
|
|
61
|
+
function getTimezone() {
|
|
62
|
+
try {
|
|
63
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get timezone offset (PostHog-style)
|
|
71
|
+
* Returns the timezone offset in minutes
|
|
72
|
+
*/
|
|
73
|
+
function getTimezoneOffset() {
|
|
74
|
+
try {
|
|
75
|
+
return new Date().getTimezoneOffset();
|
|
76
|
+
}
|
|
77
|
+
catch (_a) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generate insert ID for deduplication (PostHog-style)
|
|
83
|
+
*/
|
|
84
|
+
function generateInsertId() {
|
|
85
|
+
return (Math.random().toString(36).substring(2, 10) +
|
|
86
|
+
Math.random().toString(36).substring(2, 10));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get event properties that should be added to all events (PostHog-style)
|
|
90
|
+
* Matches PostHog's getEventProperties() implementation
|
|
91
|
+
*/
|
|
92
|
+
function getEventProperties() {
|
|
93
|
+
const props = {};
|
|
94
|
+
if (!globals_1.userAgent) {
|
|
95
|
+
return props;
|
|
96
|
+
}
|
|
97
|
+
// Device/OS properties
|
|
98
|
+
const [os_name, os_version] = (0, user_agent_utils_1.detectOS)(globals_1.userAgent);
|
|
99
|
+
if (os_name) {
|
|
100
|
+
props.$os = os_name;
|
|
101
|
+
}
|
|
102
|
+
if (os_version) {
|
|
103
|
+
props.$os_version = os_version;
|
|
104
|
+
}
|
|
105
|
+
const browser = (0, user_agent_utils_1.detectBrowser)(globals_1.userAgent, globals_1.navigator === null || globals_1.navigator === void 0 ? void 0 : globals_1.navigator.vendor);
|
|
106
|
+
if (browser) {
|
|
107
|
+
props.$browser = browser;
|
|
108
|
+
}
|
|
109
|
+
const browserVersion = (0, user_agent_utils_1.detectBrowserVersion)(globals_1.userAgent, globals_1.navigator === null || globals_1.navigator === void 0 ? void 0 : globals_1.navigator.vendor);
|
|
110
|
+
if (browserVersion) {
|
|
111
|
+
props.$browser_version = browserVersion;
|
|
112
|
+
}
|
|
113
|
+
const device = (0, user_agent_utils_1.detectDevice)(globals_1.userAgent);
|
|
114
|
+
if (device) {
|
|
115
|
+
props.$device = device;
|
|
116
|
+
}
|
|
117
|
+
const deviceType = (0, user_agent_utils_1.detectDeviceType)(globals_1.userAgent);
|
|
118
|
+
if (deviceType) {
|
|
119
|
+
props.$device_type = deviceType;
|
|
120
|
+
}
|
|
121
|
+
// Timezone properties
|
|
122
|
+
const timezone = getTimezone();
|
|
123
|
+
if (timezone) {
|
|
124
|
+
props.$timezone = timezone;
|
|
125
|
+
}
|
|
126
|
+
const timezoneOffset = getTimezoneOffset();
|
|
127
|
+
if (timezoneOffset !== undefined) {
|
|
128
|
+
props.$timezone_offset = timezoneOffset;
|
|
129
|
+
}
|
|
130
|
+
// URL properties (added to all events)
|
|
131
|
+
if (globals_1.location) {
|
|
132
|
+
props.$current_url = globals_1.location.href;
|
|
133
|
+
props.$host = globals_1.location.host;
|
|
134
|
+
props.$pathname = globals_1.location.pathname;
|
|
135
|
+
}
|
|
136
|
+
// User agent
|
|
137
|
+
if (globals_1.userAgent) {
|
|
138
|
+
props.$raw_user_agent =
|
|
139
|
+
globals_1.userAgent.length > 1000 ? globals_1.userAgent.substring(0, 997) + "..." : globals_1.userAgent;
|
|
140
|
+
}
|
|
141
|
+
// Browser language (added to all events)
|
|
142
|
+
const browserLanguage = getBrowserLanguage();
|
|
143
|
+
const browserLanguagePrefix = getBrowserLanguagePrefix();
|
|
144
|
+
if (browserLanguage) {
|
|
145
|
+
props.$browser_language = browserLanguage;
|
|
146
|
+
}
|
|
147
|
+
if (browserLanguagePrefix) {
|
|
148
|
+
props.$browser_language_prefix = browserLanguagePrefix;
|
|
149
|
+
}
|
|
150
|
+
// Screen/viewport properties
|
|
151
|
+
if (globals_1.window === null || globals_1.window === void 0 ? void 0 : globals_1.window.screen) {
|
|
152
|
+
if (globals_1.window.screen.height) {
|
|
153
|
+
props.$screen_height = globals_1.window.screen.height;
|
|
154
|
+
}
|
|
155
|
+
if (globals_1.window.screen.width) {
|
|
156
|
+
props.$screen_width = globals_1.window.screen.width;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (globals_1.window) {
|
|
160
|
+
if (globals_1.window.innerHeight) {
|
|
161
|
+
props.$viewport_height = globals_1.window.innerHeight;
|
|
162
|
+
}
|
|
163
|
+
if (globals_1.window.innerWidth) {
|
|
164
|
+
props.$viewport_width = globals_1.window.innerWidth;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Library info
|
|
168
|
+
props.$lib = "web";
|
|
169
|
+
props.$lib_version = LIB_VERSION;
|
|
170
|
+
// Insert ID for deduplication
|
|
171
|
+
props.$insert_id = generateInsertId();
|
|
172
|
+
// Timestamp (epoch time in seconds)
|
|
173
|
+
props.$time = Date.now() / 1000;
|
|
174
|
+
// Referrer properties (added to all events)
|
|
175
|
+
props.$referrer = getReferrer();
|
|
176
|
+
props.$referring_domain = getReferringDomain();
|
|
177
|
+
return props;
|
|
178
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch utility for wrapping native methods
|
|
3
|
+
* Based on PostHog's patch implementation from rrweb
|
|
4
|
+
*/
|
|
5
|
+
export declare const isFunction: (f: any) => f is (...args: any[]) => any;
|
|
6
|
+
export declare function patch(source: {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}, name: string, replacement: (...args: unknown[]) => unknown): () => void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Patch utility for wrapping native methods
|
|
4
|
+
* Based on PostHog's patch implementation from rrweb
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isFunction = void 0;
|
|
8
|
+
exports.patch = patch;
|
|
9
|
+
const isFunction = function (f) {
|
|
10
|
+
return typeof f === "function";
|
|
11
|
+
};
|
|
12
|
+
exports.isFunction = isFunction;
|
|
13
|
+
function patch(source, name, replacement) {
|
|
14
|
+
try {
|
|
15
|
+
if (!(name in source)) {
|
|
16
|
+
return () => {
|
|
17
|
+
//
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const original = source[name];
|
|
21
|
+
const wrapped = replacement(original);
|
|
22
|
+
// Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
|
|
23
|
+
// otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
|
|
24
|
+
if ((0, exports.isFunction)(wrapped)) {
|
|
25
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
26
|
+
Object.defineProperties(wrapped, {
|
|
27
|
+
__vtilt_wrapped__: {
|
|
28
|
+
enumerable: false,
|
|
29
|
+
value: true,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
source[name] = wrapped;
|
|
34
|
+
return () => {
|
|
35
|
+
source[name] = original;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
return () => {
|
|
40
|
+
//
|
|
41
|
+
};
|
|
42
|
+
// This can throw if multiple fill happens on a global object like XMLHttpRequest
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function detects which browser is running this script.
|
|
3
|
+
* The order of the checks are important since many user agents
|
|
4
|
+
* include keywords used in later checks.
|
|
5
|
+
*/
|
|
6
|
+
export declare const detectBrowser: (user_agent: string, vendor: string | undefined) => string;
|
|
7
|
+
/**
|
|
8
|
+
* This function detects which browser version is running this script,
|
|
9
|
+
* parsing major and minor version (e.g., 42.1). User agent strings from:
|
|
10
|
+
* http://www.useragentstring.com/pages/useragentstring.php
|
|
11
|
+
*
|
|
12
|
+
* `navigator.vendor` is passed in and used to help with detecting certain browsers
|
|
13
|
+
* NB `navigator.vendor` is deprecated and not present in every browser
|
|
14
|
+
*/
|
|
15
|
+
export declare const detectBrowserVersion: (userAgent: string, vendor: string | undefined) => number | null;
|
|
16
|
+
export declare const detectOS: (user_agent: string) => [string, string];
|
|
17
|
+
export declare const detectDevice: (user_agent: string) => string;
|
|
18
|
+
export declare const detectDeviceType: (user_agent: string) => string;
|