Files
klz-cables.com/lib/services/analytics/noop-analytics-service.ts
Marc Mintel 72711c74ba
Some checks failed
Build & Deploy KLZ Cables / deploy (push) Failing after 13m20s
umami
2026-01-24 22:03:06 +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.NEXT_PUBLIC_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
}
}