Conversion tracking requires a Business plan subscription or higher.
When it comes to conversion tracking, a lead event happens when a user performs an action that indicates interest in your product or service. This could be anything from:
  • Signing up for an account
  • Booking a demo meeting
  • Joining a mailing list
A diagram showing how lead events are tracked in the conversion funnel
This guide shows you how to track lead conversion events with HubSpot as your CRM.

Prerequisites

First, you’ll need to enable conversion tracking for your Dub links to be able to start tracking conversions:
If you’re using Dub Partners, you can skip this step since partner links will have conversion tracking enabled by default.
Then, you’d want to install the @dub/analytics script to your website to track conversion events. You can install the @dub/analytics script in several different ways:
You can verify the installation with the following tests:
  1. Open the browser console and type in _dubAnalytics – if the script is installed correctly, you should see the _dubAnalytics object in the console.
  2. Add the ?dub_id=test query parameter to your website URL and make sure that the dub_id cookie is being set in your browser.
If both of these checks pass, the script is installed correctly. Otherwise, please make sure:
  • The analytics script was added to the <head> section of the page
  • If you’re using a content delivery network (CDN), make sure to purge any cached content
Finally, install the HubSpot Dub Integration to your workspace.
HubSpot Dub Integration

Option 1: Using HubSpot Forms

HubSpot Forms help you capture lead information and track conversions. By integrating with Dub, you can attribute each form submission back to the specific Dub link that drove the conversion. To make attribution work, you need to capture the dub_id cookie in your HubSpot form. This ensures each lead is tied back to the exact Dub link they came from. Here’s how you can set it up:
1

Create a new property

In HubSpot, create a new property under the Contact object:
  • Label: Dub Id
  • Group: Contact information
  • Field type: Single-line text
  • Visibility options: set to Show property in forms and bots
  • Internal name: must be dub_id
Segment Dub (Actions) Mapping
2

Add a hidden field to your form

In the HubSpot form builder, add a hidden field and map it to the Dub Id property you just created.This makes sure the value captured by your script is stored on the contact record. Without mapping to a property, HubSpot won’t persist the dub_id value.
Segment Dub (Actions) Mapping
3

Add the script to your site

Finally, add the following snippet to your site. The script reads the dub_id cookie and, if found, automatically fills the hidden Dub Id form field with its value.
<script src="https://js.hsforms.net/forms/embed/47839131.js" defer></script>

<div
  class="hs-form-frame"
  data-region="na1"
  data-form-id="YOUR_FORM_ID"
  data-portal-id="YOUR_PORTAL_ID"
></div>

<script>
  // A helper function to get the value of a cookie
  function getCookie(name) {
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);

    if (parts.length === 2) {
      return parts.pop().split(";").shift();
    }

    return null;
  }

  // Listen for the form ready event
  window.addEventListener("hs-form-event:on-ready", (event) => {
    const clickId = getCookie("dub_id");

    if (!clickId) {
      console.debug("clickId not found. Skipping lead tracking.");
      return;
    }

    // Populate the hidden field with the dub_id
    HubSpotFormsV4.getForms()[0].setFieldValue("0-1/dub_id", clickId);
  });
</script>
When the form is ready, the script checks for the dub_id and, if found, automatically sets it into a hidden Dub Id field on the form.This way, when a prospect submits the form, the dub_id is captured and passed to HubSpot, ensuring the lead is attributed back to the original Dub link.

Option 2: Using HubSpot Meeting Scheduler

HubSpot’s Meeting Scheduler lets prospects book time directly with you or your team. Since HubSpot doesn’t let you add a hidden field to the scheduling form, you should handle initial lead tracking through deferred lead tracking on the client side.
1

Generate your publishable key

Before you can track conversions on the client-side, you need to generate a publishable key from your Dub workspace.To do that, navigate to your workspace’s Analytics settings page and generate a new publishable key under the Publishable Key section.
Enabling conversion tracking for a workspace
2

Allowlist your site's domain

Then, you’ll need to allowlist your site’s domain to allow the client-side conversion events to be ingested by Dub.To do that, navigate to your workspace’s Analytics settings page and add your site’s domain to the Allowed Hostnames list.This provides an additional layer of security by ensuring only authorized domains can track conversions using your publishable key.
Enabling conversion tracking for a workspace
You can group your hostnames when adding them to the allow list:
  • example.com: Tracks traffic only from example.com.
  • *.example.com: Tracks traffic from all subdomains of example.com, but not from example.com itself.
When testing things out locally, you can add localhost to the Allowed Hostnames list temporarily. This will allow local events to be ingested by Dub. Don’t forget to remove it once you’re ready to go live!
3

Add the tracking code to your site

Use the following code to track lead conversions when meetings are booked through the HubSpot scheduler.The script listens for booking events from HubSpot, extracts the customer’s details (name and email), and then calls dubAnalytics.trackLead() with deferred lead tracking.This way, the lead is only tracked after the meeting is confirmed, ensuring accurate attribution.

<!-- Load Dub analytics script -->
<script>
  !(function(w, n) {
    w[n] = w[n] || function() { (w[n].q = w[n].q || []).push(arguments); };
    ["trackClick","trackLead","trackSale"].forEach(t => w[n][t] = (...a) => w[n](t, ...a));
    var s = document.createElement("script");
    s.defer = true;
    s.src = "https://dubcdn.com/analytics/script.conversion-tracking.js";
    s.setAttribute("data-publishable-key", "YOUR_PUBLISHABLE_KEY");
    s.setAttribute("data-domains", '{"refer":"YOUR_SHORT_DOMAIN"}');
    document.head.appendChild(s);
  })(window, "dubAnalytics");
</script>

<div
  class="meetings-iframe-container"
  data-src="https://meetings.hubspot.com/YOUR_USERNAME?embed=true"
></div>

<script
  type="text/javascript"
  src="https://static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js"
></script>

<script>
  // Listen for the message event
  window.addEventListener("message", function (event) {
    // Check if the message is from the scheduling widget
    if (event.origin === "https://meetings.hubspot.com") {
      // Get the data from the event
      const data = event.data;

      if (data.meetingBookSucceeded) {
        // Get the scheduled contact
        const contact =
          data.meetingsPayload.bookingResponse.postResponse.contact;

        if (!contact) {
          console.debug("contact not found. Skipping lead tracking.");
          return;
        }

        // Track the lead with the scheduled contact
        const customerName = [contact.firstName, contact.lastName]
          .filter(Boolean)
          .join(" ");

        dubAnalytics.trackLead({
          mode: "deferred",
          eventName: "Meeting scheduled",
          customerExternalId: contact.email,
          customerName: customerName,
          customerEmail: contact.email,
        });
      }
    }
  });
</script>

Tracking sale conversion events

After a prospect attends your demo call, you’ll typically create a deal in HubSpot to track the sales opportunity. Dub’s HubSpot integration automatically sets up webhooks to track both deal creation and deal closure events, providing complete visibility into your sales funnel.

When a deal is created

When you create a deal in HubSpot for a contact who came through your Dub links, the integration automatically tracks this as a lead conversion event in Dub.

When a deal is closed

When a deal moves to a Closed Won status in HubSpot, the integration automatically tracks a sale event in Dub using the deal amount as the sale value.