UNPKG

@shopana/ga

Version:

Type-safe Google Analytics 4 (GA4) tracking library for React and Next.js with ecommerce support, event batching, and SSR compatibility

31 lines 895 B
import {} from '../types/events'; export function normalizeItems(items) { return items.map((item) => ({ ...item, quantity: normalizeQuantity(item.quantity), price: normalizePrice(item.price), })); } export function sanitizeNumeric(source, keys) { const result = {}; for (const key of keys) { const value = source[key]; if (typeof value === 'number' && Number.isFinite(value)) { result[key] = Number(value); } } return result; } function normalizeQuantity(quantity) { if (typeof quantity !== 'number' || Number.isNaN(quantity)) { return 1; } return Math.max(1, Math.floor(quantity)); } function normalizePrice(price) { if (typeof price !== 'number' || !Number.isFinite(price)) { return undefined; } return Math.round(price * 100) / 100; } //# sourceMappingURL=utils.js.map