useTracker()
Returns the BrowserTracker instance held by the nearest <TrackbridgeProvider> ancestor. The standard way to call any tracker method from a client component.
Signature
Section titled “Signature”import { useTracker } from '@trackbridge/sdk/next';
function useTracker(): BrowserTracker;Errors
Section titled “Errors”Throws synchronously if called outside a <TrackbridgeProvider>:
Error: useTracker must be called inside <TrackbridgeProvider>This is a programming error — no fallback, no warning.
Example
Section titled “Example”'use client';import { useTracker } from '@trackbridge/sdk/next';
export function CheckoutButton({ cart }: { cart: Cart }) { const tracker = useTracker();
return ( <button onClick={async () => { await tracker.trackBeginCheckout({ transactionId: cart.id, value: cart.total, currency: cart.currency, items: cart.items, }); router.push('/checkout'); }} > Checkout </button> );}For a long-lived module reference (e.g., calling the tracker from outside React), prefer the explicit createBrowserTracker pattern in a lib/tracker.client.ts module rather than reaching for the hook from non-component code.
See also
Section titled “See also”<TrackbridgeProvider>— required ancestor.createBrowserTracker()— fullBrowserTrackersurface.