Files
klz-cables.com/lib/services/analytics/noop-analytics-service.ts
Marc Mintel c646815a3a
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 1m14s
Build & Deploy / 🧪 QA (push) Successful in 3m20s
Build & Deploy / 🧪 Smoke Test (push) Failing after 49s
Build & Deploy / ⚡ Lighthouse (push) Successful in 3m24s
Build & Deploy / 🏗️ Build (push) Successful in 3m2s
Build & Deploy / 🚀 Deploy (push) Successful in 26s
Build & Deploy / 🔔 Notify (push) Successful in 2s
chore(analytics): completely scrub NEXT_PUBLIC prefix from umami website id across codebase and docs
2026-02-20 15:29:50 +01:00

68 lines
2.0 KiB
TypeScript

import type { AnalyticsEventProperties, AnalyticsService } from './analytics-service';
/**
* No-op Analytics Service Implementation.
*
* This service implements the AnalyticsService interface but does nothing.
* It's used as a fallback when analytics are disabled or not configured.
*
* @example
* ```typescript
* // Service creation (usually done by create-services.ts)
* const service = new NoopAnalyticsService();
*
* // These calls do nothing but are safe to execute
* service.track('button_click', { button_id: 'cta' });
* service.trackPageview('/products/123');
* ```
*
* @example
* ```typescript
* // Automatic fallback in create-services.ts
* const umamiEnabled = Boolean(process.env.UMAMI_WEBSITE_ID);
* const analytics = umamiEnabled
* ? new UmamiAnalyticsService({ enabled: true })
* : new NoopAnalyticsService(); // Fallback when no website ID
* ```
*/
export class NoopAnalyticsService implements AnalyticsService {
/**
* No-op implementation of track.
*
* This method does nothing but maintains the same signature as other
* analytics services for consistency.
*
* @param _eventName - Event name (ignored)
* @param _props - Event properties (ignored)
*
* @example
* ```typescript
* // Safe to call even when analytics are disabled
* service.track('button_click', { button_id: 'cta' });
* // No error, no action taken
* ```
*/
track(_eventName: string, _props?: AnalyticsEventProperties) {
// intentionally noop - analytics are disabled
}
/**
* No-op implementation of trackPageview.
*
* This method does nothing but maintains the same signature as other
* analytics services for consistency.
*
* @param _url - URL to track (ignored)
*
* @example
* ```typescript
* // Safe to call even when analytics are disabled
* service.trackPageview('/products/123');
* // No error, no action taken
* ```
*/
trackPageview(_url?: string) {
// intentionally noop - analytics are disabled
}
}