Skip to content

Commit ab3e838

Browse files
committed
skip sending analytics for localhost
1 parent 6d96da0 commit ab3e838

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

analytics.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ class AnalyticsTracker {
149149
// console.log('Fetched data: ', data);
150150
return data;
151151
} catch (error) {
152-
console.error('Fetch error: ', error);
152+
// Suppress CORS errors in local development
153+
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
154+
if (isLocalhost) {
155+
console.log('[Analytics] Skipping analytics in local development (CORS restriction)');
156+
} else {
157+
console.error('[Analytics] Fetch error: ', error);
158+
}
153159
}
154160
}
155161

@@ -401,6 +407,13 @@ class AnalyticsTracker {
401407
// Initialization
402408
// ========================
403409
static init() {
410+
// Skip analytics in local development to avoid CORS errors
411+
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
412+
if (isLocalhost) {
413+
console.log('[Analytics] Skipping analytics in local development environment.');
414+
return;
415+
}
416+
404417
// Only initialize analytics if user has consented
405418
if (!this.hasConsent()) {
406419
console.log('[Analytics] User has not consented to tracking. Analytics disabled.');

0 commit comments

Comments
 (0)