Revenue attribution
Attribute Polar checkouts created on your server
Read the supr_visitor_id cookie when your server creates a Polar checkout and pass it as metadata, with examples for Node.js, Next.js and Python.
When your server creates the checkout, read the supr_visitor_id cookie from the request and pass it as metadata:
import { Polar } from "@polar-sh/sdk";
const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN });
app.post("/checkout", async (req, res) => {
const checkout = await polar.checkouts.create({
products: ["<product id>"],
successUrl: "https://yourdomain.com/thanks",
metadata: {
supr_visitor_id: req.cookies.supr_visitor_id,
supr_session_id: req.cookies.supr_session_id,
},
});
res.redirect(303, checkout.url);
});// app/api/checkout/route.ts
import { cookies } from "next/headers";
import { Polar } from "@polar-sh/sdk";
const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN! });
export async function POST() {
const jar = await cookies();
const checkout = await polar.checkouts.create({
products: ["<product id>"],
successUrl: "https://yourdomain.com/thanks",
metadata: {
supr_visitor_id: jar.get("supr_visitor_id")?.value ?? "",
supr_session_id: jar.get("supr_session_id")?.value ?? "",
},
});
return Response.redirect(checkout.url, 303);
}from polar_sdk import Polar
polar = Polar(access_token=os.environ["POLAR_ACCESS_TOKEN"])
checkout = polar.checkouts.create(request={
"products": ["<product id>"],
"success_url": "https://yourdomain.com/thanks",
"metadata": {
"supr_visitor_id": request.cookies.get("supr_visitor_id", ""),
"supr_session_id": request.cookies.get("supr_session_id", ""),
},
})supr_session_id is optional: it credits the payment to that exact visit. SuprAnalytics also reads visitor_id from metadata, and the metadata of the customer and the subscription, so renewals keep their attribution.
AI agent or LLM? Read this page as Markdown