The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add Stripe
Kiran Kb05cdaea54de
diff --git a/apps/web/integration-guides/stripe-checkout.md b/apps/web/integration-guides/stripe-checkout.mdnew file mode 100644index 0000000000..3c71736c76--- /dev/null+++ b/apps/web/integration-guides/stripe-checkout.md@@ -0,0 +1,34 @@+If you have a custom checkout flow that uses Stripe's `checkout.sessions.create` API, you'd want to associate the [Stripe customer object](https://docs.stripe.com/api/customers/object) with the user's unique ID in your database.++This will allow Dub to automatically listen for purchase events from Stripe and associate them with the original click event (and by extension, the link that the user came from).++Under the hood, Dub records the user as a customer and associates them with the click event that they came from.++Then, when the user makes a purchase, Dub will automatically associate the checkout session details (invoice amount, currency, etc.) with the customer – and by extension, the original click event.++Then, when you [create a checkout session](https://docs.stripe.com/api/checkout/sessions/create), pass your customer's unique user ID in your database as the `dubCustomerId` value in the `metadata` field.++```javascript+import { stripe } from "@/lib/stripe";++const user = {+ id: "user_123",+ email: "[email protected]",+ teamId: "team_xxxxxxxxx",+};++const priceId = "price_xxxxxxxxx";++const stripeSession = await stripe.checkout.sessions.create({+ customer_email: user.email,+ success_url: "https://app.domain.com/success",+ line_items: [{ price: priceId, quantity: 1 }],+ mode: "subscription",+ client_reference_id: user.teamId,+ metadata: {+ dubCustomerId: user.id, // the unique user ID of the customer in your database+ },+});+```++This way, when the customer completes their checkout session, Dub will automatically associate the checkout session details (invoice amount, currency, etc.) with the customer – and by extension, the original click event.diff --git a/apps/web/integration-guides/stripe-customers.md b/apps/web/integration-guides/stripe-customers.mdnew file mode 100644index 0000000000..4a0795e590--- /dev/null+++ b/apps/web/integration-guides/stripe-customers.md@@ -0,0 +1,47 @@+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](https://docs.stripe.com/api/customers/create).++When you [create a Stripe customer](https://docs.stripe.com/api/customers/create), pass the user's unique user ID in your database as the `dubCustomerId` value in the `metadata` field.++```javascript+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: {+ dubCustomerId: user.id,+ dubClickId: dub_id,+ },+});+```++Alternatively, you can also pass the `dubCustomerId` and `dubClickId` values in the `metadata` field of the [Stripe customer update flow](https://docs.stripe.com/api/customers/update):++```javascript+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: {+ dubCustomerId: 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.diff --git a/apps/web/integration-guides/stripe-payment-links.md b/apps/web/integration-guides/stripe-payment-links.mdnew file mode 100644index 0000000000..86ef82b38e--- /dev/null+++ b/apps/web/integration-guides/stripe-payment-links.md@@ -0,0 +1,34 @@+If you're using [Stripe Payment Links](https://docs.stripe.com/payment-links), simply add a `?dub_client_reference_id=1` query parameter to your Stripe Payment Link when shortening it on Dub.++Then, when a user clicks on the shortened link, Dub will automatically append the unique click ID as the `client_reference_id` [query parameter](https://docs.stripe.com/payment-links/url-parameters) to the payment link.++++Finally, when the user completes the checkout flow, Dub will automatically track the sale event and update the customer's `externalId` with their Stripe customer ID for future reference.++Alternatively, if you have a marketing site that you're redirecting your users to first, you can do this instead:++1. [Install the @dub/analytics client-side SDK](/sdks/client-side/introduction), which automatically detects the `dub_id` in the URL and stores it as a first-party cookie on your site.+2. Then, retrieve and append the `dub_id` value as the `client_reference_id` parameter to the payment links on your pricing page / CTA button (prefixed with `dub_id_`).++```javascript+https://buy.stripe.com/xxxxxx?client_reference_id=dub_id_xxxxxxxxxxxxxx+```++## What if I'm using Stripe Pricing Tables?++If you're using [Stripe Pricing Tables](https://docs.stripe.com/payments/checkout/pricing-table) – you'd want to pass the Dub click ID as a [`client-reference-id` attribute](https://docs.stripe.com/payments/checkout/pricing-table#handle-fulfillment-with-the-stripe-api) instead:++```html+<body>+ <h1>We offer plans that help any business!</h1>+ <!-- Paste your embed code script here. -->+ <script async src="https://js.stripe.com/v3/pricing-table.js"></script>+ <stripe-pricing-table+ pricing-table-id="{{PRICING_TABLE_ID}}"+ publishable-key="pk_test_51ODHJvFacAXKeDpJsgWLQJSzBIDtCUFN6MoB4IIXKJDfWdFmiEO4JuvAU1A0Y2Ri4m4q1egIfwYy3s72cUBRCwXC00GQhEZuXa"+ client-reference-id="dub_id_xxxxxxxxxxxxxx"+ >+ </stripe-pricing-table>+</body>+```\ No newline at end of filediff --git a/apps/web/ui/guides/guide-list.tsx b/apps/web/ui/guides/guide-list.tsxindex 18460acd34..cb8cfc67d0 100644--- a/apps/web/ui/guides/guide-list.tsx+++ b/apps/web/ui/guides/guide-list.tsx@@ -120,8 +120,17 @@ export function GuideList({ showConnectLaterButton = true }: GuideListProps) {<div className="flex h-16 w-full items-center justify-center"><guide.icon className="size-10" /></div>- <div className="w-full text-sm font-semibold leading-5 text-neutral-900">- {guide.title}++ <div>+ <div className="w-full text-sm font-semibold leading-5 text-neutral-900">+ {guide.title}+ </div>++ {guide.description && (+ <div className="w-full text-sm font-medium leading-5 text-neutral-500">+ {guide.description}+ </div>+ )}</div></Link>))}diff --git a/apps/web/ui/guides/integrations.ts b/apps/web/ui/guides/integrations.tsindex 246aa36b6a..4a637ca715 100644--- a/apps/web/ui/guides/integrations.ts+++ b/apps/web/ui/guides/integrations.ts@@ -171,7 +171,7 @@ export const guides: IntegrationGuide[] = [},{type: "track-sales",- key: "stripe",+ key: "stripe-customers",title: "Stripe",description: "Customers",icon: Stripe,