UNPKG

@leancodepl/gtag

Version:

Google Tag Manager integration utilities for web analytics

22 lines (20 loc) 762 B
/** * Creates a type-safe Google Tag Manager data layer push function. * * Returns a function that pushes events to the GTM data layer with type safety. * Handles cases where GTM is not initialized by safely checking for dataLayer existence. * * @template T - Event object type extending { event: string } * @returns Function that accepts data layer arguments and pushes to GTM * @example * ```typescript * const gtag = mkgtag<{ event: 'purchase'; value: number }>(); * gtag({ event: 'purchase', value: 29.99 }); * ``` */ function mkgtag() { return (dataLayerArguments)=>{ var _window_dataLayer; (_window_dataLayer = window.dataLayer) == null ? void 0 : _window_dataLayer.push(dataLayerArguments); }; } export { mkgtag };