@v-tilt/browser 1.0.9 → 1.0.11

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.
@@ -23,3 +23,24 @@ export declare function each<T>(obj: T[] | Record<string, T> | null | undefined,
23
23
  * This properly implements the default options for passive event listeners
24
24
  */
25
25
  export declare function addEventListener(element: Window | Document | Element | undefined, event: string, callback: EventListener, options?: AddEventListenerOptions): void;
26
+ /**
27
+ * Extend object with properties from another object
28
+ */
29
+ export declare function extend<T extends Record<string, any>>(target: T, source: Record<string, any> | null | undefined): T;
30
+ /**
31
+ * Extend array with additional items
32
+ * Mutates the base array and returns it (matches PostHog's behavior)
33
+ */
34
+ export declare function extendArray<T>(base: T[], ...additional: T[][]): T[];
35
+ /**
36
+ * Strip properties with empty values (null, undefined, empty string)
37
+ */
38
+ export declare function stripEmptyProperties<T extends Record<string, any>>(obj: T): Partial<T>;
39
+ /**
40
+ * Strip leading dollar sign from string
41
+ */
42
+ export declare function stripLeadingDollar(str: string): string;
43
+ /**
44
+ * Check if value is null
45
+ */
46
+ export declare function isNull(value: any): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Request utilities
3
+ * Functions for parsing URLs, query parameters, and masking sensitive data
4
+ */
5
+ /**
6
+ * Convert string URL to HTMLAnchorElement for parsing
7
+ * IE11 doesn't support `new URL`, so we use anchor element
8
+ */
9
+ export declare function convertToURL(url: string): HTMLAnchorElement | null;
10
+ /**
11
+ * Get query parameter from URL
12
+ */
13
+ export declare function getQueryParam(url: string, param: string): string;
14
+ /**
15
+ * Mask query parameters in URL
16
+ */
17
+ export declare function maskQueryParams<T extends string | undefined>(url: T, maskedParams: string[] | undefined, mask: string): T extends string ? string : undefined;
package/dist/vtilt.d.ts CHANGED
@@ -86,7 +86,8 @@ export declare class VTilt {
86
86
  /**
87
87
  * Capture an event
88
88
  * Automatically adds common properties to all events
89
- * ($current_url, $host, $pathname, $referrer, $referring_domain, $browser_language, etc.)
89
+ * ($current_url, $host, $pathname, $referrer, $referring_domain, $browser, $os, $device, $timezone, etc.)
90
+ * Only properties in EVENT_TO_PERSON_PROPERTIES are copied to person properties
90
91
  * Also adds title property for $pageview events only
91
92
  *
92
93
  * @param name - Event name
@@ -7,5 +7,6 @@ export declare const DISTINCT_ID_KEY = "vt_distinct_id";
7
7
  export declare const DEVICE_ID_KEY = "vt_device_id";
8
8
  export declare const USER_PROPERTIES_KEY = "vt_user_properties";
9
9
  export declare const USER_STATE_KEY = "vt_user_state";
10
+ export declare const INITIAL_PERSON_INFO = "$initial_person_info";
10
11
  export declare const STORAGE_METHODS: StorageMethods;
11
12
  export declare const TIMEZONES: Record<string, string>;
package/lib/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TIMEZONES = exports.STORAGE_METHODS = exports.USER_STATE_KEY = exports.USER_PROPERTIES_KEY = exports.DEVICE_ID_KEY = exports.DISTINCT_ID_KEY = exports.ANONYMOUS_ID_KEY = exports.PRIMARY_WINDOW_EXISTS_KEY = exports.WINDOW_ID_KEY = exports.STORAGE_KEY = void 0;
3
+ exports.TIMEZONES = exports.STORAGE_METHODS = exports.INITIAL_PERSON_INFO = exports.USER_STATE_KEY = exports.USER_PROPERTIES_KEY = exports.DEVICE_ID_KEY = exports.DISTINCT_ID_KEY = exports.ANONYMOUS_ID_KEY = exports.PRIMARY_WINDOW_EXISTS_KEY = exports.WINDOW_ID_KEY = exports.STORAGE_KEY = void 0;
4
4
  exports.STORAGE_KEY = "vt_session_id";
5
5
  exports.WINDOW_ID_KEY = "vt_window_id";
6
6
  exports.PRIMARY_WINDOW_EXISTS_KEY = "vt_primary_window_exists";
@@ -9,6 +9,7 @@ exports.DISTINCT_ID_KEY = "vt_distinct_id";
9
9
  exports.DEVICE_ID_KEY = "vt_device_id";
10
10
  exports.USER_PROPERTIES_KEY = "vt_user_properties";
11
11
  exports.USER_STATE_KEY = "vt_user_state";
12
+ exports.INITIAL_PERSON_INFO = "$initial_person_info";
12
13
  exports.STORAGE_METHODS = {
13
14
  cookie: "cookie",
14
15
  localStorage: "localStorage",
package/lib/types.d.ts CHANGED
@@ -36,7 +36,7 @@ export interface EventPayload {
36
36
  export interface TrackingEvent {
37
37
  timestamp: string;
38
38
  event: string;
39
- tenant_id: string;
39
+ project_id: string;
40
40
  domain: string;
41
41
  payload: EventPayload;
42
42
  distinct_id?: string;
@@ -159,4 +159,25 @@ export declare class UserManager {
159
159
  * Remove cookie value
160
160
  */
161
161
  private removeCookieValue;
162
+ /**
163
+ * Register a value once (only if not already set)
164
+ * Stores properties in localStorage only if they don't already exist
165
+ */
166
+ private register_once;
167
+ /**
168
+ * Set initial person info
169
+ * Stores referrer and URL info on first visit for generating $initial_* properties
170
+ */
171
+ set_initial_person_info(maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[]): void;
172
+ /**
173
+ * Get initial props
174
+ * Generates $initial_* properties from stored initial person info
175
+ * These are sent with events as $set_once to preserve first values
176
+ */
177
+ get_initial_props(): Record<string, any>;
178
+ /**
179
+ * Update referrer info
180
+ * Stores current referrer information if not already stored
181
+ */
182
+ update_referrer_info(): void;
162
183
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserManager = void 0;
4
4
  const constants_1 = require("./constants");
5
5
  const utils_1 = require("./utils");
6
+ const event_utils_1 = require("./utils/event-utils");
6
7
  class UserManager {
7
8
  constructor(storageMethod = "localStorage", domain) {
8
9
  this._cachedPersonProperties = null; // Cache for deduplication
@@ -64,8 +65,6 @@ class UserManager {
64
65
  return;
65
66
  }
66
67
  const previousDistinctId = this.userIdentity.distinct_id;
67
- const anonymousId = this.userIdentity.anonymous_id;
68
- const deviceId = this.userIdentity.device_id;
69
68
  // Register user ID
70
69
  this.userIdentity.distinct_id = newDistinctId;
71
70
  // Handle device ID if not already set
@@ -572,5 +571,70 @@ class UserManager {
572
571
  }
573
572
  document.cookie = cookieValue;
574
573
  }
574
+ /**
575
+ * Register a value once (only if not already set)
576
+ * Stores properties in localStorage only if they don't already exist
577
+ */
578
+ register_once(props, defaultValues) {
579
+ const stored = this.getStoredUserProperties();
580
+ let changed = false;
581
+ for (const key in props) {
582
+ if (Object.prototype.hasOwnProperty.call(props, key)) {
583
+ if (!(key in stored)) {
584
+ stored[key] = props[key];
585
+ changed = true;
586
+ }
587
+ }
588
+ }
589
+ if (defaultValues) {
590
+ for (const key in defaultValues) {
591
+ if (Object.prototype.hasOwnProperty.call(defaultValues, key)) {
592
+ if (!(key in stored)) {
593
+ stored[key] = defaultValues[key];
594
+ changed = true;
595
+ }
596
+ }
597
+ }
598
+ }
599
+ if (changed) {
600
+ this.setStoredUserProperties(stored);
601
+ }
602
+ }
603
+ /**
604
+ * Set initial person info
605
+ * Stores referrer and URL info on first visit for generating $initial_* properties
606
+ */
607
+ set_initial_person_info(maskPersonalDataProperties, customPersonalDataProperties) {
608
+ const stored = this.getStoredUserProperties();
609
+ // Check if already set (backwards compatibility check)
610
+ if (stored[constants_1.INITIAL_PERSON_INFO]) {
611
+ return;
612
+ }
613
+ const personInfo = (0, event_utils_1.getPersonInfo)(maskPersonalDataProperties, customPersonalDataProperties);
614
+ this.register_once({
615
+ [constants_1.INITIAL_PERSON_INFO]: personInfo,
616
+ }, undefined);
617
+ }
618
+ /**
619
+ * Get initial props
620
+ * Generates $initial_* properties from stored initial person info
621
+ * These are sent with events as $set_once to preserve first values
622
+ */
623
+ get_initial_props() {
624
+ const stored = this.getStoredUserProperties();
625
+ const initialPersonInfo = stored[constants_1.INITIAL_PERSON_INFO];
626
+ if (!initialPersonInfo) {
627
+ return {};
628
+ }
629
+ return (0, event_utils_1.getInitialPersonPropsFromInfo)(initialPersonInfo);
630
+ }
631
+ /**
632
+ * Update referrer info
633
+ * Stores current referrer information if not already stored
634
+ */
635
+ update_referrer_info() {
636
+ const referrerInfo = (0, event_utils_1.getReferrerInfo)();
637
+ this.register_once(referrerInfo, undefined);
638
+ }
575
639
  }
576
640
  exports.UserManager = UserManager;
@@ -1,34 +1,52 @@
1
1
  /**
2
- * Get browser language
3
- * Returns the browser's language setting (e.g., "en-US")
2
+ * Event utilities
3
+ * Functions for extracting event properties, campaign parameters, and person info
4
4
  */
5
- export declare function getBrowserLanguage(): string | undefined;
5
+ export declare const PERSONAL_DATA_CAMPAIGN_PARAMS: string[];
6
+ export declare const CAMPAIGN_PARAMS: string[];
7
+ export declare const EVENT_TO_PERSON_PROPERTIES: string[];
8
+ export declare const MASKED = "<masked>";
9
+ export declare const COOKIE_CAMPAIGN_PARAMS: string[];
6
10
  /**
7
- * Get browser language prefix
8
- * Returns the language code without region (e.g., "en" from "en-US")
11
+ * Get campaign parameters from URL
12
+ * Extracts UTM and other campaign tracking parameters from current page URL
13
+ * Masks personal data parameters if configured
9
14
  */
15
+ export declare function getCampaignParams(customTrackedParams?: string[], maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[] | undefined): Record<string, string>;
16
+ export declare function getSearchInfo(): Record<string, any>;
17
+ export declare function getBrowserLanguage(): string | undefined;
10
18
  export declare function getBrowserLanguagePrefix(): string | undefined;
19
+ export declare function getReferrer(): string;
20
+ export declare function getReferringDomain(): string;
11
21
  /**
12
- * Get referrer
13
- * Returns document.referrer or '$direct' if no referrer
22
+ * Get referrer information
23
+ * Returns current referrer and referring domain
14
24
  */
15
- export declare function getReferrer(): string;
25
+ export declare function getReferrerInfo(): Record<string, any>;
16
26
  /**
17
- * Get referring domain
18
- * Returns the hostname of the referrer URL or '$direct' if no referrer
27
+ * Get person info for initial storage
28
+ * Extracts referrer and URL info, masks personal data if configured
29
+ * Returns compact format (r: referrer, u: url) for storage efficiency
19
30
  */
20
- export declare function getReferringDomain(): string;
31
+ export declare function getPersonInfo(maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[]): {
32
+ r: string;
33
+ u: string | undefined;
34
+ };
21
35
  /**
22
- * Get timezone
23
- * Returns the timezone (e.g., "America/New_York")
36
+ * Convert person info to person properties
37
+ * Extracts referrer, URL, campaign params, and search info from stored person info
24
38
  */
25
- export declare function getTimezone(): string | undefined;
39
+ export declare function getPersonPropsFromInfo(info: Record<string, any>): Record<string, any>;
26
40
  /**
27
- * Get timezone offset
28
- * Returns the timezone offset in minutes
41
+ * Convert person info to initial person properties
42
+ * Generates $initial_* properties from person info (preserves first values)
29
43
  */
44
+ export declare function getInitialPersonPropsFromInfo(info: Record<string, any>): Record<string, any>;
45
+ export declare function getTimezone(): string | undefined;
30
46
  export declare function getTimezoneOffset(): number | undefined;
31
47
  /**
32
48
  * Get event properties that should be added to all events
49
+ * Returns all event context properties (browser, device, URL, etc.) plus event metadata
50
+ * Note: Only properties in EVENT_TO_PERSON_PROPERTIES are copied to person properties
33
51
  */
34
- export declare function getEventProperties(): Record<string, any>;
52
+ export declare function getEventProperties(maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[]): Record<string, any>;