Source: https://usedataowl.com/docs/dodopayments
Markdown source: https://usedataowl.com/docs/dodopayments.md
Description: Connect Dodo Payments via API key and checkout metadata to see realtime revenue by traffic source, country, and landing page.

# How to Attribute Revenue with Dodo Payments & DataOwl

> Make sure you've [connected your Dodo Payments account](/docs/connect-payment-provider) 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:

```js title="app/api/checkout/route.js"
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](/docs/stripe-other-methods)).

Once the provider is connected and the metadata is passed, DataOwl 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.
