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.

improve GTM guides

Steven Tey3a610d0b7783
diff --git a/apps/web/guides/gtm-track-lead.md b/apps/web/guides/gtm-track-lead.md
index 00740227bc..5a5a3e432e 100644
--- a/apps/web/guides/gtm-track-lead.md
+++ b/apps/web/guides/gtm-track-lead.md
@@ -16,82 +16,103 @@ Configure the variable with the following settings:
Click **Save** to create the variable.
-## Step 2: Create Lead Tracking Tag for Form Submissions
+## Step 2: Tracking lead events
-Next, create a tag to track leads when users submit forms on your website.
+There are two ways to track lead events with Google Tag Manager:
-Create another **Custom HTML** tag with the following code:
+- Thank You Page Tracking (Recommended)
+- Form Submission Tracking
+
+### Option 1: Thank You Page Tracking (Recommended)
+
+This method tracks leads when users land on a thank-you or success page after completing a form. This approach is more reliable as it's less likely to be blocked by ad blockers and provides better data accuracy.
+
+Create a **Custom HTML** tag with the following code:
```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
- : "";
+ // Get query parameters from URL
+ var params = new URLSearchParams(window.location.search);
+ var email = params.get("email");
+ var name = params.get("name");
+
+ // Get dub_id from cookie using GTM variable
+ var clickId = {{Dub ID Cookie}} || "";
- if (email) {
- // Track the lead event
+ // Only track the lead event if email and clickId are present
+ if (email && clickId) {
dubAnalytics.trackLead({
eventName: "Sign Up",
customerExternalId: email,
- customerName: name || undefined,
+ customerName: name || email,
customerEmail: email,
- clickId: {{Dub ID Cookie}} || undefined,
+ clickId: clickId,
});
}
})();
</script>
```
-Configure this tag to fire on **Form Submission** by creating a new trigger:
+> **Important**: Make sure to pass along the `email` and `name` query parameters to the thank-you page so that the lead event can be attributed to the correct customer.
-- 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
+Configure this tag to fire on specific pages by creating a **Page View** trigger with conditions:
-Name this tag "Dub Lead Tracking - Form Submission" and click **Save** to create the tag.
+- 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
-### Step 3: Create Lead Tracking Tag for Thank You Pages
+Name this tag "Dub Lead Tracking - Thank You Page" and save it.
-For tracking leads on thank-you pages (recommended approach), create another **Custom HTML** tag:
+### Option 2: Form Submission Tracking
+
+This method tracks leads immediately when users submit forms on your website. Note that this approach may be less reliable due to ad blockers and timing issues.
+
+Create a **Custom HTML** tag with the following code:
```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");
+ // 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
+ : "";
- // Only track if email is present
- if (email) {
- // Track the lead event
+ // Get dub_id from cookie using GTM variable
+ var clickId = {{Dub ID Cookie}} || "";
+
+ // Only track the lead event if email and clickId are present
+ if (email && clickId) {
dubAnalytics.trackLead({
eventName: "Sign Up",
customerExternalId: email,
- customerName: name || undefined,
+ customerName: name || email,
customerEmail: email,
- clickId: {{Dub ID Cookie}} || undefined,
+ clickId: clickId,
});
}
})();
</script>
```
-Configure this tag to fire on specific pages by creating a **Page View** trigger with conditions:
+> **Important**: You'll need to customize the DOM selectors
+> (`getElementById('name')`, `getElementById('email')`) to match your actual
+> form field IDs or use different methods to capture the form data based on your
+> website's structure.
-- 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
+Configure this tag to fire on **Form Submission** by creating a new trigger:
-Name this tag "Dub Lead Tracking - Thank You Page" and save it.
+- 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 save it.
## Testing your setup
@@ -99,6 +120,22 @@ 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
+3. **Test your chosen tracking method**:
+ - **For Option 1 (Thank You Page)**: Navigate to your thank-you page with query parameters (e.g., `[email protected]&name=Test User`)
+ - **For Option 2 (Form Submission)**: Navigate to a page with a form and submit a test form
+4. **Check the GTM debugger** to see if your tags are firing correctly
+
+### Verify lead tracking
+
+You can also verify that leads are being tracked by:
+
+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 lead events are appearing in your analytics
+
+### Common troubleshooting tips
+
+- **Tag not firing**: Check that your triggers are configured correctly and that the conditions match your page structure
+- **Missing publishable key**: Ensure you've replaced the placeholder with your actual publishable key
+- **Missing query parameters** (Option 1): Ensure your form redirects to the thank-you page with the required query parameters
+- **Form data not captured** (Option 2): Verify that your DOM selectors match your actual form field IDs or names
diff --git a/apps/web/scripts/migrations/backfill-customer-partner-ids.ts b/apps/web/scripts/migrations/backfill-customer-partner-ids.ts
index 485f2570b4..eade76c259 100644
--- a/apps/web/scripts/migrations/backfill-customer-partner-ids.ts
+++ b/apps/web/scripts/migrations/backfill-customer-partner-ids.ts
@@ -22,7 +22,7 @@ async function main() {
},
},
},
- take: 1000,
+ take: 10000,
});
if (customers.length === 0) {
console.log("No customers left to backfill");