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.

Update GTM guides for client SDK, lead tracking, and sale tracking

Kiran Kbff7f47f6948
diff --git a/apps/web/guides/gtm-client-sdk.md b/apps/web/guides/gtm-client-sdk.md
index d06e385bb6..8c54552527 100644
--- a/apps/web/guides/gtm-client-sdk.md
+++ b/apps/web/guides/gtm-client-sdk.md
@@ -39,7 +39,7 @@ If you’re using [Dub Partners](https://dub.co/docs/partners/quickstart) for af
</script>
```
-Read the [client-side click-tracking guide](/sdks/client-side/features/client-side-click-tracking) for more information.
+Read the [client-side click-tracking guide](https://dub.co/docs/sdks/client-side/features/client-side-click-tracking) for more information.
## Step 3: Configure the Trigger
diff --git a/apps/web/guides/gtm-track-lead.md b/apps/web/guides/gtm-track-lead.md
index 3a0d40f38c..076b896515 100644
--- a/apps/web/guides/gtm-track-lead.md
+++ b/apps/web/guides/gtm-track-lead.md
@@ -1,120 +1,104 @@
-Configure Google Tag Manager server-side tracking
+Configure Google Tag Manager for lead tracking
-To track lead 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.
+The following steps assume that you've already installed the Dub Analytics script through GTM.
-## Step 1: Set up GTM Server Container
+## Step 1: Create a GTM Variable to Read the dub_id Cookie
-In Google Tag Manager, you'll need to use an existing server container or [create a new one](https://youtu.be/waqBSk3vkko). Server containers are the foundation for server-side tracking and allow you to process events before they reach their final destinations.
+To read the `dub_id` cookie that Dub Analytics sets, you'll need to create a new **User-Defined Variable** in Google Tag Manager.
-- If you already have a server container set up, you can use that
-- If not, [create a new server container in your GTM workspace](https://developers.google.com/tag-platform/learn/sst-fundamentals/4-sst-setup-container)
+In your GTM workspace, navigate to the **Variables** section and click **New** to create a new variable.
-## Step 2: Import Dub GTM Server Client Template
+Configure the variable with the following settings:
-Inside your GTM server container, navigate to the **Templates** tab. Under **Client Templates**, click the **New** button.
+- **Variable Type**: Select **1st Party Cookie**
+- **Cookie Name**: `dub_id`
+- **Variable Name**: Name it "Dub ID Cookie"
-![GTM New Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-client-template.png)
+Click **Save** to create the variable.
-This will open up the **Template Editor**. In the top right corner, click on the **⋮** button and select **Import**.
+## Step 2: Create Lead Tracking Tag for Form Submissions
-![GTM Import Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-import-client-template.png)
+Next, create a tag to track leads when users submit forms on your website.
-Download the [gtm-server-client-template/template.tpl](https://raw.githubusercontent.com/dubinc/gtm-server-client-template/main/template.tpl) file and upload it to the Template Editor. You'll see a preview of the template:
+Create another **Custom HTML** tag with the following code:
-![GTM Server Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-server-client-template.png)
+```html
+<script>
+ (function () {
+ // Get form data - customize these selectors based on your form
+ var name = document.getElementById("name")
+ ? document.getElementById("name").value
+ : "";
+ var email = document.getElementById("email")
+ ? document.getElementById("email").value
+ : "";
-Click the **Save** button in the top right to save the template.
-
-## Step 3: Create Dub Server Client
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-server-client.png)
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-choose-client-type.png)
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-server-client.png)
-
-> 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.
-
-## Step 4: Import Dub GTM Server Tag Template
-
-Next, you'll want to import the Dub GTM Server Tag template to handle lead tracking.
-
-In your GTM server container, navigate to the **Templates** tab once again. Under **Tag Templates**, click the **New** button.
-
-![GTM New Tag Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-tag-template.png)
-
-This will open up the **Template Editor**. In the top right corner, click on the **⋮** button and select **Import**.
-
-![GTM Import Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-import-client-template.png)
-
-Download the [gtm-server-tag-template/template.tpl](https://raw.githubusercontent.com/dubinc/gtm-server-tag-template/main/template.tpl) file and upload it to the Template Editor. You'll see a preview of the template:
-
-![Dub GTM Server Tag Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-server-tag-template.png)
-
-Click the **Save** button in the top right to save the template.
-
-## Step 5: Add Lead 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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-tag.png)
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-choose-tag-type.png)
-
-Make sure your tag configuration is set to the following:
+ if (email) {
+ // Track the lead event
+ dubAnalytics.trackLead({
+ eventName: "Sign Up",
+ customerExternalId: email,
+ customerName: name || undefined,
+ customerEmail: email,
+ clickId: {{Dub ID Cookie}} || undefined,
+ });
+ }
+ })();
+</script>
+```
-- **Dub API Key**: Your [Dub API key](https://dub.co/docs/api-reference/tokens) (starts with `dub_`)
-- **Event**: Select "Track lead" from the dropdown
-- **Click ID**: `clickId` from the Dub Server Client event data
-- **Customer External ID**: `customerExternalId` from the event data
-- **Event Name**: `eventName` from the event data (e.g., "Sign Up")
-- **Customer Name**: `customerName` from the event data
-- **Customer Email**: Map to the `customerEmail` from the event data
-- **Customer Avatar**: Map to the `customerAvatar` from the event data (optional)
-- **Event Quantity**: Map to the `eventQuantity` from the event data (default: 1)
+Configure this tag to fire on **Form Submission** by creating a new trigger:
+
+- Trigger Type: **Form Submission**
+- This trigger fires on: **Some Forms** (or **All Forms** if you want to track all form submissions)
+- Add conditions to specify which forms should trigger lead tracking
+
+Name this tag "Dub Lead Tracking - Form Submission" and click **Save** to create the tag.
+
+### Step 3: Create Lead Tracking Tag for Thank You Pages
+
+For tracking leads on thank-you pages (recommended approach), create another **Custom HTML** tag:
+
+```html
+<script>
+ (function () {
+ // Get query parameters from URL
+ var params = new URLSearchParams(window.location.search);
+ var email = params.get("email");
+ var name = params.get("name");
+
+ // Only track if email is present
+ if (email) {
+ // Track the lead event
+ dubAnalytics.trackLead({
+ eventName: "Sign Up",
+ customerExternalId: email,
+ customerName: name || undefined,
+ customerEmail: email,
+ clickId: {{Dub ID Cookie}} || undefined,
+ });
+ }
+ })();
+</script>
+```
-![GTM Lead Tracking Tag](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-track-lead-tag.png)
+Configure this tag to fire on specific pages by creating a **Page View** trigger with conditions:
-Under the **Triggering** section, configure when the tag should fire:
+- Trigger Type: **Page View**
+- This trigger fires on: **Some Page Views**
+- Add conditions like:
+ - **Page URL** contains `/thank-you`
+ - Or **Page Path** equals `/success`
+ - Or whatever URL pattern matches your thank-you pages
-- 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 lead events:
- - **Variable**: Select a variable that contains the event type
- - **Operator**: Equals
- - **Value**: "Sign Up"
-- Name the trigger "Dub Lead Event Trigger" and save it
+Name this tag "Dub Lead Tracking - Thank You Page" 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:
-
-```bash
-curl "https://server-side-tagging-xxx-uc.a.run.app/dub/track/lead?\
-dub_id=pAzVZ3jzwZXcLMDT&\
-eventName=Sign%20Up&\
-customerExternalId=user_1K0RN3SDNAC0C1WCW4BGRS3EW&\
-customerName=John%20Doe&\
-customerAvatar=https://example.com/avatar.jpg&\
-eventQuantity=1&\
-mode=async"
-```
+To test your GTM setup, you can use the **Preview** mode in Google Tag Manager:
+
+1. **Enable Preview Mode**: In your GTM workspace, click the **Preview** button in the top right corner
+2. **Enter your website URL** and click **Connect**
+3. **Navigate to a page** with a form or your thank-you page
+4. **Submit a test form** or visit the thank-you page with query parameters
+5. **Check the GTM debugger** to see if your tags are firing correctly
diff --git a/apps/web/guides/gtm-track-sale.md b/apps/web/guides/gtm-track-sale.md
index 4dce6ecdda..5f5a875bb9 100644
--- a/apps/web/guides/gtm-track-sale.md
+++ b/apps/web/guides/gtm-track-sale.md
@@ -1,122 +1,105 @@
-Configure Google Tag Manager server-side tracking
-
-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.
-
-## Step 1: Set up GTM Server Container
-
-In Google Tag Manager, you'll need to use an existing server container or [create a new one](https://youtu.be/waqBSk3vkko). Server containers are the foundation for server-side tracking and allow you to process events before they reach their final destinations.
-
-- If you already have a server container set up, you can use that
-- If not, [create a new server container in your GTM workspace](https://developers.google.com/tag-platform/learn/sst-fundamentals/4-sst-setup-container)
-
-## Step 2: Import Dub GTM Server Client Template
-
-Inside your GTM server container, navigate to the **Templates** tab. Under **Client Templates**, click the **New** button.
-
-![GTM New Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-client-template.png)
-
-This will open up the **Template Editor**. In the top right corner, click on the **⋮** button and select **Import**.
-
-![GTM Import Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-import-client-template.png)
-
-Download the [gtm-server-client-template/template.tpl](https://github.com/dubinc/gtm-server-client-template/blob/main/template.tpl) file and upload it to the Template Editor. You'll see a preview of the template:
-
-![GTM Server Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-server-client-template.png)
-
-Click the **Save** button in the top right to save the template.
-
-## Step 3: Create Dub Server Client
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-server-client.png)
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-choose-client-type.png)
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-server-client.png)
-
-> 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.
-
-## Step 4: Import Dub GTM Server Tag Template
-
-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](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-tag-template.png)
-
-This will open up the **Template Editor**. In the top right corner, click on the **⋮** button and select **Import**.
-
-![GTM Import Client Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-import-client-template.png)
-
-Download the [gtm-server-tag-template/template.tpl](https://github.com/dubinc/gtm-server-tag-template/blob/main/template.tpl) file and upload it to the Template Editor. You'll see a preview of the template:
-
-![Dub GTM Server Tag Template](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-server-tag-template.png)
-
-Click the **Save** button in the top right to save the template.
-
-## Step 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**.
+Configure Google Tag Manager for sale tracking
+
+The following steps assume that you've already installed the Dub Analytics script through GTM.
+
+## Step 1: Create Sales Tracking Tag for Checkout Forms
+
+Next, create a tag to track sales when users complete checkout forms on your website.
+
+Create another **Custom HTML** tag with the following code:
+
+```html
+<script>
+ (function () {
+ // Get checkout data - customize these selectors based on your form
+ var customerId = document.getElementById("customer_id")
+ ? document.getElementById("customer_id").value
+ : "";
+ var amount = document.getElementById("amount")
+ ? document.getElementById("amount").value
+ : "";
+ var invoiceId = document.getElementById("invoice_id")
+ ? document.getElementById("invoice_id").value
+ : "";
+
+ // Only track if customer ID and amount are present
+ if (customerId && amount) {
+ // Track the sale event
+ dubAnalytics.trackSale({
+ eventName: "Purchase",
+ customerExternalId: customerId,
+ amount: parseInt(amount), // Amount in cents
+ invoiceId: invoiceId || undefined,
+ currency: "usd", // Customize as needed
+ paymentProcessor: "stripe", // Customize as needed
+ });
+ }
+ })();
+</script>
+```
-![GTM New Tag](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-new-tag.png)
+Configure this tag to fire on **Form Submission** by creating a new trigger:
+
+- Trigger Type: **Form Submission**
+- This trigger fires on: **Some Forms** (or **All Forms** if you want to track all form submissions)
+- Add conditions to specify which forms should trigger sales tracking (e.g., checkout forms)
+
+Name this tag "Dub Sales Tracking - Checkout Form" and save it.
+
+### Step 2: Create Sales Tracking Tag for Order Confirmation Pages
+
+For tracking sales on order confirmation pages (recommended approach), create another **Custom HTML** tag:
+
+```html
+<script>
+ (function () {
+ // Get query parameters from URL
+ var params = new URLSearchParams(window.location.search);
+ var customerId = params.get("customer_id");
+ var amount = params.get("amount");
+ var invoiceId = params.get("invoice_id");
+
+ // Only track if customer ID and amount are present
+ if (customerId && amount) {
+ // Track the sale event
+ dubAnalytics.trackSale({
+ eventName: "Purchase",
+ customerExternalId: customerId,
+ amount: parseInt(amount), // Amount in cents
+ invoiceId: invoiceId || undefined,
+ currency: "usd", // Customize as needed
+ paymentProcessor: "stripe", // Customize as needed
+ });
+ }
+ })();
+</script>
+```
-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.
+Configure this tag to fire on specific pages by creating a **Page View** trigger with conditions:
-![GTM Choose Tag Type](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-choose-tag-type.png)
+- Trigger Type: **Page View**
+- This trigger fires on: **Some Page Views**
+- Add conditions like:
+ - **Page URL** contains `/order-confirmation`
+ - Or **Page Path** equals `/checkout/success`
+ - Or whatever URL pattern matches your order confirmation pages
-Make sure your tag configuration is set to the following:
+Name this tag "Dub Sales Tracking - Order Confirmation" and save it.
-- **Dub API Key**: Your [Dub API key](https://dub.co/docs/api-reference/tokens) (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)
+## Testing your setup
-![GTM Sales Tracking Tag](https://mintlify.s3.us-west-1.amazonaws.com/dub/images/conversions/google-tag-manager/gtm-track-sale-tag.png)
+To test your GTM setup, you can use the **Preview** mode in Google Tag Manager:
-Under the **Triggering** section, configure when the tag should fire:
+1. **Enable Preview Mode**: In your GTM workspace, click the **Preview** button in the top right corner
+2. **Enter your website URL** and click **Connect**
+3. **Navigate to a checkout page** or your order confirmation page
+4. **Complete a test purchase** or visit the confirmation page with query parameters
+5. **Check the GTM debugger** to see if your tags are firing correctly
-- 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
+## Verify sales tracking
-## Testing your setup
+You can also verify that sales are being tracked by:
-You can test your GTM server setup by sending a curl request to your server URL with the appropriate query parameters:
-
-```bash
-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"
-```
+1. **Checking your browser's developer console** for any JavaScript errors
+2. **Using the Network tab** to see if requests are being sent to Dub's analytics endpoint
+3. **Viewing your Dub dashboard** to confirm that sale events are appearing in your analytics