@tracelog/lib 0.5.4 → 0.6.0

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 (200) hide show
  1. package/README.md +157 -180
  2. package/dist/browser/tracelog.esm.js +1007 -1357
  3. package/dist/browser/tracelog.js +2 -2
  4. package/dist/cjs/api.d.ts +12 -2
  5. package/dist/cjs/api.js +63 -27
  6. package/dist/cjs/app.d.ts +2 -2
  7. package/dist/cjs/app.js +26 -32
  8. package/dist/cjs/constants/config.constants.d.ts +4 -2
  9. package/dist/cjs/constants/config.constants.js +6 -18
  10. package/dist/cjs/constants/index.d.ts +0 -1
  11. package/dist/cjs/constants/index.js +0 -1
  12. package/dist/cjs/constants/storage.constants.d.ts +3 -2
  13. package/dist/cjs/constants/storage.constants.js +4 -4
  14. package/dist/cjs/handlers/click.handler.js +3 -6
  15. package/dist/cjs/handlers/error.handler.js +1 -11
  16. package/dist/cjs/handlers/page-view.handler.js +0 -4
  17. package/dist/cjs/handlers/performance.handler.js +14 -29
  18. package/dist/cjs/handlers/scroll.handler.js +7 -6
  19. package/dist/cjs/handlers/session.handler.js +7 -6
  20. package/dist/cjs/integrations/google-analytics.integration.js +2 -6
  21. package/dist/cjs/listeners/activity-listener-manager.js +3 -3
  22. package/dist/cjs/listeners/input-listener-managers.js +3 -3
  23. package/dist/cjs/listeners/touch-listener-manager.js +3 -3
  24. package/dist/cjs/listeners/unload-listener-manager.js +3 -3
  25. package/dist/cjs/listeners/visibility-listener-manager.js +3 -3
  26. package/dist/cjs/managers/event.manager.d.ts +2 -1
  27. package/dist/cjs/managers/event.manager.js +60 -38
  28. package/dist/cjs/managers/sender.manager.js +29 -36
  29. package/dist/cjs/managers/session.manager.js +5 -13
  30. package/dist/cjs/managers/state.manager.d.ts +0 -3
  31. package/dist/cjs/managers/state.manager.js +1 -43
  32. package/dist/cjs/managers/storage.manager.d.ts +16 -2
  33. package/dist/cjs/managers/storage.manager.js +73 -19
  34. package/dist/cjs/managers/user.manager.d.ts +1 -1
  35. package/dist/cjs/managers/user.manager.js +2 -2
  36. package/dist/cjs/public-api.d.ts +3 -3
  37. package/dist/cjs/public-api.js +1 -1
  38. package/dist/cjs/test-bridge.d.ts +1 -0
  39. package/dist/cjs/test-bridge.js +37 -2
  40. package/dist/cjs/types/config.types.d.ts +15 -18
  41. package/dist/cjs/types/config.types.js +6 -0
  42. package/dist/cjs/types/event.types.d.ts +1 -13
  43. package/dist/cjs/types/index.d.ts +0 -2
  44. package/dist/cjs/types/index.js +0 -2
  45. package/dist/cjs/types/mode.types.d.ts +1 -2
  46. package/dist/cjs/types/mode.types.js +0 -1
  47. package/dist/cjs/types/queue.types.d.ts +0 -6
  48. package/dist/cjs/types/state.types.d.ts +2 -0
  49. package/dist/cjs/types/test-bridge.types.d.ts +2 -2
  50. package/dist/cjs/types/validation-error.types.d.ts +0 -6
  51. package/dist/cjs/types/validation-error.types.js +1 -10
  52. package/dist/cjs/utils/browser/device-detector.utils.js +2 -24
  53. package/dist/cjs/utils/browser/index.d.ts +1 -0
  54. package/dist/cjs/utils/browser/index.js +1 -0
  55. package/dist/cjs/utils/browser/qa-mode.utils.d.ts +13 -0
  56. package/dist/cjs/utils/browser/qa-mode.utils.js +43 -0
  57. package/dist/cjs/utils/browser/utm-params.utils.js +0 -15
  58. package/dist/cjs/utils/data/uuid.utils.d.ts +13 -0
  59. package/dist/cjs/utils/data/uuid.utils.js +37 -1
  60. package/dist/cjs/utils/index.d.ts +1 -1
  61. package/dist/cjs/utils/index.js +1 -1
  62. package/dist/cjs/utils/logging.utils.d.ts +6 -0
  63. package/dist/cjs/utils/logging.utils.js +25 -0
  64. package/dist/cjs/utils/network/index.d.ts +0 -1
  65. package/dist/cjs/utils/network/index.js +0 -1
  66. package/dist/cjs/utils/network/url.utils.d.ts +2 -8
  67. package/dist/cjs/utils/network/url.utils.js +46 -90
  68. package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -13
  69. package/dist/cjs/utils/security/sanitize.utils.js +15 -178
  70. package/dist/cjs/utils/validations/config-validations.utils.d.ts +3 -9
  71. package/dist/cjs/utils/validations/config-validations.utils.js +48 -94
  72. package/dist/cjs/utils/validations/event-validations.utils.js +11 -5
  73. package/dist/cjs/utils/validations/index.d.ts +0 -1
  74. package/dist/cjs/utils/validations/index.js +0 -1
  75. package/dist/cjs/utils/validations/metadata-validations.utils.js +0 -1
  76. package/dist/cjs/utils/validations/type-guards.utils.d.ts +2 -2
  77. package/dist/cjs/utils/validations/type-guards.utils.js +50 -4
  78. package/dist/esm/api.d.ts +12 -2
  79. package/dist/esm/api.js +62 -27
  80. package/dist/esm/app.d.ts +2 -2
  81. package/dist/esm/app.js +28 -34
  82. package/dist/esm/constants/config.constants.d.ts +4 -2
  83. package/dist/esm/constants/config.constants.js +4 -16
  84. package/dist/esm/constants/index.d.ts +0 -1
  85. package/dist/esm/constants/index.js +0 -1
  86. package/dist/esm/constants/storage.constants.d.ts +3 -2
  87. package/dist/esm/constants/storage.constants.js +3 -2
  88. package/dist/esm/handlers/click.handler.js +3 -6
  89. package/dist/esm/handlers/error.handler.js +1 -11
  90. package/dist/esm/handlers/page-view.handler.js +0 -4
  91. package/dist/esm/handlers/performance.handler.js +14 -29
  92. package/dist/esm/handlers/scroll.handler.js +7 -6
  93. package/dist/esm/handlers/session.handler.js +7 -6
  94. package/dist/esm/integrations/google-analytics.integration.js +3 -7
  95. package/dist/esm/listeners/activity-listener-manager.js +3 -3
  96. package/dist/esm/listeners/input-listener-managers.js +3 -3
  97. package/dist/esm/listeners/touch-listener-manager.js +3 -3
  98. package/dist/esm/listeners/unload-listener-manager.js +3 -3
  99. package/dist/esm/listeners/visibility-listener-manager.js +3 -3
  100. package/dist/esm/managers/event.manager.d.ts +2 -1
  101. package/dist/esm/managers/event.manager.js +62 -40
  102. package/dist/esm/managers/sender.manager.js +31 -38
  103. package/dist/esm/managers/session.manager.js +5 -13
  104. package/dist/esm/managers/state.manager.d.ts +0 -3
  105. package/dist/esm/managers/state.manager.js +1 -43
  106. package/dist/esm/managers/storage.manager.d.ts +16 -2
  107. package/dist/esm/managers/storage.manager.js +73 -19
  108. package/dist/esm/managers/user.manager.d.ts +1 -1
  109. package/dist/esm/managers/user.manager.js +2 -2
  110. package/dist/esm/public-api.d.ts +3 -3
  111. package/dist/esm/public-api.js +1 -1
  112. package/dist/esm/test-bridge.d.ts +1 -0
  113. package/dist/esm/test-bridge.js +37 -2
  114. package/dist/esm/types/config.types.d.ts +15 -18
  115. package/dist/esm/types/config.types.js +5 -1
  116. package/dist/esm/types/event.types.d.ts +1 -13
  117. package/dist/esm/types/index.d.ts +0 -2
  118. package/dist/esm/types/index.js +0 -2
  119. package/dist/esm/types/mode.types.d.ts +1 -2
  120. package/dist/esm/types/mode.types.js +0 -1
  121. package/dist/esm/types/queue.types.d.ts +0 -6
  122. package/dist/esm/types/state.types.d.ts +2 -0
  123. package/dist/esm/types/test-bridge.types.d.ts +2 -2
  124. package/dist/esm/types/validation-error.types.d.ts +0 -6
  125. package/dist/esm/types/validation-error.types.js +0 -8
  126. package/dist/esm/utils/browser/device-detector.utils.js +2 -24
  127. package/dist/esm/utils/browser/index.d.ts +1 -0
  128. package/dist/esm/utils/browser/index.js +1 -0
  129. package/dist/esm/utils/browser/qa-mode.utils.d.ts +13 -0
  130. package/dist/esm/utils/browser/qa-mode.utils.js +39 -0
  131. package/dist/esm/utils/browser/utm-params.utils.js +0 -15
  132. package/dist/esm/utils/data/uuid.utils.d.ts +13 -0
  133. package/dist/esm/utils/data/uuid.utils.js +35 -0
  134. package/dist/esm/utils/index.d.ts +1 -1
  135. package/dist/esm/utils/index.js +1 -1
  136. package/dist/esm/utils/logging.utils.d.ts +6 -0
  137. package/dist/esm/utils/logging.utils.js +20 -0
  138. package/dist/esm/utils/network/index.d.ts +0 -1
  139. package/dist/esm/utils/network/index.js +0 -1
  140. package/dist/esm/utils/network/url.utils.d.ts +2 -8
  141. package/dist/esm/utils/network/url.utils.js +45 -88
  142. package/dist/esm/utils/security/sanitize.utils.d.ts +1 -13
  143. package/dist/esm/utils/security/sanitize.utils.js +15 -176
  144. package/dist/esm/utils/validations/config-validations.utils.d.ts +3 -9
  145. package/dist/esm/utils/validations/config-validations.utils.js +49 -94
  146. package/dist/esm/utils/validations/event-validations.utils.js +11 -5
  147. package/dist/esm/utils/validations/index.d.ts +0 -1
  148. package/dist/esm/utils/validations/index.js +0 -1
  149. package/dist/esm/utils/validations/metadata-validations.utils.js +0 -1
  150. package/dist/esm/utils/validations/type-guards.utils.d.ts +2 -2
  151. package/dist/esm/utils/validations/type-guards.utils.js +50 -4
  152. package/package.json +1 -1
  153. package/dist/cjs/app.types.d.ts +0 -2
  154. package/dist/cjs/app.types.js +0 -12
  155. package/dist/cjs/constants/api.constants.d.ts +0 -6
  156. package/dist/cjs/constants/api.constants.js +0 -14
  157. package/dist/cjs/managers/api.manager.d.ts +0 -13
  158. package/dist/cjs/managers/api.manager.js +0 -44
  159. package/dist/cjs/managers/config.builder.d.ts +0 -33
  160. package/dist/cjs/managers/config.builder.js +0 -116
  161. package/dist/cjs/managers/config.manager.d.ts +0 -56
  162. package/dist/cjs/managers/config.manager.js +0 -157
  163. package/dist/cjs/managers/tags.manager.d.ts +0 -36
  164. package/dist/cjs/managers/tags.manager.js +0 -171
  165. package/dist/cjs/types/api.types.d.ts +0 -52
  166. package/dist/cjs/types/api.types.js +0 -56
  167. package/dist/cjs/types/tag.types.d.ts +0 -43
  168. package/dist/cjs/types/tag.types.js +0 -31
  169. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +0 -14
  170. package/dist/cjs/utils/logging/debug-logger.utils.js +0 -47
  171. package/dist/cjs/utils/logging/index.d.ts +0 -1
  172. package/dist/cjs/utils/logging/index.js +0 -5
  173. package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +0 -4
  174. package/dist/cjs/utils/network/fetch-with-timeout.utils.js +0 -25
  175. package/dist/cjs/utils/validations/url-validations.utils.d.ts +0 -15
  176. package/dist/cjs/utils/validations/url-validations.utils.js +0 -47
  177. package/dist/esm/app.types.d.ts +0 -2
  178. package/dist/esm/app.types.js +0 -1
  179. package/dist/esm/constants/api.constants.d.ts +0 -6
  180. package/dist/esm/constants/api.constants.js +0 -11
  181. package/dist/esm/managers/api.manager.d.ts +0 -13
  182. package/dist/esm/managers/api.manager.js +0 -41
  183. package/dist/esm/managers/config.builder.d.ts +0 -33
  184. package/dist/esm/managers/config.builder.js +0 -112
  185. package/dist/esm/managers/config.manager.d.ts +0 -56
  186. package/dist/esm/managers/config.manager.js +0 -153
  187. package/dist/esm/managers/tags.manager.d.ts +0 -36
  188. package/dist/esm/managers/tags.manager.js +0 -167
  189. package/dist/esm/types/api.types.d.ts +0 -52
  190. package/dist/esm/types/api.types.js +0 -53
  191. package/dist/esm/types/tag.types.d.ts +0 -43
  192. package/dist/esm/types/tag.types.js +0 -28
  193. package/dist/esm/utils/logging/debug-logger.utils.d.ts +0 -14
  194. package/dist/esm/utils/logging/debug-logger.utils.js +0 -44
  195. package/dist/esm/utils/logging/index.d.ts +0 -1
  196. package/dist/esm/utils/logging/index.js +0 -1
  197. package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +0 -4
  198. package/dist/esm/utils/network/fetch-with-timeout.utils.js +0 -22
  199. package/dist/esm/utils/validations/url-validations.utils.d.ts +0 -15
  200. package/dist/esm/utils/validations/url-validations.utils.js +0 -42
