Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

1.4 KB
Raw Blame

Alternatively, if you don't use Stripe's checkout session creation flow, you can also pass the user ID and the click event ID (dub_id) in the Stripe customer creation flow.

When you create a Stripe customer, pass the user's unique user ID in your database as the dubCustomerExternalId value in the metadata field.

import { stripe } from "@/lib/stripe";

const user = {
  id: "user_123",
  email: "[email protected]",
  teamId: "team_xxxxxxxxx",
};

const dub_id = req.headers.get("dub_id");

await stripe.customers.create({
  email: user.email,
  name: user.name,
  metadata: {
    dubCustomerExternalId: user.id,
    dubClickId: dub_id,
  },
});

Alternatively, you can also pass the dubCustomerExternalId and dubClickId values in the metadata field of the Stripe customer update flow:

import { stripe } from "@/lib/stripe";

const user = {
  id: "user_123",
  email: "[email protected]",
  teamId: "team_xxxxxxxxx",
};

const dub_id = req.headers.get("dub_id");

await stripe.customers.update(user.id, {
  metadata: {
    dubCustomerExternalId: user.id,
    dubClickId: dub_id,
  },
});

This way, when the customer makes a purchase, Dub will automatically associate the purchase details (invoice amount, currency, etc.) with the original click event.