Learn how to track lead conversion events using HubSpot and Linkkit to measure and attribute leads generated through your links.
Linkkit HubSpot Integration
Linkkit’s HubSpot integration allows you to track conversion events directly from HubSpot.
This is especially useful for B2B SaaS companies that use HubSpot as their CRM and want to track events such as meeting bookings, deal creation, and closed-won deals as lead and sale conversion events in Linkkit.
Prerequisites
Before you can start tracking conversions, you need to enable conversion tracking for your Linkkit links.
Option 1: Workspace-Level Setup
Open your workspace’s Tracking Settings page.
Enable the Workspace-Level Conversion Tracking toggle to activate conversion tracking across the workspace.
Option 2: Link-Level Setup
To enable conversion tracking for a specific link, open the Linkkit Link Builder, choose the desired link, and turn on the Conversion Tracking toggle.
Option 3: Via the API
To enable tracking, simply pass trackConversion: true when creating a new link or updating an existing link.
Next, install the Linkkit Analytics script on your website to start tracking conversion events.
You can add the Linkkit Analytics script using multiple installation methods depending on your website setup.
Open your browser's developer console and enter _linkkitAnalytics. If the installation was successful, the _linkkitAnalytics object should appear in the console.
Add the ?linkkit_id=test query parameter to your website URL and confirm that a linkkit_id cookie is created in your browser.
If both checks pass, the analytics script is installed and working correctly.
If not, verify the following:
The Linkkit Analytics script has been added to the <head> section of your website.
If your website uses a CDN, clear or purge the cache to ensure the latest version of the page is being served.
Finally, install the Linkkit HubSpot Integration in your workspace to connect HubSpot and start tracking conversion events.
Integration Setup
During the installation process, Linkkit will automatically create three properties in your HubSpot contact object:
- Linkkit ID – A unique identifier used by Linkkit to track clicks and attribute conversions.
- Linkkit Link – The shortened link that the contact clicked before visiting your website.
- Linkkit Partner Email – The email address of the partner associated with the shortened link.
Set Your Closed Won Deal Stage ID
You can specify which HubSpot deal stage should be considered as Closed Won for automatic sales tracking in Linkkit.
If you have customized your HubSpot pipeline by adding or modifying deal stages, enter the stage ID of your custom Closed Won stage in the Linkkit HubSpot Integration Settings.
Once configured, any HubSpot deal marked as Closed Won will automatically be recorded in Linkkit as a sale conversion event along with the associated deal value.
Option 1: Using HubSpot Forms
HubSpot Forms allow you to collect lead information and track conversions. By connecting HubSpot with Linkkit, you can attribute each form submission to the specific Linkkit link that generated the lead.
To enable accurate attribution, you need to capture the linkkit_id cookie in your HubSpot form. This ensures every lead is connected to the exact Linkkit link they interacted with.
Follow these steps to set it up:
1. Add a Hidden Field to Your Form
In the HubSpot form builder, create a hidden field and map it to the Linkkit ID contact property.
This allows the value captured by the Linkkit script to be stored on the contact record. Without mapping the field to a contact property, HubSpot will not save the linkkit_id value.
2. Add the Script to Your Website
Add the following script snippet to your website.
The script will read the linkkit_id cookie and, when available, automatically populate the hidden Linkkit ID form field with the captured 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("linkkit_id");
if (!clickId) {
console.debug("clickId not found. Skipping lead tracking.");
return;
}
// Populate the hidden field with the linkkit_id
HubSpotFormsV4.getForms()[0].setFieldValue("0-1/linkkit_id", clickId);
});
</script>
When a prospect submits the form, the linkkit_id value is captured and sent to HubSpot, ensuring the lead is correctly attributed to the original Linkkit link that generated the conversion.
Option 2: Using HubSpot Meeting Scheduler
HubSpot’s Meeting Scheduler allows prospects to book meetings directly with you or your team.
Since HubSpot does not support adding hidden fields to the scheduling form, you should use deferred lead tracking on the client side to capture and attribute leads.
1. Generate Your Publishable Key
Before setting up client-side conversion tracking, you need to create a publishable key from your Linkkit workspace.
To generate the key:
- Go to your workspace’s Tracking Settings page.
- Navigate to the Publishable Key section.
- Create a new publishable key for tracking conversions.
2. Allowlist Your Website Domain
Next, add your website domain to the allowlist so that client-side conversion events can be securely received by Linkkit.
To add your domain:
- Go to your workspace’s Tracking Settings page.
- Add your website domain to the Allowed Hostnames list.
This adds an extra layer of security by ensuring that only approved domains can send conversion events using your publishable key.
You can use hostname patterns to organize and manage your allowlist entries:
- example.com: Tracks conversion events only from the main domain (example.com).
- *.example.com: Tracks conversion events from all subdomains of example.com, but does not include the main domain itself.
3. Add the Tracking Code to Your Website
Add the following tracking code to your website to capture lead conversions when meetings are booked through the HubSpot Scheduler.
The script listens for HubSpot booking events, collects the prospect’s details (such as name and email), and sends the data using linkkitAnalytics.trackLead() with deferred lead tracking.
This ensures that leads are recorded only after the meeting is successfully confirmed, providing more accurate conversion attribution.
<!-- Load LinkKit 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://www.linkkitcdn.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, "linkkitAnalytics");
</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(" ");
linkkitAnalytics.trackLead({
mode: "deferred",
eventName: "Meeting scheduled",
customerExternalId: contact.email,
customerName: customerName,
customerEmail: contact.email,
});
}
}
});
</script>
Tracking Conversion Events
After a prospect completes a demo call, you’ll usually create a deal in HubSpot to manage the sales opportunity.
The Linkkit HubSpot Integration automatically uses webhooks to track both deal creation and deal closure events, giving you complete visibility into your conversion funnel.
When a Deal Is Created (Lead Event)
When you create a deal in HubSpot for a contact who originated from a Linkkit link, the integration automatically records it as a lead event in Linkkit.
When a Deal Is Closed (Sale Event)
When a deal reaches the Closed Won stage in HubSpot, the integration automatically records it as a sale event in Linkkit using the deal amount as the sale value.
If a deal is not being tracked as a sale in Linkkit, verify that the correct Closed Won Deal Stage ID is configured in your Linkkit HubSpot Integration Settings.
