Attribute revenue with Dodo Payments
Connect Dodo Payments with an API key and pass the Datasense visit as checkout metadata.
Make sure you've connected your Dodo Payments account first. Connecting adds the webhook for you: no endpoint to set up in Dodo's dashboard.
Checkout sessions
Pass the visit as metadata when you create the checkout session:
import { cookies } from "next/headers"
export async function POST() {
const cookieStore = await cookies()
const visit = {
datasense_visitor_id: cookieStore.get("datasense_vid")?.value,
datasense_session_id: cookieStore.get("datasense_sid")?.value,
}
const session = await dodo.checkoutSessions.create({
product_cart: [{ product_id: productId, quantity: 1 }],
return_url: "https://example.com/thanks",
metadata: visit,
})
return Response.json({ url: session.checkout_url })
}Payment links
Nothing to do: the script adds the visit to every checkout.dodopayments.com/buy/… link on your pages (as metadata_datasense_session_id). As a backup, set the link's return URL to a page on your site: Dodo adds ?payment_id=… (or ?subscription_id=…), and the script ties that payment to the visit.
Other checkouts
On your success page, call datasense("payment", { email }) (how).
Once the provider is connected and the metadata is passed, Datasense attributes revenue to the right channels on its own. No webhook code needed.
After a successful payment, you'll see it on the dashboard with its source, campaign, landing page, country and device.