Track revenue using Stripe PaymentIntent API
1Setup the Checkout Session
Make sure that you've connected your Stripe account to Trackthemetric.
To ensure proper attribution with Stripe Elements and the PaymentIntent API, include ttm_visitor_id and ttm_session_id as metadata as metadata in your backend checkout session.
Here is an example setup:
// app/api/create-payment/route.ts
import { cookies } from 'next/headers';
// ---
// other code...
// ---
export async function POST() {
const reqCookies = await cookies(); // Use await in Next.js 15+
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: 'usd',
metadata: {
ttm_visitor_id: reqCookies.get("ttm_visitor_id")?.value ?? "",
ttm_session_id: reqCookies.get("ttm_session_id")?.value ?? "",
},
});
return new Response(JSON.stringify({ clientSecret: paymentIntent.client_secret }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
}
As soon as metadata is passed, TrackTheMetric automatically maps revenue to the right marketing channels. No extra webhook configuration is needed.
2Use this method if
You want to use Stripe Elements and the PaymentIntent API for fully custom checkout flows.