@@ -1,18 +1,5 @@
1
1
  import { MetadataType } from './common.types';
2
- import { TagConfig } from './tag.types';
3
- import { Mode } from './mode.types';
4
- export type Config = AppConfig & ExclusiveApiConfig;
5
- export type ApiConfig = SharedConfig & ExclusiveApiConfig;
6
- export type SharedConfig = Pick<AppConfig, 'mode' | 'samplingRate' | 'excludedUrlPaths'>;
7
- export interface ExclusiveApiConfig {
8
- /** Tag definitions used to categorize tracked events. */
9
- tags?: TagConfig[];
10
- /** Determines if IP address is excluded from tracking. */
11
- ipExcluded?: boolean;
12
- }
13
- export interface AppConfig {
14
- /** Project identifier used for tracing. */
15
- id: string;
2
+ export interface Config {
16
3
  /** Session inactivity timeout in milliseconds. @default 900000 */
17
4
  sessionTimeout?: number;
18
5
  /** Metadata appended to every tracked event. */
@@ -25,14 +12,20 @@ export interface AppConfig {
25
12
  sensitiveQueryParams?: string[];
26
13
  /** Error event sampling rate between 0 and 1. */
27
14
  errorSampling?: number;
28
- /** Logging mode controlling verbosity of client logs. */
29
- mode?: Mode;
30
15
  /** Event sampling rate between 0 and 1. */
31
16
  samplingRate?: number;
32
- /** URL path patterns that should be ignored by tracking. */
33
- excludedUrlPaths?: string[];
34
17
  /** Optional configuration for third-party integrations. */
35
18
  integrations?: {
19
+ /** TraceLog integration options. */
20
+ tracelog?: {
21
+ /** Required project ID TraceLog SaaS integration. */
22
+ projectId: string;
23
+ };
24
+ /** Custom integration options. */
25
+ custom?: {
26
+ /** Required API URL for custom integration. */
27
+ apiUrl: string;
28
+ };
36
29
  /** Google Analytics integration options. */
37
30
  googleAnalytics?: {
38
31
  /** Required measurement ID for Google Analytics. */
@@ -40,3 +33,7 @@ export interface AppConfig {
40
33
  };
41
34
  };
42
35
  }
36
+ export declare enum SpecialApiUrl {
37
+ Localhost = "localhost:8080",
38
+ Fail = "localhost:9999"
39
+ }
@@ -1 +1,5 @@
1
- export {};
1
+ export var SpecialApiUrl;
2
+ (function (SpecialApiUrl) {
3
+ SpecialApiUrl["Localhost"] = "localhost:8080";
4
+ SpecialApiUrl["Fail"] = "localhost:9999";
5
+ })(SpecialApiUrl || (SpecialApiUrl = {}));
@@ -74,15 +74,8 @@ export interface PageViewData {
74
74
  search?: string;
75
75
  hash?: string;
76
76
  }
77
- export interface EventLocation {
78
- country: string;
79
- country_code: string;
80
- }
81
- export interface VitalSample {
82
- type: WebVitalType;
83
- value: number;
84
- }
85
77
  export interface EventData {
78
+ id: string;
86
79
  type: EventType;
87
80
  page_url: string;
88
81
  timestamp: number;
@@ -96,9 +89,4 @@ export interface EventData {
96
89
  session_end_reason?: SessionEndReason;
97
90
  error_data?: ErrorData;
98
91
  utm?: UTM;
99
- location?: EventLocation;
100
- tags?: string[] | {
101
- id: string;
102
- key: string;
103
- }[];
104
92
  }
@@ -1,4 +1,3 @@
1
- export * from './api.types';
2
1
  export * from './common.types';
3
2
  export * from './config.types';
4
3
  export * from './device.types';
@@ -9,7 +8,6 @@ export * from './mode.types';
9
8
  export * from './queue.types';
10
9
  export * from './session.types';
11
10
  export * from './state.types';
12
- export * from './tag.types';
13
11
  export * from './test-bridge.types';
14
12
  export * from './validation-error.types';
15
13
  export * from './window.types';
@@ -1,4 +1,3 @@
1
- export * from './api.types';
2
1
  export * from './common.types';
3
2
  export * from './config.types';
4
3
  export * from './device.types';
@@ -9,7 +8,6 @@ export * from './mode.types';
9
8
  export * from './queue.types';
10
9
  export * from './session.types';
11
10
  export * from './state.types';
12
- export * from './tag.types';
13
11
  export * from './test-bridge.types';
14
12
  export * from './validation-error.types';
15
13
  export * from './window.types';
@@ -2,6 +2,5 @@
2
2
  * App modes for the TraceLog Library
3
3
  */
4
4
  export declare enum Mode {
5
- QA = "qa",
6
- DEBUG = "debug"
5
+ QA = "qa"
7
6
  }
@@ -4,5 +4,4 @@
4
4
  export var Mode;
5
5
  (function (Mode) {
6
6
  Mode["QA"] = "qa";
7
- Mode["DEBUG"] = "debug";
8
7
  })(Mode || (Mode = {}));
@@ -8,11 +8,6 @@ export interface BaseEventsQueueDto {
8
8
  events: EventData[];
9
9
  global_metadata?: Record<string, MetadataType>;
10
10
  }
11
- export interface ExtendedEventsQueueDto extends BaseEventsQueueDto {
12
- project: string;
13
- source: string;
14
- ip: string;
15
- }
16
11
  export interface PersistedQueueData {
17
12
  userId: string;
18
13
  sessionId: string;
@@ -20,5 +15,4 @@ export interface PersistedQueueData {
20
15
  events: BaseEventsQueueDto['events'];
21
16
  timestamp: number;
22
17
  global_metadata?: BaseEventsQueueDto['global_metadata'];
23
- fallbackMode?: boolean;
24
18
  }
@@ -1,6 +1,8 @@
1
1
  import { Config } from './config.types';
2
2
  import { DeviceType } from './device.types';
3
+ import { Mode } from './mode.types';
3
4
  export interface State {
5
+ mode?: Mode;
4
6
  apiUrl: string;
5
7
  config: Config;
6
8
  sessionId: string | null;
@@ -7,7 +7,7 @@ import { SessionHandler } from '@/handlers/session.handler';
7
7
  import { GoogleAnalyticsIntegration } from '@/integrations/google-analytics.integration';
8
8
  import { EventManager } from '@/managers/event.manager';
9
9
  import { StorageManager as TraceLogStorageManager } from '@/managers/storage.manager';
10
- import { AppConfig } from './config.types';
10
+ import { Config } from './config.types';
11
11
  import { State } from './state.types';
12
12
  /**
13
13
  * Testing bridge interface for E2E tests
@@ -15,7 +15,7 @@ import { State } from './state.types';
15
15
  */
16
16
  export interface TraceLogTestBridge {
17
17
  readonly initialized: boolean;
18
- init(config: AppConfig): Promise<void>;
18
+ init(config: Config): Promise<void>;
19
19
  destroy(): Promise<void>;
20
20
  isInitializing(): boolean;
21
21
  sendCustomEvent(name: string, data?: Record<string, unknown> | Record<string, unknown>[]): void;
@@ -10,12 +10,6 @@ export declare abstract class TraceLogValidationError extends Error {
10
10
  readonly layer: 'config' | 'app' | 'runtime';
11
11
  constructor(message: string, errorCode: string, layer: 'config' | 'app' | 'runtime');
12
12
  }
13
- /**
14
- * Thrown when project ID validation fails
15
- */
16
- export declare class ProjectIdValidationError extends TraceLogValidationError {
17
- constructor(message?: string, layer?: 'config' | 'app' | 'runtime');
18
- }
19
13
  /**
20
14
  * Thrown when app configuration validation fails
21
15
  */
@@ -17,14 +17,6 @@ export class TraceLogValidationError extends Error {
17
17
  }
18
18
  }
19
19
  }
20
- /**
21
- * Thrown when project ID validation fails
22
- */
23
- export class ProjectIdValidationError extends TraceLogValidationError {
24
- constructor(message = 'Project ID is required', layer = 'config') {
25
- super(message, 'PROJECT_ID_INVALID', layer);
26
- }
27
- }
28
20
  /**
29
21
  * Thrown when app configuration validation fails
30
22
  */
@@ -1,5 +1,5 @@
1
1
  import { DeviceType } from '../../types/device.types';
2
- import { debugLog } from '../logging';
2
+ import { log } from '../logging.utils';
3
3
  let coarsePointerQuery;
4
4
  let noHoverQuery;
5
5
  const initMediaQueries = () => {
@@ -14,22 +14,14 @@ const initMediaQueries = () => {
14
14
  */
15
15
  export const getDeviceType = () => {
16
16
  try {
17
- debugLog.debug('DeviceDetector', 'Starting device detection');
18
17
  const nav = navigator;
19
18
  if (nav.userAgentData && typeof nav.userAgentData.mobile === 'boolean') {
20
- debugLog.debug('DeviceDetector', 'Using modern User-Agent Client Hints API', {
21
- mobile: nav.userAgentData.mobile,
22
- platform: nav.userAgentData.platform,
23
- });
24
19
  if (nav.userAgentData.platform && /ipad|tablet/i.test(nav.userAgentData.platform)) {
25
- debugLog.debug('DeviceDetector', 'Device detected as tablet via platform hint');
26
20
  return DeviceType.Tablet;
27
21
  }
28
22
  const result = nav.userAgentData.mobile ? DeviceType.Mobile : DeviceType.Desktop;
29
- debugLog.debug('DeviceDetector', 'Device detected via User-Agent hints', { result });
30
23
  return result;
31
24
  }
32
- debugLog.debug('DeviceDetector', 'Using fallback detection methods');
33
25
  initMediaQueries();
34
26
  const width = window.innerWidth;
35
27
  const hasCoarsePointer = coarsePointerQuery?.matches ?? false;
@@ -38,30 +30,16 @@ export const getDeviceType = () => {
38
30
  const ua = navigator.userAgent.toLowerCase();
39
31
  const isMobileUA = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(ua);
40
32
  const isTabletUA = /tablet|ipad|android(?!.*mobile)/.test(ua);
41
- const detectionData = {
42
- width,
43
- hasCoarsePointer,
44
- hasNoHover,
45
- hasTouchSupport,
46
- isMobileUA,
47
- isTabletUA,
48
- maxTouchPoints: navigator.maxTouchPoints,
49
- };
50
33
  if (width <= 767 || (isMobileUA && hasTouchSupport)) {
51
- debugLog.debug('DeviceDetector', 'Device detected as mobile', detectionData);
52
34
  return DeviceType.Mobile;
53
35
  }
54
36
  if ((width >= 768 && width <= 1024) || isTabletUA || (hasCoarsePointer && hasNoHover && hasTouchSupport)) {
55
- debugLog.debug('DeviceDetector', 'Device detected as tablet', detectionData);
56
37
  return DeviceType.Tablet;
57
38
  }
58
- debugLog.debug('DeviceDetector', 'Device detected as desktop', detectionData);
59
39
  return DeviceType.Desktop;
60
40
  }
61
41
  catch (error) {
62
- debugLog.warn('DeviceDetector', 'Device detection failed, defaulting to desktop', {
63
- error: error instanceof Error ? error.message : error,
64
- });
42
+ log('warn', 'Device detection failed, defaulting to desktop', { error });
65
43
  return DeviceType.Desktop;
66
44
  }
67
45
  };
@@ -1,2 +1,3 @@
1
1
  export * from './device-detector.utils';
2
+ export * from './qa-mode.utils';
2
3
  export * from './utm-params.utils';
@@ -1,2 +1,3 @@
1
1
  export * from './device-detector.utils';
2
+ export * from './qa-mode.utils';
2
3
  export * from './utm-params.utils';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Detects if QA mode should be active based on URL query parameter or sessionStorage
3
+ *
4
+ * Detection flow:
5
+ * 1. Check if already active in sessionStorage
6
+ * 2. Check for ?tlog_mode=qa query parameter
7
+ * 3. If found in URL:
8
+ * - Persist to sessionStorage
9
+ * - Clean param from URL
10
+ *
11
+ * @returns True if QA mode is active, false otherwise
12
+ */
13
+ export declare const detectQaMode: () => boolean;
@@ -0,0 +1,39 @@
1
+ import { QA_MODE_KEY } from '@/constants';
2
+ import { log } from '../logging.utils';
3
+ const QA_MODE_PARAM = 'tlog_mode';
4
+ const QA_MODE_VALUE = 'qa';
5
+ /**
6
+ * Detects if QA mode should be active based on URL query parameter or sessionStorage
7
+ *
8
+ * Detection flow:
9
+ * 1. Check if already active in sessionStorage
10
+ * 2. Check for ?tlog_mode=qa query parameter
11
+ * 3. If found in URL:
12
+ * - Persist to sessionStorage
13
+ * - Clean param from URL
14
+ *
15
+ * @returns True if QA mode is active, false otherwise
16
+ */
17
+ export const detectQaMode = () => {
18
+ const stored = sessionStorage.getItem(QA_MODE_KEY);
19
+ if (stored === 'true') {
20
+ return true;
21
+ }
22
+ const params = new URLSearchParams(window.location.search);
23
+ const modeParam = params.get(QA_MODE_PARAM);
24
+ const isQaMode = modeParam === QA_MODE_VALUE;
25
+ if (isQaMode) {
26
+ sessionStorage.setItem(QA_MODE_KEY, 'true');
27
+ params.delete(QA_MODE_PARAM);
28
+ const newSearch = params.toString();
29
+ const newUrl = `${window.location.pathname}${newSearch ? '?' + newSearch : ''}${window.location.hash}`;
30
+ try {
31
+ window.history.replaceState({}, '', newUrl);
32
+ }
33
+ catch (error) {
34
+ log('warn', 'History API not available, cannot replace URL', { error });
35
+ }
36
+ console.log('%c[TraceLog] QA Mode ACTIVE', 'background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;');
37
+ }
38
+ return isQaMode;
39
+ };
@@ -1,14 +1,9 @@
1
1
  import { UTM_PARAMS } from '../../constants';
2
- import { debugLog } from '../logging';
3
2
  /**
4
3
  * Extracts UTM parameters from the current URL
5
4
  * @returns UTM parameters object or undefined if none found
6
5
  */
7
6
  export const getUTMParameters = () => {
8
- debugLog.debug('UTMParams', 'Extracting UTM parameters from URL', {
9
- url: window.location.href,
10
- search: window.location.search,
11
- });
12
7
  const urlParams = new URLSearchParams(window.location.search);
13
8
  const utmParams = {};
14
9
  UTM_PARAMS.forEach((param) => {
@@ -16,18 +11,8 @@ export const getUTMParameters = () => {
16
11
  if (value) {
17
12
  const key = param.split('utm_')[1];
18
13
  utmParams[key] = value;
19
- debugLog.debug('UTMParams', 'Found UTM parameter', { param, key, value });
20
14
  }
21
15
  });
22
16
  const result = Object.keys(utmParams).length ? utmParams : undefined;
23
- if (result) {
24
- debugLog.debug('UTMParams', 'UTM parameters extracted successfully', {
25
- parameterCount: Object.keys(result).length,
26
- parameters: Object.keys(result),
27
- });
28
- }
29
- else {
30
- debugLog.debug('UTMParams', 'No UTM parameters found in URL');
31
- }
32
17
  return result;
33
18
  };
@@ -3,3 +3,16 @@
3
3
  * @returns A UUID string
4
4
  */
5
5
  export declare const generateUUID: () => string;
6
+ /**
7
+ * Generates a unique event ID optimized for high-frequency event tracking
8
+ *
9
+ * Uses a simple hybrid approach:
10
+ * - Timestamp for temporal ordering
11
+ * - Random component for uniqueness across tabs/processes
12
+ *
13
+ * Format: {timestamp}-{random}
14
+ * Example: "1704067200000-a3f9c2b1"
15
+ *
16
+ * @returns Unique event ID string
17
+ */
18
+ export declare const generateEventId: () => string;
@@ -14,3 +14,38 @@ export const generateUUID = () => {
14
14
  return v.toString(16);
15
15
  });
16
16
  };
17
+ /**
18
+ * Generates a unique event ID optimized for high-frequency event tracking
19
+ *
20
+ * Uses a simple hybrid approach:
21
+ * - Timestamp for temporal ordering
22
+ * - Random component for uniqueness across tabs/processes
23
+ *
24
+ * Format: {timestamp}-{random}
25
+ * Example: "1704067200000-a3f9c2b1"
26
+ *
27
+ * @returns Unique event ID string
28
+ */
29
+ export const generateEventId = () => {
30
+ const timestamp = Date.now();
31
+ // Generate 8 random hex chars (32 bits entropy)
32
+ let random = '';
33
+ try {
34
+ if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
35
+ const bytes = crypto.getRandomValues(new Uint8Array(4));
36
+ if (bytes) {
37
+ random = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
38
+ }
39
+ }
40
+ }
41
+ catch {
42
+ // crypto failed, use fallback
43
+ }
44
+ // Fallback to Math.random if crypto unavailable
45
+ if (!random) {
46
+ random = Math.floor(Math.random() * 0xffffffff)
47
+ .toString(16)
48
+ .padStart(8, '0');
49
+ }
50
+ return `${timestamp}-${random}`;
51
+ };
@@ -1,7 +1,7 @@
1
1
  export * from './browser';
2
2
  export * from './data';
3
- export * from './logging';
4
3
  export * from './network';
5
4
  export * from './security';
6
5
  export * from './validations';
7
6
  export * from './emitter.utils';
7
+ export * from './logging.utils';
@@ -1,7 +1,7 @@
1
1
  export * from './browser';
2
2
  export * from './data';
3
- export * from './logging';
4
3
  export * from './network';
5
4
  export * from './security';
6
5
  export * from './validations';
7
6
  export * from './emitter.utils';
7
+ export * from './logging.utils';
@@ -0,0 +1,6 @@
1
+ export declare const formatLogMsg: (msg: string, error?: unknown) => string;
2
+ export declare const log: (type: "info" | "warn" | "error", msg: string, extra?: {
3
+ error?: unknown;
4
+ data?: Record<string, unknown>;
5
+ showToClient?: boolean;
6
+ }) => void;
@@ -0,0 +1,20 @@
1
+ export const formatLogMsg = (msg, error) => {
2
+ if (error) {
3
+ return `[TraceLog] ${msg}: ${error instanceof Error ? error.message : 'Unknown error'}`;
4
+ }
5
+ return `[TraceLog] ${msg}`;
6
+ };
7
+ export const log = (type, msg, extra) => {
8
+ const { error, data, showToClient } = extra ?? {};
9
+ const formattedMsg = error ? formatLogMsg(msg, error) : `[TraceLog] ${msg}`;
10
+ const method = type === 'error' ? 'error' : type === 'warn' ? 'warn' : 'log';
11
+ if (process.env.NODE_ENV !== 'dev' && !showToClient) {
12
+ return;
13
+ }
14
+ if (data !== undefined) {
15
+ console[method](formattedMsg, data);
16
+ }
17
+ else {
18
+ console[method](formattedMsg);
19
+ }
20
+ };
@@ -1,2 +1 @@
1
1
  export * from './url.utils';
2
- export * from './fetch-with-timeout.utils';
@@ -1,2 +1 @@
1
1
  export * from './url.utils';
2
- export * from './fetch-with-timeout.utils';
@@ -1,9 +1,10 @@
1
+ import { Config } from '@/types';
1
2
  /**
2
3
  * Generates an API URL based on project ID and current domain
3
4
  * @param id - The project ID
4
5
  * @returns The generated API URL
5
6
  */
6
- export declare const getApiUrl: (id: string, allowHttp?: boolean) => string;
7
+ export declare const getApiUrl: (config: Config) => string;
7
8
  /**
8
9
  * Normalizes a URL by removing sensitive query parameters
9
10
  * @param url - The URL to normalize
@@ -11,10 +12,3 @@ export declare const getApiUrl: (id: string, allowHttp?: boolean) => string;
11
12
  * @returns The normalized URL
12
13
  */
13
14
  export declare const normalizeUrl: (url: string, sensitiveQueryParams?: string[]) => string;
14
- /**
15
- * Checks if a URL path should be excluded from tracking
16
- * @param url - The URL to check
17
- * @param excludedPaths - Array of patterns to match against
18
- * @returns True if the URL should be excluded
19
- */
20
- export declare const isUrlPathExcluded: (url: string, excludedPaths?: string[]) => boolean;