@tracelog/lib 0.0.8 → 0.2.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.
- package/README.md +58 -24
- package/dist/browser/tracelog.js +1934 -3226
- package/dist/cjs/api.d.ts +33 -19
- package/dist/cjs/api.js +111 -156
- package/dist/cjs/app.constants.d.ts +80 -1
- package/dist/cjs/app.constants.js +90 -3
- package/dist/cjs/app.d.ts +29 -44
- package/dist/cjs/app.js +114 -212
- package/dist/cjs/app.types.d.ts +2 -7
- package/dist/cjs/app.types.js +10 -21
- package/dist/cjs/constants/api.constants.js +11 -5
- package/dist/cjs/constants/config.constants.d.ts +75 -0
- package/dist/cjs/constants/config.constants.js +178 -0
- package/dist/cjs/constants/error.constants.d.ts +29 -0
- package/dist/cjs/constants/error.constants.js +50 -0
- package/dist/cjs/constants/index.d.ts +3 -6
- package/dist/cjs/constants/index.js +3 -6
- package/dist/cjs/constants/performance.constants.d.ts +28 -0
- package/dist/cjs/constants/performance.constants.js +43 -0
- package/dist/cjs/handlers/click.handler.d.ts +1 -0
- package/dist/cjs/handlers/click.handler.js +30 -49
- package/dist/cjs/handlers/error.handler.d.ts +11 -6
- package/dist/cjs/handlers/error.handler.js +91 -51
- package/dist/cjs/handlers/page-view.handler.js +38 -29
- package/dist/cjs/handlers/performance.handler.d.ts +3 -0
- package/dist/cjs/handlers/performance.handler.js +76 -37
- package/dist/cjs/handlers/scroll.handler.d.ts +15 -0
- package/dist/cjs/handlers/scroll.handler.js +105 -31
- package/dist/cjs/handlers/session.handler.d.ts +6 -20
- package/dist/cjs/handlers/session.handler.js +38 -326
- package/dist/cjs/integrations/google-analytics.integration.d.ts +0 -1
- package/dist/cjs/integrations/google-analytics.integration.js +27 -98
- package/dist/cjs/listeners/input-listener-managers.d.ts +18 -9
- package/dist/cjs/listeners/input-listener-managers.js +24 -33
- package/dist/cjs/listeners/touch-listener-manager.d.ts +1 -3
- package/dist/cjs/listeners/touch-listener-manager.js +1 -23
- package/dist/cjs/listeners/visibility-listener-manager.d.ts +1 -4
- package/dist/cjs/listeners/visibility-listener-manager.js +6 -42
- package/dist/cjs/managers/api.manager.d.ts +13 -3
- package/dist/cjs/managers/api.manager.js +35 -5
- package/dist/cjs/managers/config.manager.d.ts +53 -3
- package/dist/cjs/managers/config.manager.js +131 -62
- package/dist/cjs/managers/event.manager.d.ts +57 -36
- package/dist/cjs/managers/event.manager.js +266 -417
- package/dist/cjs/managers/sender.manager.d.ts +40 -22
- package/dist/cjs/managers/sender.manager.js +200 -198
- package/dist/cjs/managers/session.manager.d.ts +80 -66
- package/dist/cjs/managers/session.manager.js +267 -522
- package/dist/cjs/managers/state.manager.d.ts +33 -0
- package/dist/cjs/managers/state.manager.js +79 -6
- package/dist/cjs/managers/storage.manager.d.ts +26 -2
- package/dist/cjs/managers/storage.manager.js +67 -34
- package/dist/cjs/managers/tags.manager.d.ts +31 -7
- package/dist/cjs/managers/tags.manager.js +123 -241
- package/dist/cjs/managers/user.manager.d.ts +14 -5
- package/dist/cjs/managers/user.manager.js +17 -9
- package/dist/cjs/public-api.d.ts +10 -1
- package/dist/cjs/public-api.js +18 -24
- package/dist/cjs/test-bridge.d.ts +48 -0
- package/dist/cjs/test-bridge.js +110 -0
- package/dist/cjs/types/api.types.d.ts +21 -6
- package/dist/cjs/types/api.types.js +21 -6
- package/dist/cjs/types/config.types.d.ts +22 -84
- package/dist/cjs/types/emitter.types.d.ts +11 -0
- package/dist/cjs/types/emitter.types.js +8 -0
- package/dist/cjs/types/event.types.d.ts +8 -11
- package/dist/cjs/types/index.d.ts +3 -1
- package/dist/cjs/types/index.js +3 -1
- package/dist/cjs/types/queue.types.d.ts +1 -0
- package/dist/cjs/types/session.types.d.ts +0 -64
- package/dist/cjs/types/state.types.d.ts +1 -0
- package/dist/cjs/types/test-bridge.types.d.ts +38 -0
- package/dist/cjs/types/validation-error.types.d.ts +7 -0
- package/dist/cjs/types/validation-error.types.js +11 -1
- package/dist/cjs/types/window.types.d.ts +1 -8
- package/dist/cjs/utils/data/uuid.utils.d.ts +1 -1
- package/dist/cjs/utils/data/uuid.utils.js +7 -5
- package/dist/cjs/utils/emitter.utils.d.ts +8 -0
- package/dist/cjs/utils/emitter.utils.js +33 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/logging/debug-logger.utils.d.ts +10 -51
- package/dist/cjs/utils/logging/debug-logger.utils.js +36 -127
- package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +4 -0
- package/dist/cjs/utils/network/fetch-with-timeout.utils.js +25 -0
- package/dist/cjs/utils/network/index.d.ts +1 -0
- package/dist/cjs/utils/network/index.js +1 -0
- package/dist/cjs/utils/network/url.utils.js +2 -42
- package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -8
- package/dist/cjs/utils/security/sanitize.utils.js +7 -41
- package/dist/cjs/utils/validations/config-validations.utils.d.ts +7 -0
- package/dist/cjs/utils/validations/config-validations.utils.js +77 -22
- package/dist/esm/api.d.ts +33 -19
- package/dist/esm/api.js +105 -118
- package/dist/esm/app.constants.d.ts +80 -1
- package/dist/esm/app.constants.js +89 -1
- package/dist/esm/app.d.ts +29 -44
- package/dist/esm/app.js +115 -213
- package/dist/esm/app.types.d.ts +2 -7
- package/dist/esm/app.types.js +1 -7
- package/dist/esm/constants/api.constants.js +10 -4
- package/dist/esm/constants/config.constants.d.ts +75 -0
- package/dist/esm/constants/config.constants.js +174 -0
- package/dist/esm/constants/error.constants.d.ts +29 -0
- package/dist/esm/constants/error.constants.js +47 -0
- package/dist/esm/constants/index.d.ts +3 -6
- package/dist/esm/constants/index.js +3 -6
- package/dist/esm/constants/performance.constants.d.ts +28 -0
- package/dist/esm/constants/performance.constants.js +40 -0
- package/dist/esm/handlers/click.handler.d.ts +1 -0
- package/dist/esm/handlers/click.handler.js +30 -49
- package/dist/esm/handlers/error.handler.d.ts +11 -6
- package/dist/esm/handlers/error.handler.js +91 -51
- package/dist/esm/handlers/page-view.handler.js +38 -29
- package/dist/esm/handlers/performance.handler.d.ts +3 -0
- package/dist/esm/handlers/performance.handler.js +71 -32
- package/dist/esm/handlers/scroll.handler.d.ts +15 -0
- package/dist/esm/handlers/scroll.handler.js +106 -32
- package/dist/esm/handlers/session.handler.d.ts +6 -20
- package/dist/esm/handlers/session.handler.js +38 -326
- package/dist/esm/integrations/google-analytics.integration.d.ts +0 -1
- package/dist/esm/integrations/google-analytics.integration.js +27 -98
- package/dist/esm/listeners/input-listener-managers.d.ts +18 -9
- package/dist/esm/listeners/input-listener-managers.js +23 -32
- package/dist/esm/listeners/touch-listener-manager.d.ts +1 -3
- package/dist/esm/listeners/touch-listener-manager.js +1 -23
- package/dist/esm/listeners/visibility-listener-manager.d.ts +1 -4
- package/dist/esm/listeners/visibility-listener-manager.js +6 -42
- package/dist/esm/managers/api.manager.d.ts +13 -3
- package/dist/esm/managers/api.manager.js +34 -3
- package/dist/esm/managers/config.manager.d.ts +53 -3
- package/dist/esm/managers/config.manager.js +133 -64
- package/dist/esm/managers/event.manager.d.ts +57 -36
- package/dist/esm/managers/event.manager.js +268 -419
- package/dist/esm/managers/sender.manager.d.ts +40 -22
- package/dist/esm/managers/sender.manager.js +201 -199
- package/dist/esm/managers/session.manager.d.ts +80 -66
- package/dist/esm/managers/session.manager.js +269 -524
- package/dist/esm/managers/state.manager.d.ts +33 -0
- package/dist/esm/managers/state.manager.js +78 -6
- package/dist/esm/managers/storage.manager.d.ts +26 -2
- package/dist/esm/managers/storage.manager.js +66 -33
- package/dist/esm/managers/tags.manager.d.ts +31 -7
- package/dist/esm/managers/tags.manager.js +124 -242
- package/dist/esm/managers/user.manager.d.ts +14 -5
- package/dist/esm/managers/user.manager.js +17 -9
- package/dist/esm/public-api.d.ts +10 -1
- package/dist/esm/public-api.js +14 -1
- package/dist/esm/test-bridge.d.ts +48 -0
- package/dist/esm/test-bridge.js +106 -0
- package/dist/esm/types/api.types.d.ts +21 -6
- package/dist/esm/types/api.types.js +21 -6
- package/dist/esm/types/config.types.d.ts +22 -84
- package/dist/esm/types/emitter.types.d.ts +11 -0
- package/dist/esm/types/emitter.types.js +5 -0
- package/dist/esm/types/event.types.d.ts +8 -11
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/types/index.js +3 -1
- package/dist/esm/types/queue.types.d.ts +1 -0
- package/dist/esm/types/session.types.d.ts +0 -64
- package/dist/esm/types/state.types.d.ts +1 -0
- package/dist/esm/types/test-bridge.types.d.ts +38 -0
- package/dist/esm/types/validation-error.types.d.ts +7 -0
- package/dist/esm/types/validation-error.types.js +9 -0
- package/dist/esm/types/window.types.d.ts +1 -8
- package/dist/esm/utils/data/uuid.utils.d.ts +1 -1
- package/dist/esm/utils/data/uuid.utils.js +7 -5
- package/dist/esm/utils/emitter.utils.d.ts +8 -0
- package/dist/esm/utils/emitter.utils.js +29 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/logging/debug-logger.utils.d.ts +10 -51
- package/dist/esm/utils/logging/debug-logger.utils.js +36 -127
- package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +4 -0
- package/dist/esm/utils/network/fetch-with-timeout.utils.js +22 -0
- package/dist/esm/utils/network/index.d.ts +1 -0
- package/dist/esm/utils/network/index.js +1 -0
- package/dist/esm/utils/network/url.utils.js +2 -42
- package/dist/esm/utils/security/sanitize.utils.d.ts +1 -8
- package/dist/esm/utils/security/sanitize.utils.js +6 -39
- package/dist/esm/utils/validations/config-validations.utils.d.ts +7 -0
- package/dist/esm/utils/validations/config-validations.utils.js +76 -22
- package/package.json +23 -16
- package/dist/browser/web-vitals-CCnqwnC8.mjs +0 -198
- package/dist/cjs/constants/browser.constants.d.ts +0 -3
- package/dist/cjs/constants/browser.constants.js +0 -41
- package/dist/cjs/constants/initialization.constants.d.ts +0 -40
- package/dist/cjs/constants/initialization.constants.js +0 -48
- package/dist/cjs/constants/limits.constants.d.ts +0 -25
- package/dist/cjs/constants/limits.constants.js +0 -40
- package/dist/cjs/constants/security.constants.d.ts +0 -1
- package/dist/cjs/constants/security.constants.js +0 -12
- package/dist/cjs/constants/timing.constants.d.ts +0 -22
- package/dist/cjs/constants/timing.constants.js +0 -34
- package/dist/cjs/constants/validation.constants.d.ts +0 -13
- package/dist/cjs/constants/validation.constants.js +0 -31
- package/dist/cjs/handlers/network.handler.d.ts +0 -16
- package/dist/cjs/handlers/network.handler.js +0 -136
- package/dist/cjs/managers/cross-tab-session.manager.d.ts +0 -170
- package/dist/cjs/managers/cross-tab-session.manager.js +0 -730
- package/dist/cjs/managers/sampling.manager.d.ts +0 -8
- package/dist/cjs/managers/sampling.manager.js +0 -53
- package/dist/cjs/managers/session-recovery.manager.d.ts +0 -65
- package/dist/cjs/managers/session-recovery.manager.js +0 -237
- package/dist/cjs/types/web-vitals.types.d.ts +0 -6
- package/dist/esm/constants/browser.constants.d.ts +0 -3
- package/dist/esm/constants/browser.constants.js +0 -38
- package/dist/esm/constants/initialization.constants.d.ts +0 -40
- package/dist/esm/constants/initialization.constants.js +0 -45
- package/dist/esm/constants/limits.constants.d.ts +0 -25
- package/dist/esm/constants/limits.constants.js +0 -37
- package/dist/esm/constants/security.constants.d.ts +0 -1
- package/dist/esm/constants/security.constants.js +0 -9
- package/dist/esm/constants/timing.constants.d.ts +0 -22
- package/dist/esm/constants/timing.constants.js +0 -31
- package/dist/esm/constants/validation.constants.d.ts +0 -13
- package/dist/esm/constants/validation.constants.js +0 -28
- package/dist/esm/handlers/network.handler.d.ts +0 -16
- package/dist/esm/handlers/network.handler.js +0 -132
- package/dist/esm/managers/cross-tab-session.manager.d.ts +0 -170
- package/dist/esm/managers/cross-tab-session.manager.js +0 -726
- package/dist/esm/managers/sampling.manager.d.ts +0 -8
- package/dist/esm/managers/sampling.manager.js +0 -49
- package/dist/esm/managers/session-recovery.manager.d.ts +0 -65
- package/dist/esm/managers/session-recovery.manager.js +0 -233
- package/dist/esm/types/web-vitals.types.d.ts +0 -6
- /package/dist/cjs/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
- /package/dist/esm/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GoogleAnalyticsIntegration = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
5
|
const state_manager_1 = require("../managers/state.manager");
|
|
6
6
|
class GoogleAnalyticsIntegration extends state_manager_1.StateManager {
|
|
7
7
|
constructor() {
|
|
8
|
-
super();
|
|
8
|
+
super(...arguments);
|
|
9
9
|
this.isInitialized = false;
|
|
10
10
|
}
|
|
11
11
|
async initialize() {
|
|
@@ -13,69 +13,35 @@ class GoogleAnalyticsIntegration extends state_manager_1.StateManager {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const measurementId = this.get('config').integrations?.googleAnalytics?.measurementId;
|
|
16
|
-
if (!measurementId?.trim()) {
|
|
17
|
-
logging_1.debugLog.clientWarn('GoogleAnalytics', 'Google Analytics integration disabled - measurementId not configured', {
|
|
18
|
-
hasIntegrations: !!this.get('config').integrations,
|
|
19
|
-
hasGoogleAnalytics: !!this.get('config').integrations?.googleAnalytics,
|
|
20
|
-
});
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
16
|
const userId = this.get('userId');
|
|
24
|
-
if (!userId?.trim()) {
|
|
25
|
-
logging_1.debugLog.warn('GoogleAnalytics', 'Google Analytics initialization delayed - userId not available', {
|
|
26
|
-
measurementId: measurementId.substring(0, 8) + '...',
|
|
27
|
-
});
|
|
17
|
+
if (!measurementId?.trim() || !userId?.trim()) {
|
|
28
18
|
return;
|
|
29
19
|
}
|
|
30
20
|
try {
|
|
31
21
|
if (this.isScriptAlreadyLoaded()) {
|
|
32
|
-
logging_1.debugLog.info('GoogleAnalytics', 'Google Analytics script already loaded', { measurementId });
|
|
33
22
|
this.isInitialized = true;
|
|
34
23
|
return;
|
|
35
24
|
}
|
|
36
25
|
await this.loadScript(measurementId);
|
|
37
26
|
this.configureGtag(measurementId, userId);
|
|
38
27
|
this.isInitialized = true;
|
|
39
|
-
logging_1.debugLog.info('GoogleAnalytics', 'Google Analytics integration initialized successfully', {
|
|
40
|
-
measurementId,
|
|
41
|
-
userId,
|
|
42
|
-
});
|
|
43
28
|
}
|
|
44
29
|
catch (error) {
|
|
45
|
-
|
|
30
|
+
utils_1.debugLog.error('GoogleAnalyticsIntegration', 'Initialization failed', {
|
|
46
31
|
error: error instanceof Error ? error.message : 'Unknown error',
|
|
47
|
-
measurementId,
|
|
48
|
-
userId,
|
|
49
32
|
});
|
|
50
33
|
}
|
|
51
34
|
}
|
|
52
35
|
trackEvent(eventName, metadata) {
|
|
53
|
-
if (!eventName?.trim()) {
|
|
54
|
-
logging_1.debugLog.clientWarn('GoogleAnalytics', 'Event tracking skipped - invalid event name provided', {
|
|
55
|
-
eventName,
|
|
56
|
-
hasMetadata: !!metadata && Object.keys(metadata).length > 0,
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (!this.isInitialized) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (typeof window.gtag !== 'function') {
|
|
64
|
-
logging_1.debugLog.warn('GoogleAnalytics', 'Event tracking failed - gtag function not available', {
|
|
65
|
-
eventName,
|
|
66
|
-
hasGtag: typeof window.gtag,
|
|
67
|
-
hasDataLayer: Array.isArray(window.dataLayer),
|
|
68
|
-
});
|
|
36
|
+
if (!eventName?.trim() || !this.isInitialized || typeof window.gtag !== 'function') {
|
|
69
37
|
return;
|
|
70
38
|
}
|
|
71
39
|
try {
|
|
72
40
|
window.gtag('event', eventName, metadata);
|
|
73
41
|
}
|
|
74
42
|
catch (error) {
|
|
75
|
-
|
|
76
|
-
eventName,
|
|
43
|
+
utils_1.debugLog.error('GoogleAnalyticsIntegration', 'Event tracking failed', {
|
|
77
44
|
error: error instanceof Error ? error.message : 'Unknown error',
|
|
78
|
-
metadataKeys: Object.keys(metadata || {}),
|
|
79
45
|
});
|
|
80
46
|
}
|
|
81
47
|
}
|
|
@@ -85,75 +51,38 @@ class GoogleAnalyticsIntegration extends state_manager_1.StateManager {
|
|
|
85
51
|
if (script) {
|
|
86
52
|
script.remove();
|
|
87
53
|
}
|
|
88
|
-
logging_1.debugLog.info('GoogleAnalytics', 'Google Analytics integration cleanup completed');
|
|
89
54
|
}
|
|
90
55
|
isScriptAlreadyLoaded() {
|
|
91
|
-
|
|
92
|
-
if (
|
|
56
|
+
// Check if we already loaded the script
|
|
57
|
+
if (document.getElementById('tracelog-ga-script')) {
|
|
93
58
|
return true;
|
|
94
59
|
}
|
|
60
|
+
// Check if GA is already loaded by another source
|
|
95
61
|
const existingGAScript = document.querySelector('script[src*="googletagmanager.com/gtag/js"]');
|
|
96
|
-
|
|
97
|
-
logging_1.debugLog.clientWarn('GoogleAnalytics', 'Google Analytics script already loaded from external source', {
|
|
98
|
-
scriptSrc: existingGAScript.getAttribute('src'),
|
|
99
|
-
hasGtag: typeof window.gtag === 'function',
|
|
100
|
-
});
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
62
|
+
return !!existingGAScript;
|
|
104
63
|
}
|
|
105
64
|
async loadScript(measurementId) {
|
|
106
65
|
return new Promise((resolve, reject) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
script.onerror = () => {
|
|
116
|
-
const error = new Error('Failed to load Google Analytics script');
|
|
117
|
-
logging_1.debugLog.error('GoogleAnalytics', 'Google Analytics script load failed', {
|
|
118
|
-
measurementId,
|
|
119
|
-
error: error.message,
|
|
120
|
-
scriptSrc: script.src,
|
|
121
|
-
});
|
|
122
|
-
reject(error);
|
|
123
|
-
};
|
|
124
|
-
document.head.appendChild(script);
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
const errorMsg = error instanceof Error ? error : new Error(String(error));
|
|
128
|
-
logging_1.debugLog.error('GoogleAnalytics', 'Error creating Google Analytics script', {
|
|
129
|
-
measurementId,
|
|
130
|
-
error: errorMsg.message,
|
|
131
|
-
});
|
|
132
|
-
reject(errorMsg);
|
|
133
|
-
}
|
|
66
|
+
const script = document.createElement('script');
|
|
67
|
+
script.id = 'tracelog-ga-script';
|
|
68
|
+
script.async = true;
|
|
69
|
+
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
|
|
70
|
+
script.onload = () => resolve();
|
|
71
|
+
script.onerror = () => reject(new Error('Failed to load Google Analytics script'));
|
|
72
|
+
document.head.appendChild(script);
|
|
134
73
|
});
|
|
135
74
|
}
|
|
136
75
|
configureGtag(measurementId, userId) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
document.head.appendChild(gaScriptConfig);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
logging_1.debugLog.error('GoogleAnalytics', 'Failed to configure Google Analytics', {
|
|
151
|
-
measurementId,
|
|
152
|
-
userId,
|
|
153
|
-
error: error instanceof Error ? error.message : 'Unknown error',
|
|
154
|
-
});
|
|
155
|
-
throw error;
|
|
156
|
-
}
|
|
76
|
+
const gaScriptConfig = document.createElement('script');
|
|
77
|
+
gaScriptConfig.innerHTML = `
|
|
78
|
+
window.dataLayer = window.dataLayer || [];
|
|
79
|
+
function gtag(){dataLayer.push(arguments);}
|
|
80
|
+
gtag('js', new Date());
|
|
81
|
+
gtag('config', '${measurementId}', {
|
|
82
|
+
'user_id': '${userId}'
|
|
83
|
+
});
|
|
84
|
+
`;
|
|
85
|
+
document.head.appendChild(gaScriptConfig);
|
|
157
86
|
}
|
|
158
87
|
}
|
|
159
88
|
exports.GoogleAnalyticsIntegration = GoogleAnalyticsIntegration;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { EventListenerManager } from './listeners.types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Base class for input listener managers to reduce code duplication
|
|
4
|
+
*/
|
|
5
|
+
declare abstract class BaseInputListenerManager implements EventListenerManager {
|
|
6
|
+
protected readonly onActivity: () => void;
|
|
7
|
+
protected readonly options: {
|
|
8
|
+
passive: boolean;
|
|
9
|
+
};
|
|
10
|
+
protected abstract readonly events: string[];
|
|
11
|
+
protected abstract readonly logPrefix: string;
|
|
5
12
|
constructor(onActivity: () => void);
|
|
6
13
|
setup(): void;
|
|
7
14
|
cleanup(): void;
|
|
8
15
|
}
|
|
9
|
-
export declare class
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
export declare class MouseListenerManager extends BaseInputListenerManager {
|
|
17
|
+
protected readonly events: string[];
|
|
18
|
+
protected readonly logPrefix = "MouseListenerManager";
|
|
19
|
+
}
|
|
20
|
+
export declare class KeyboardListenerManager extends BaseInputListenerManager {
|
|
21
|
+
protected readonly events: string[];
|
|
22
|
+
protected readonly logPrefix = "KeyboardListenerManager";
|
|
15
23
|
}
|
|
24
|
+
export {};
|
|
@@ -2,57 +2,48 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KeyboardListenerManager = exports.MouseListenerManager = void 0;
|
|
4
4
|
const logging_1 = require("../utils/logging");
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Base class for input listener managers to reduce code duplication
|
|
7
|
+
*/
|
|
8
|
+
class BaseInputListenerManager {
|
|
6
9
|
constructor(onActivity) {
|
|
7
10
|
this.options = { passive: true };
|
|
8
11
|
this.onActivity = onActivity;
|
|
9
12
|
}
|
|
10
13
|
setup() {
|
|
11
14
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
this.events.forEach((event) => {
|
|
16
|
+
window.addEventListener(event, this.onActivity, this.options);
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
19
|
catch (error) {
|
|
17
|
-
logging_1.debugLog.error(
|
|
18
|
-
throw error;
|
|
20
|
+
logging_1.debugLog.error(this.logPrefix, `Failed to setup ${this.logPrefix.toLowerCase()} listeners`, { error });
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
cleanup() {
|
|
22
24
|
try {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
this.events.forEach((event) => {
|
|
26
|
+
window.removeEventListener(event, this.onActivity);
|
|
27
|
+
});
|
|
26
28
|
}
|
|
27
29
|
catch (error) {
|
|
28
|
-
logging_1.debugLog.warn(
|
|
30
|
+
logging_1.debugLog.warn(this.logPrefix, `Error during ${this.logPrefix.toLowerCase()} listeners cleanup`, { error });
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
34
|
+
class MouseListenerManager extends BaseInputListenerManager {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
this.events = ['mousemove', 'mousedown', 'wheel'];
|
|
38
|
+
this.logPrefix = 'MouseListenerManager';
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
cleanup() {
|
|
49
|
-
try {
|
|
50
|
-
window.removeEventListener('keydown', this.onActivity);
|
|
51
|
-
window.removeEventListener('keypress', this.onActivity);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
logging_1.debugLog.warn('KeyboardListenerManager', 'Error during keyboard listeners cleanup', { error });
|
|
55
|
-
}
|
|
40
|
+
}
|
|
41
|
+
exports.MouseListenerManager = MouseListenerManager;
|
|
42
|
+
class KeyboardListenerManager extends BaseInputListenerManager {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
this.events = ['keydown'];
|
|
46
|
+
this.logPrefix = 'KeyboardListenerManager';
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
exports.KeyboardListenerManager = KeyboardListenerManager;
|
|
@@ -2,9 +2,7 @@ import { EventListenerManager } from './listeners.types';
|
|
|
2
2
|
export declare class TouchListenerManager implements EventListenerManager {
|
|
3
3
|
private readonly onActivity;
|
|
4
4
|
private readonly options;
|
|
5
|
-
|
|
6
|
-
constructor(onActivity: () => void, motionThreshold: number);
|
|
5
|
+
constructor(onActivity: () => void);
|
|
7
6
|
setup(): void;
|
|
8
7
|
cleanup(): void;
|
|
9
|
-
private readonly handleDeviceMotion;
|
|
10
8
|
}
|
|
@@ -3,24 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TouchListenerManager = void 0;
|
|
4
4
|
const logging_1 = require("../utils/logging");
|
|
5
5
|
class TouchListenerManager {
|
|
6
|
-
constructor(onActivity
|
|
6
|
+
constructor(onActivity) {
|
|
7
7
|
this.options = { passive: true };
|
|
8
|
-
this.handleDeviceMotion = (event) => {
|
|
9
|
-
try {
|
|
10
|
-
const acceleration = event.acceleration;
|
|
11
|
-
if (acceleration) {
|
|
12
|
-
const totalAcceleration = Math.abs(acceleration.x ?? 0) + Math.abs(acceleration.y ?? 0) + Math.abs(acceleration.z ?? 0);
|
|
13
|
-
if (totalAcceleration > this.motionThreshold) {
|
|
14
|
-
this.onActivity();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
logging_1.debugLog.warn('TouchListenerManager', 'Error handling device motion event', { error });
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
8
|
this.onActivity = onActivity;
|
|
23
|
-
this.motionThreshold = motionThreshold;
|
|
24
9
|
}
|
|
25
10
|
setup() {
|
|
26
11
|
try {
|
|
@@ -28,10 +13,6 @@ class TouchListenerManager {
|
|
|
28
13
|
window.addEventListener('touchmove', this.onActivity, this.options);
|
|
29
14
|
window.addEventListener('touchend', this.onActivity, this.options);
|
|
30
15
|
window.addEventListener('orientationchange', this.onActivity, this.options);
|
|
31
|
-
const hasDeviceMotion = 'DeviceMotionEvent' in window;
|
|
32
|
-
if (hasDeviceMotion) {
|
|
33
|
-
window.addEventListener('devicemotion', this.handleDeviceMotion, this.options);
|
|
34
|
-
}
|
|
35
16
|
}
|
|
36
17
|
catch (error) {
|
|
37
18
|
logging_1.debugLog.error('TouchListenerManager', 'Failed to setup touch listeners', { error });
|
|
@@ -44,9 +25,6 @@ class TouchListenerManager {
|
|
|
44
25
|
window.removeEventListener('touchmove', this.onActivity);
|
|
45
26
|
window.removeEventListener('touchend', this.onActivity);
|
|
46
27
|
window.removeEventListener('orientationchange', this.onActivity);
|
|
47
|
-
if ('DeviceMotionEvent' in window) {
|
|
48
|
-
window.removeEventListener('devicemotion', this.handleDeviceMotion);
|
|
49
|
-
}
|
|
50
28
|
}
|
|
51
29
|
catch (error) {
|
|
52
30
|
logging_1.debugLog.warn('TouchListenerManager', 'Error during touch listeners cleanup', { error });
|
|
@@ -2,11 +2,8 @@ import { EventListenerManager } from './listeners.types';
|
|
|
2
2
|
export declare class VisibilityListenerManager implements EventListenerManager {
|
|
3
3
|
private readonly onActivity;
|
|
4
4
|
private readonly onVisibilityChange;
|
|
5
|
-
private readonly isMobile;
|
|
6
5
|
private readonly options;
|
|
7
|
-
constructor(onActivity: () => void, onVisibilityChange: () => void
|
|
6
|
+
constructor(onActivity: () => void, onVisibilityChange: () => void);
|
|
8
7
|
setup(): void;
|
|
9
8
|
cleanup(): void;
|
|
10
|
-
private setupMobileEvents;
|
|
11
|
-
private cleanupMobileEvents;
|
|
12
9
|
}
|
|
@@ -3,32 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VisibilityListenerManager = void 0;
|
|
4
4
|
const logging_1 = require("../utils/logging");
|
|
5
5
|
class VisibilityListenerManager {
|
|
6
|
-
constructor(onActivity, onVisibilityChange
|
|
6
|
+
constructor(onActivity, onVisibilityChange) {
|
|
7
7
|
this.options = { passive: true };
|
|
8
8
|
this.onActivity = onActivity;
|
|
9
9
|
this.onVisibilityChange = onVisibilityChange;
|
|
10
|
-
this.isMobile = isMobile;
|
|
11
10
|
}
|
|
12
11
|
setup() {
|
|
13
12
|
try {
|
|
14
|
-
|
|
15
|
-
if (
|
|
13
|
+
// Core visibility API support
|
|
14
|
+
if ('visibilityState' in document) {
|
|
16
15
|
document.addEventListener('visibilitychange', this.onVisibilityChange, this.options);
|
|
17
16
|
}
|
|
17
|
+
// Window focus/blur events
|
|
18
18
|
window.addEventListener('blur', this.onVisibilityChange, this.options);
|
|
19
19
|
window.addEventListener('focus', this.onActivity, this.options);
|
|
20
|
-
|
|
21
|
-
if (
|
|
20
|
+
// Basic network status detection
|
|
21
|
+
if ('onLine' in navigator) {
|
|
22
22
|
window.addEventListener('online', this.onActivity, this.options);
|
|
23
23
|
window.addEventListener('offline', this.onVisibilityChange, this.options);
|
|
24
24
|
}
|
|
25
|
-
if (this.isMobile) {
|
|
26
|
-
this.setupMobileEvents();
|
|
27
|
-
}
|
|
28
25
|
}
|
|
29
26
|
catch (error) {
|
|
30
27
|
logging_1.debugLog.error('VisibilityListenerManager', 'Failed to setup visibility listeners', { error });
|
|
31
|
-
throw error;
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
cleanup() {
|
|
@@ -42,42 +38,10 @@ class VisibilityListenerManager {
|
|
|
42
38
|
window.removeEventListener('online', this.onActivity);
|
|
43
39
|
window.removeEventListener('offline', this.onVisibilityChange);
|
|
44
40
|
}
|
|
45
|
-
if (this.isMobile) {
|
|
46
|
-
this.cleanupMobileEvents();
|
|
47
|
-
}
|
|
48
41
|
}
|
|
49
42
|
catch (error) {
|
|
50
43
|
logging_1.debugLog.warn('VisibilityListenerManager', 'Error during visibility listeners cleanup', { error });
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
|
-
setupMobileEvents() {
|
|
54
|
-
try {
|
|
55
|
-
document.addEventListener('pause', this.onVisibilityChange, this.options);
|
|
56
|
-
document.addEventListener('resume', this.onActivity, this.options);
|
|
57
|
-
const hasOrientationAPI = 'orientation' in screen;
|
|
58
|
-
if (hasOrientationAPI) {
|
|
59
|
-
screen.orientation.addEventListener('change', this.onActivity, this.options);
|
|
60
|
-
}
|
|
61
|
-
window.addEventListener('pageshow', this.onActivity, this.options);
|
|
62
|
-
window.addEventListener('pagehide', this.onActivity, this.options);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
logging_1.debugLog.warn('VisibilityListenerManager', 'Failed to setup mobile listeners', { error });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
cleanupMobileEvents() {
|
|
69
|
-
try {
|
|
70
|
-
document.removeEventListener('pause', this.onVisibilityChange);
|
|
71
|
-
document.removeEventListener('resume', this.onActivity);
|
|
72
|
-
if ('orientation' in screen) {
|
|
73
|
-
screen.orientation.removeEventListener('change', this.onActivity);
|
|
74
|
-
}
|
|
75
|
-
window.removeEventListener('pageshow', this.onActivity);
|
|
76
|
-
window.removeEventListener('pagehide', this.onActivity);
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
logging_1.debugLog.warn('VisibilityListenerManager', 'Error during mobile listeners cleanup', { error });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
46
|
}
|
|
83
47
|
exports.VisibilityListenerManager = VisibilityListenerManager;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates API URL for TraceLog service based on project ID
|
|
3
|
+
*
|
|
4
|
+
* Handles two special cases:
|
|
5
|
+
* - 'localhost:PORT' - for local development (generates http://localhost:PORT)
|
|
6
|
+
* - Regular project IDs - generates subdomain URLs via getApiUrl utility
|
|
7
|
+
*
|
|
8
|
+
* @param id Project ID or localhost address
|
|
9
|
+
* @param allowHttp Whether to allow HTTP protocol (default: false)
|
|
10
|
+
* @returns Generated API URL
|
|
11
|
+
* @throws Error if URL generation or validation fails
|
|
12
|
+
*/
|
|
13
|
+
export declare function getApiUrlForProject(id: string, allowHttp?: boolean): string;
|
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getApiUrlForProject = getApiUrlForProject;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const logging_1 = require("../utils/logging");
|
|
7
|
+
/**
|
|
8
|
+
* Generates API URL for TraceLog service based on project ID
|
|
9
|
+
*
|
|
10
|
+
* Handles two special cases:
|
|
11
|
+
* - 'localhost:PORT' - for local development (generates http://localhost:PORT)
|
|
12
|
+
* - Regular project IDs - generates subdomain URLs via getApiUrl utility
|
|
13
|
+
*
|
|
14
|
+
* @param id Project ID or localhost address
|
|
15
|
+
* @param allowHttp Whether to allow HTTP protocol (default: false)
|
|
16
|
+
* @returns Generated API URL
|
|
17
|
+
* @throws Error if URL generation or validation fails
|
|
18
|
+
*/
|
|
19
|
+
function getApiUrlForProject(id, allowHttp = false) {
|
|
20
|
+
try {
|
|
21
|
+
// Handle localhost development case
|
|
22
|
+
if (id.startsWith(types_1.SpecialProjectId.Localhost)) {
|
|
23
|
+
const url = `http://${id}`;
|
|
24
|
+
if (!(0, utils_1.isValidUrl)(url, true)) {
|
|
25
|
+
throw new Error(`Invalid localhost URL format: ${id}`);
|
|
26
|
+
}
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
// Handle regular project ID case
|
|
7
30
|
const url = (0, utils_1.getApiUrl)(id, allowHttp);
|
|
8
31
|
if (!(0, utils_1.isValidUrl)(url, allowHttp)) {
|
|
9
|
-
throw new Error(
|
|
32
|
+
throw new Error(`Generated API URL failed validation: ${url}`);
|
|
10
33
|
}
|
|
11
34
|
return url;
|
|
12
35
|
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logging_1.debugLog.error('ApiManager', 'API URL generation failed', {
|
|
38
|
+
projectId: id,
|
|
39
|
+
allowHttp,
|
|
40
|
+
error: error instanceof Error ? error.message : error,
|
|
41
|
+
});
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
13
44
|
}
|
|
14
|
-
exports.ApiManager = ApiManager;
|
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
import { AppConfig, Config } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration manager responsible for loading and merging application configuration.
|
|
4
|
+
*
|
|
5
|
+
* Handles three configuration sources:
|
|
6
|
+
* 1. Default configuration (fallback values)
|
|
7
|
+
* 2. API configuration (server-side settings)
|
|
8
|
+
* 3. App configuration (client initialization settings)
|
|
9
|
+
*
|
|
10
|
+
* Supports special project IDs for development and testing:
|
|
11
|
+
* - 'skip': Bypasses all network calls, uses defaults
|
|
12
|
+
* - 'localhost:PORT': Loads config from local development server
|
|
13
|
+
*/
|
|
2
14
|
export declare class ConfigManager {
|
|
15
|
+
private static readonly LOCALHOST_PATTERN;
|
|
16
|
+
private static readonly PRODUCTION_DOMAINS;
|
|
17
|
+
/**
|
|
18
|
+
* Gets complete configuration by merging default, API, and app configurations.
|
|
19
|
+
*
|
|
20
|
+
* @param apiUrl - Base URL for the configuration API
|
|
21
|
+
* @param appConfig - Client-side configuration from init()
|
|
22
|
+
* @returns Promise<Config> - Merged configuration object
|
|
23
|
+
*/
|
|
3
24
|
get(apiUrl: string, appConfig: AppConfig): Promise<Config>;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loads configuration from API and merges with app config.
|
|
27
|
+
*/
|
|
28
|
+
private loadFromApi;
|
|
29
|
+
/**
|
|
30
|
+
* Builds the configuration URL based on project type and QA mode.
|
|
31
|
+
*/
|
|
32
|
+
private buildConfigUrl;
|
|
33
|
+
/**
|
|
34
|
+
* Builds request headers based on project configuration.
|
|
35
|
+
*/
|
|
36
|
+
private buildHeaders;
|
|
37
|
+
/**
|
|
38
|
+
* Parses and validates JSON response from config API.
|
|
39
|
+
*/
|
|
40
|
+
private parseJsonResponse;
|
|
41
|
+
/**
|
|
42
|
+
* Validates localhost project ID format and port range.
|
|
43
|
+
*/
|
|
44
|
+
private validateLocalhostProjectId;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if QA mode is enabled via URL parameter.
|
|
47
|
+
*/
|
|
48
|
+
private isQaModeEnabled;
|
|
49
|
+
/**
|
|
50
|
+
* Merges API configuration with app configuration and applies mode-specific settings.
|
|
51
|
+
*/
|
|
52
|
+
private mergeConfigurations;
|
|
53
|
+
/**
|
|
54
|
+
* Creates default configuration for skip mode and fallback scenarios.
|
|
55
|
+
*/
|
|
56
|
+
private createDefaultConfig;
|
|
7
57
|
}
|