Stripe Checkout API
Pass attribu.tech cookies as metadata when creating Stripe Checkout sessions. This is the most common integration path for revenue attribution.
Make sure you've connected Stripe in your attribu.tech dashboard first. You need a restricted API key linked before payments can be attributed.
Next.js example
Read the attribu_visitor_id and attribu_session_id cookies on the server and pass them as metadata when creating the Checkout Session:
// app/api/checkout/route.ts
import { cookies } from "next/headers";
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(req: Request) {
const cookieStore = await cookies();
const session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [{ price: "price_xxx", quantity: 1 }],
success_url: "https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "https://yourdomain.com/",
metadata: {
attribu_visitor_id: cookieStore.get("attribu_visitor_id")?.value || "",
attribu_session_id: cookieStore.get("attribu_session_id")?.value || "",
},
});
return Response.json({ url: session.url });
}Node.js / Express example
If you're using Express or plain Node.js with cookie-parser:
// routes/checkout.js
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
app.post("/create-checkout", async (req, res) => {
const session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [{ price: "price_xxx", quantity: 1 }],
success_url: "https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "https://yourdomain.com/",
metadata: {
attribu_visitor_id: req.cookies.attribu_visitor_id || "",
attribu_session_id: req.cookies.attribu_session_id || "",
},
});
res.json({ url: session.url });
});The
metadata field must be on the Checkout Session itself, not on the line item or product. attribu.tech reads session-level metadata from the Stripe webhook.How it works
Once connected, attribu.tech automatically attributes revenue to the traffic source that brought the visitor. No webhook setup needed on your end -- attribu.tech handles that when you connect your Stripe key.
When to use
- Stripe Checkout -- the hosted payment page that Stripe manages for you
- Hosted payment pages -- any flow where you redirect to Stripe and back
If you use Stripe Elements or build a custom checkout form, see the PaymentIntent guide instead. If you use Stripe Payment Links, see the Payment Links guide.