Revenue attribution guide

If you're using Stripe, LemonSqueezy, or Polar, you don't need to use this endpoint. We automatically track payments if you have connected your payment provider.

Attribute revenue with custom payment providers

Use DataFast's Payment API to create payments and attribute revenue to your traffic sources.

How it works

When you receive a successful payment, make an API call to DataFast's Payment API. That's it!

// Send payment data to DataFast's API
await fetch('https://datafa.st/api/v1/payments', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${DATAFAST_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    amount: 29.99,
    currency: 'USD',
    transaction_id: 'txn_98hj',
    datafast_visitor_id: '3cff4252-fa96-4gec-8b1b-bs695e763b65', // available in the cookie, like request.cookies.datafast_visitor_id
  }),
});

You'll need an API key for your website.

Here's a recommended flow:

  1. Capture DataFast's visitor ID, a unique identifier for each visitor, from the cookie datafast_visitor_id. Store it in your database or pass it to your payment provider when creating checkout sessions (metadata).
  2. Send payment data to DataFast using our Payment API when you receive a successful payment (your webhook handler, a success page, etc.)

For more details, see the Payment API documentation.

Example: DodoPayments integration

1. Add visitor ID to checkout metadata

// Your existing checkout flow (backend)
const datafastVisitorId = cookies().get('datafast_visitor_id')?.value;

const payment = await dodopayments.payments.create({
  // ... existing config
  metadata: {
    datafast_visitor_id: datafastVisitorId, // DataFast's visitor ID
  },
});

2. Call DataFast's Payment API in your webhook handler

// Your existing 'payment.succeeded' webhook handler
if (paymentData.metadata?.datafast_visitor_id) {
  await fetch('https://datafa.st/api/v1/payments', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${DATAFAST_API_KEY}` },
    body: JSON.stringify({
      amount: paymentData.total_amount / 100,
      currency: paymentData.currency,
      transaction_id: paymentData.payment_id,
      datafast_visitor_id: paymentData.metadata.datafast_visitor_id,
    }),
  });
}

After implementing this setup, you should see revenue data in your DataFast dashboard with full attribution to marketing channels. If you need help, contact us at marc@datafa.st.

Something missing? Suggest features ✍️