Source: https://usedataowl.com/docs/paddle-checkout-api
Markdown source: https://usedataowl.com/docs/paddle-checkout-api.md
Description: Pass visitor and session identifiers into Paddle transaction custom_data to measure exact SaaS revenue and customers by traffic source.

# Attribute SaaS Revenue with the Paddle Checkout & Billing API

> Make sure you've [connected your Paddle account](/docs/connect-payment-provider) first.

Pass `datasense_visitor_id` and `datasense_session_id` (the `datasense_vid` and `datasense_sid` cookies the script sets) as `custom_data` when you create the checkout:

```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 response = await fetch("https://api.paddle.com/transactions", {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.PADDLE_API_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ items: [{ price_id: priceId, quantity: 1 }], custom_data: visit }),
  })
  return Response.json(await response.json())
}
```

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.

On the cookieless script there's no cookie to read on the server: send `window.datasense.sessionId()` from the browser with the checkout request, as in this variant:

```js title="app/api/checkout/route.js"
export async function POST(request) {
  // The cookieless script keeps the session in the tab: send it from the
  // browser with the checkout request, as { sessionId: window.datasense?.sessionId?.() }
  const { sessionId } = await request.json()
  const visit = { datasense_session_id: sessionId }

  // …the rest as above
}
```
