Revenue attribution with Polar
Polar copies checkout metadata to the resulting orders. Add the visitor id when you create the checkout.
1. Add the metadata
With @polar-sh/sdk
import { cookies } from "next/headers";
import { Polar } from "@polar-sh/sdk";
const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN! });
const visitorId = (await cookies()).get("dataeasy_visitor_id")?.value;
const checkout = await polar.checkouts.create({
products: ["PRODUCT_ID"],
successUrl: "https://yourdomain.com/thanks",
metadata: visitorId ? { dataeasy_visitor_id: visitorId } : {},
});DataEasy also looks at the customer metadata, so setting dataeasy_visitor_id on the Polar customer works too.
2. Connect the webhook
- In DataEasy, open Website settings → Revenue and pick Polar.
- Copy the webhook endpoint shown there. It looks like
https://dataeasy.app/api/integrations/polar/webhook/<website id>. - In your Polar dashboard, create a webhook pointing to that URL and subscribe it to:
order.paid,order.refunded. - Paste the webhook signing secret back in DataEasy and save.
Polar webhooks follow the Standard Webhooks spec (webhook-id, webhook-timestamp, webhook-signature); DataEasy verifies them with your signing secret.