How to set up Meta CAPI in Next.js without GTM
Skip Google Tag Manager. Wire first-party Meta CAPI in Next.js with an SDK that handles hashing, deduplication, retries, and delivery logs from your existing app code.
- Meta CAPI
- Next.js
- GTM
- quickstart
Problem: Meta CAPI documentation assumes GTM Server-Side or a custom PHP backend. You run Next.js App Router and want events colocated with the code that fires them — not mapped in a tag manager UI.
Why GTM frustrates Next.js teams
GTM was built for marketers injecting scripts without engineering. In App Router, it fights the component model, loads extra JavaScript, and creates a debugging black box.
Server-Side GTM adds containers and variable mapping disconnected from your TypeScript types.
Install and init
Add the SDK, wrap your layout with the provider, and configure Meta pixel ID and access token in the TrackStack dashboard — not in client env vars for secrets.
Follow quickstart for keys, domain allowlist, and first test event.
import { TrackStackProvider, TrackStackPageview } from "@trackstack/sdk";
import { trackstack } from "@/lib/trackstack";
export default function RootLayout({ children }) {
return (
<TrackStackProvider instance={trackstack}>
<TrackStackPageview />
{children}
</TrackStackProvider>
);
}Fire conversion events
Call capture() with canonical event names. The edge maps SignUp to Meta CompleteRegistration and Purchase to Purchase, hashing email automatically.
Always include eventId if you also run the Meta pixel.
trackstack.capture("SignUp", {
email: user.email,
eventId: `signup_${user.id}`,
});
trackstack.capture("Purchase", {
email: session.customer_email,
value: session.amount_total / 100,
currency: session.currency,
transactionId: session.id,
eventId: `purchase_${session.id}`,
});Verify in delivery logs
Open Logs after your first test event. Confirm HTTP 200 from Meta and inspect Event Match Quality indicators.
GTM sends events into a void. An SDK with logs tells you within seconds whether Meta accepted the conversion.
Stripe and webhooks
For purchases confirmed server-side, fire Purchase from the Stripe webhook handler with the same eventId you used client-side when possible. See examples for webhook patterns.
Sources
Official documentation and references cited in this article.
More in Guides
Google Enhanced Conversions for web apps
Enhanced Conversions improves Google's match rate by sending hashed first-party data with each conversion. This guide covers what to hash, where to fire events, and how to verify payloads land.
Read postLinkedIn and TikTok CAPI: a practical overview
Beyond Meta and Google, LinkedIn and TikTok have server-side conversion APIs with their own payload shapes and match keys. Here is what each expects and where teams get stuck.
Read postB2B vs DTC conversion tracking patterns
Pipeline SaaS and e-commerce shops share ad platforms but not conversion logic. Match keys, event timing, and what you optimize for differ — and your tracking setup should reflect that.
Read postReady to fix your conversion pipeline?
Install the TrackStack SDK, route events to Meta and Google, and verify delivery from one dashboard.