Conversion tracking require a Business plan subscription or higher.
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)
In this guide, we will be focusing on tracking sales events for a SaaS application that uses Google Tag Manager to track conversions.

Prerequisites

Before you get started, make sure you follow the Dub Conversions quickstart guide to get Dub Conversions set up for your links:
  1. Enable conversion tracking for your links
  2. Install the @dub/analytics client-side SDK via GTM

Configure Google Tag Manager server-side tracking

If you’ve already set up the Dub GTM Server Client and Tag for lead tracking, you can skip ahead to step 5.
To track sales conversion events with Google Tag Manager, you’ll need to set up a server container and configure a custom client to handle Dub conversion events.

1. Set up GTM Server Container

If you’ve already set up the Dub GTM Server Client and Tag for lead tracking, you can skip this step.
In Google Tag Manager, you’ll need to use an existing server container or create a new one. Server containers are the foundation for server-side tracking and allow you to process events before they reach their final destinations.

2. Import Dub GTM Server Client Template

If you’ve already set up the Dub GTM Server Client and Tag for lead tracking, you can skip this step.
Inside your GTM server container, navigate to the Templates tab. Under Client Templates, click the New button.
GTM New Client Template
This will open up the Template Editor. In the top right corner, click on the button and select Import.
GTM Import Client Template
Download the gtm-server-client-template/template.tpl file and upload it to the Template Editor. You’ll see a preview of the template:
GTM Server Client Template
Click the Save button in the top right to save the template.

3. Create Dub Server Client

If you’ve already set up the Dub GTM Server Client and Tag for lead tracking, you can skip this step.
Next, you’d want to create a new GTM Server Client using the imported template. In your GTM server container, navigate to the Clients tab and click New.
GTM New Server Client
This will open up the client configuration page, where you can choose a client type to begin setup. Under Custom, select the Dub GTM Server Client template that you created in step 2.
GTM Choose Client Type
Make sure your client configuration is set to the following:
  • Client Name: Dub GTM Server Client
  • Priority: 0
  • Request Path: /dub/track
  • Debug Logging: (optional)
GTM Server Client
Clients in GTM Server are adapters that act as bridges between the software running on a user’s device and your server container. They receive requests and transform them into events that can be processed by tags.

4. Import Dub GTM Server Tag Template

If you’ve already set up the Dub GTM Server Client and Tag for lead tracking, you can skip this step.
Next, you’ll want to import the Dub GTM Server Tag template to handle sales tracking. In your GTM server container, navigate to the Templates tab once again. Under Tag Templates, click the New button.
GTM New Tag Template
This will open up the Template Editor. In the top right corner, click on the button and select Import.
GTM Import Client Template
Download the gtm-server-tag-template/template.tpl file and upload it to the Template Editor. You’ll see a preview of the template:
Dub GTM Server Tag Template
Click the Save button in the top right to save the template.

5. Add Sales Tracking Tag

Last but not least, you’ll want to create a new GTM Server Tag using the imported template. In your GTM server container, navigate to the Tags tab and click New.
GTM New Tag
This will open up the tag configuration page. Under Tag Configuration, select the Dub Conversion Tag server tag template that you created in step 4.
GTM Choose Tag Type
Make sure your tag configuration is set to the following:
  • Dub API Key: Your Dub API key (starts with dub_)
  • Event: Select “Track sale” from the dropdown
  • Customer External ID: customerExternalId from the event data
  • Amount: amount from the event data (in cents)
  • Currency: currency from the event data (e.g., “usd”)
  • Event Name: eventName from the event data (e.g., “Purchase”)
  • Payment Processor: paymentProcessor from the event data (e.g., “stripe”)
  • Invoice ID: Map to the invoiceId from the event data (optional)
  • Lead Event Name: Map to the leadEventName from the event data (optional)
  • Metadata: Map to the metadata from the event data (optional)
GTM Sales Tracking Tag
Under the Triggering section, configure when the tag should fire:
  • Click + to add a new trigger
  • Select Custom Event as the trigger type
  • Set the Event Name to match the event name from the Dub Server Client. Default is dub_conversion
  • Add a condition to filter for sales events:
    • Variable: Select a variable that contains the event type
    • Operator: Equals
    • Value: “Purchase”
  • Name the trigger “Dub Sales Event Trigger” and save it

Testing your setup

You can test your GTM server setup by sending a curl request to your server URL with the appropriate query parameters:
curl "https://server-side-tagging-xxx-uc.a.run.app/dub/track/sale?\
dub_id=pAzVZ3jzwZXcLMDT&\
customerExternalId=user_1K0RN3SDNAC0C1WCW4BGRS3EW&\
amount=1000&\
currency=usd&\
eventName=Purchase&\
paymentProcessor=stripe&\
invoiceId=inv_123456789&\
leadEventName=Sign%20Up&\
mode=async"

Download GTM templates

To learn more about how to track sales with Google Tag Manager, check out the following templates:

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 line chart
  • Funnel chart: A funnel chart view visualizing the conversion & dropoff rates across the different steps in the conversion funnel (clicks → leads → sales).
Funnel chart view showing the conversion & dropoff rates from 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.
The Events Stream dashboard on Dub