tracker.trackEvent()
Fires one GA4 event through window.gtag. This is a thin wrapper around gtag('event', name, params) — Trackbridge’s value-add is that it shares construction, debug logging, and consent state with trackConversion, not that it transforms the event.
Signature
Section titled “Signature”tracker.trackEvent(input: BrowserEventInput): Promise<void>;BrowserEventInput
Section titled “BrowserEventInput”type BrowserEventInput = { name: string; params?: Record<string, unknown>;};| Field | Required | Notes |
|---|---|---|
name | yes | The GA4 event name (e.g. 'sign_up', 'add_to_cart'). |
params | no | Event parameters. Free-form; whatever GA4 expects for the event in question. |
Returns
Section titled “Returns”Promise<void>. Resolves after the gtag push has been queued.
Behavior
Section titled “Behavior”Calls window.gtag('event', input.name, input.params ?? {}). The call is internally wrapped in a try/catch — gtag exceptions are swallowed unless debug: true, in which case they’re logged via console.warn:
[trackbridge] gtag event failed: <error>Example
Section titled “Example”import { tracker } from '@/lib/tracker.client';
await tracker.trackEvent({ name: 'add_to_cart', params: { currency: 'USD', value: 29.99, items: [{ item_id: 'sku-123', quantity: 1, price: 29.99 }], },});When not to use this
Section titled “When not to use this”For Google Ads conversions, use trackConversion(), not trackEvent(). Conversions need the dedup key, the click-identifier attachment, and the userData hashing — none of which trackEvent does.
See also
Section titled “See also”serverTracker.trackEvent()— the GA4 Measurement Protocol equivalent.