import { Mapping, WalkerOS, Flow, Hint } from '@walkeros/core'; /** Raw input to the decoder. Origin-agnostic (express, lambda, pubsub, etc). */ interface GA4Request { /** Full request URL including query string. */ url: string; /** POST body if present. May be \n- or \r\n-separated multi-event lines. */ body?: string; } /** * Parsed GA4 wire payload. One request → one hit → N events. * IMPORTANT: dotted GA4 keys (`ep.transaction_id`, `epn.value`) are nested * into structured objects at parse time so the mapping engine's getByPath * (which splits paths on `.`) can resolve them. */ interface GA4Hit { /** Hit-level params from the URL query string. v, tid, cid, sid, dl, dt, ul, sr, gcs, gtm, p. */ hit: GA4HitParams; /** One entry per body line (POST) or single entry (GET). */ events: GA4Event[]; } /** Hit-level params extracted from URL query. Known keys typed; unknown keys allowed. */ interface GA4HitParams { v?: string; tid?: string; cid?: string; sid?: string; sct?: string; seg?: string; _p?: string; _z?: string; gtm?: string; dl?: string; dt?: string; dr?: string; ul?: string; sr?: string; uid?: string; _dbg?: string; _s?: string; _ss?: string; _fv?: string; gcs?: string; gcd?: string; dma?: string; dma_cps?: string; npa?: string; p?: string; [other: string]: string | undefined; } interface GA4Event { /** Event name from `en` param. */ en: string; /** * Per-event params with dotted keys nested: * raw `ep.transaction_id` → `params.ep.transaction_id` * raw `epn.value` → `params.epn.value` * raw `up.role` → `params.up.role` * raw `upn.score` → `params.upn.score` * Standalone keys: `_et`, `_c` stay flat. */ params: GA4EventParams; /** Parsed items from pr1, pr2, ..., prN. Empty array if none. */ items: GA4Item[]; } interface GA4EventParams { /** String event params from ep.. */ ep: Record; /** Numeric event params from epn.. Values are coerced via Number(). */ epn: Record; /** String user properties from up.. */ up: Record; /** Numeric user properties from upn.. */ upn: Record; /** Engagement time delta (ms). */ _et?: number; /** Is-conversion flag. */ _c?: string; } /** Parsed product item from one pr param. */ interface GA4Item { id?: string; name?: string; brand?: string; category?: string; category2?: string; category3?: string; category4?: string; category5?: string; variant?: string; price?: number; quantity?: number; coupon?: string; discount?: number; listName?: string; listId?: string; listPosition?: number; locationId?: string; affiliation?: string; creativeName?: string; creativeSlot?: string; promotionId?: string; promotionName?: string; /** Custom item params from k/v pairs (multi-digit N supported). */ custom: Record; } /** Decoder settings. */ interface GA4Settings { /** * Mapping registry keyed by GA4 event name (`en`). * User config replaces matching package defaults at the per-event key. * Use `'*'` for the unknown-event fallback. * Set a rule's `ignore: true` to drop matching events. */ mapping?: GA4Mapping; /** * Regex string to filter `tid` values. Default `^G-` (drops Ads `AW-`/DC `DC-`). * String at config time, compiled to RegExp once at init. */ tidPattern?: string; } /** Per-event mapping rule keyed by GA4 event name. */ type GA4Mapping = Record & { '*'?: Mapping.Rule; }; declare function parseQuery(url: string): Record; declare function parseBody(body: string): Record[]; declare function parseItem(value: string): GA4Item; declare function parseConsent(hit: { gcs?: string; }): WalkerOS.Consent; declare function parseRequest(req: GA4Request): GA4Hit; /** * Default GA4 event-name → walkerOS mapping rules. * Users may override or extend these via settings.mapping at config time. * The `'*'` key is the fallback for unknown event names. * * Field naming for `data.map`: * - Monetary: `currency` from `ep.currency`, `value`/`total` from `epn.value`, * `tax` from `epn.tax`, `shipping` from `epn.shipping`, `coupon` from * `ep.coupon`. * - Promotions read from `firstItem` (synthetic `items[0]` reference exposed by * the mapper), since GA4 encodes promotion info inside item tilde strings. */ declare const defaultMapping: GA4Mapping; /** * Convert a parsed GA4 hit into zero or more walkerOS events. * One GA4 hit may carry several events (POST batch); each is mapped * independently with hit-level metadata merged in. */ declare function mapHitToEvents(hit: GA4Hit, mapping: GA4Mapping): WalkerOS.DeepPartialEvent[]; declare const pageView: Flow.StepExample; declare const purchase: Flow.StepExample; declare const viewItem: Flow.StepExample; declare const addToCart: Flow.StepExample; declare const beginCheckout: Flow.StepExample; declare const scroll: Flow.StepExample; declare const search: Flow.StepExample; declare const login: Flow.StepExample; declare const customEvent: Flow.StepExample; declare const consentDenied: Flow.StepExample; declare const userEngagementIgnored: Flow.StepExample; declare const batchPost: Flow.StepExample; declare const step_addToCart: typeof addToCart; declare const step_batchPost: typeof batchPost; declare const step_beginCheckout: typeof beginCheckout; declare const step_consentDenied: typeof consentDenied; declare const step_customEvent: typeof customEvent; declare const step_login: typeof login; declare const step_pageView: typeof pageView; declare const step_purchase: typeof purchase; declare const step_scroll: typeof scroll; declare const step_search: typeof search; declare const step_userEngagementIgnored: typeof userEngagementIgnored; declare const step_viewItem: typeof viewItem; declare namespace step { export { step_addToCart as addToCart, step_batchPost as batchPost, step_beginCheckout as beginCheckout, step_consentDenied as consentDenied, step_customEvent as customEvent, step_login as login, step_pageView as pageView, step_purchase as purchase, step_scroll as scroll, step_search as search, step_userEngagementIgnored as userEngagementIgnored, step_viewItem as viewItem }; } declare const index_step: typeof step; declare namespace index { export { index_step as step }; } declare const hints: Hint.Hints; export { type GA4Event, type GA4EventParams, type GA4Hit, type GA4HitParams, type GA4Item, type GA4Mapping, type GA4Request, type GA4Settings, defaultMapping, index as examples, hints, mapHitToEvents, parseBody, parseConsent, parseItem, parseQuery, parseRequest };