UNPKG

unified-analytics

Version:

Unified analytics library for web applications

55 lines (54 loc) 1.71 kB
import type { AnalyticsEvent, AnalyticsObserver } from "../types"; declare global { interface Window { gtag: (...args: any[]) => void; dataLayer: any[]; } } /** * Configuration options for GA4 analytics */ export interface GA4Options { /** Google Analytics 4 measurement ID (format: G-XXXXXXXX) */ measurementId: string; /** Custom configuration parameters */ config?: Record<string, any>; /** Whether to enable debug mode */ debug?: boolean; } /** * Google Analytics 4 service implementation using gtag.js */ export declare class GoogleAnalytics4Service implements AnalyticsObserver { private _measurementId?; private _initialized; private _debug; private _config?; /** * Get the measurement ID for this GA4 instance */ getInstance(): string | undefined; /** * Initialize Google Analytics 4 with the provided measurement ID * @param options - Configuration options for GA4 */ init(options: GA4Options): void; /** * Track an event in Google Analytics 4 * @param event - The event to track * @param debug - Whether to log debug information */ onEvent(event: AnalyticsEvent, debug?: boolean): void; /** * Create a new instance of GoogleAnalytics4Service * @returns A new GoogleAnalytics4Service instance */ clone(): GoogleAnalytics4Service; /** * Load the gtag.js script and initialize with the provided measurement ID * @param measurementId - The GA4 measurement ID * @param config - Optional configuration parameters */ private _loadGtagScript; } export declare const googleAnalytics4Service: GoogleAnalytics4Service;