Skip to content

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.

tracker.trackEvent(input: BrowserEventInput): Promise<void>;
type BrowserEventInput = {
name: string;
params?: Record<string, unknown>;
};
FieldRequiredNotes
nameyesThe GA4 event name (e.g. 'sign_up', 'add_to_cart').
paramsnoEvent parameters. Free-form; whatever GA4 expects for the event in question.

Promise<void>. Resolves after the gtag push has been queued.

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>
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 }],
},
});

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.