Stripe
Learn how to track a sale conversion event with Stripe
When it comes to conversion tracking, a sale
event happens when a user purchases your product or service. Examples include:
- Subscribing to a paid plan
- Usage expansion (upgrading from one plan to another)
- Purchasing a product
In this guide, we will be focusing on tracking sale events with Stripe as the payment processor by leveraging Dub’s Stripe integration.
Prerequisites
Before you get started, make sure you follow the Dub Conversions quickstart guide to get Dub Conversions set up for your links:
- Enable conversion tracking for your links
- Install the @dub/analytics client-side SDK
- Install the Dub server-side SDK
Then, depending on your authentication provider, follow the relevant guide to set up lead conversion tracking:
NextAuth.js
Tracking lead events with NextAuth.js
Clerk
Tracking lead events with Clerk
Supabase
Tracking lead events with Supabase
Auth0
Tracking lead events with Auth0
Appwrite
Tracking lead events with Appwrite
Alternatively, if your setup doesn’t involve an authentication step (e.g. for one-time purchases / if you’re using Stripe Payment Links), you can skip the server-side SDK step above and just pass the Dub click ID to the Stripe Checkout Flow (instructions below).
Step 1: Install the Dub Stripe integration
Find Dub on the Stripe App Marketplace
Navigate to the Dub: Conversions Analytics page on the Stripe App Marketplace.
Install the Stripe app
On the top right, click on Install app to install the Dub Conversions app on your Stripe account.
Alternatively, you can also install the Stripe app in test mode first to test your end-to-end flow without involving real money.
Once the app is installed, click on Continue to app settings to finish the installation.
Connect Stripe to your Dub workspace
In the app settings page, click on Connect workspace to connect your Stripe account with your Dub workspace.
This will redirect you to the Dub OAuth flow, where you can select the Dub workspace you want to connect to your Stripe account.
Once you click on Authorize, you will be redirected back to the Dub app settings page on Stripe, where you should see that the integration is now installed.
Dub’s Stripe integration will automatically forward the following events to Dub:
customer.created
: When a new customer is createdcheckout.session.completed
: When a customer completes a checkout sessioninvoice.paid
: When an invoice is paid (for tracking recurring subscriptions)
Step 2: Associate Stripe customer with your customer ID
Next, we’ll need to associate the Stripe customer object with the user ID in your database (which we tracked in the lead conversion tracking step).
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).
There are 3 ways to associate the Stripe customer object with the user ID in your database:
- Include your customer’s unique user ID in checkout sessions
- Pass the user ID and the click event ID in the Stripe customer creation flow
- Pass the Dub click ID to the Stripe Checkout Flow
Option 1: Include your customer’s unique user ID in checkout sessions
When you create checkout sessions for your users, pass your customer’s unique user ID in your database as the dubCustomerId
value in the metadata
field.
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.
Option 2: Pass the user ID and the click event ID in the Stripe customer creation flow
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:
This way, when the customer makes a purchase, Dub will automatically associate the purchase details (invoice amount, currency, etc.) with the original click event.
Option 3: Pass the Dub click ID to the Stripe Checkout Flow
If your setup doesn’t involve a lead event and goes straight to the Stripe checkout flow (e.g. for one-time purchases), you can simply pass the Dub click ID as the client_reference_id
parameter to enable conversion tracking with Dub.
When passing the Dub click ID as the client_reference_id
parameter to
Stripe, remember to prefix it with dub_id_
to allow Dub to detect the
conversion event.
-
For Stripe Payment Links – pass it as a query parameter:
-
For Stripe Pricing Tables – pass it as a
client-reference-id
attribute: -
For Stripe Checkout Sessions – pass it as the
client_reference_id
parameter:
Behind the scenes, Dub will automatically detect when the user completes the checkout flow and track the customer as a lead and the purchase event as a sale.
In this case, we will also update the customer’s externalId
with their Stripe customer ID for future reference.
Step 3: View conversion results
And that’s it – you’re all set! You can now sit back, relax, and watch your conversion revenue grow. We provide 3 different views to help you understand your conversions:
- Time-series: A time-series view of the number clicks, leads and sales.
- Funnel chart: A funnel chart view visualizing the conversion & dropoff rates across the different steps in the conversion funnel (clicks → leads → sales).
- Real-time events stream: A real-time events stream of every single conversion event that occurs across all your links in your workspace.
Currency support
For simplicity, Dub records all sales in the native currency of the Stripe account. For example, if you’re using USD for your Stripe account, Dub will record all sales in USD.
If you’re using Stripe’s Adaptive Pricing feature, Dub will still record the sale amount using the currency of your Stripe account:
Example Apps
Was this page helpful?