> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cometly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HubSpot form tracking (new forms)

> Set up HubSpot form tracking in Cometly: pass the Comet Token through new-editor HubSpot forms so each lead is tied to the ad behind it.

HubSpot form tracking in Cometly works by saving a Comet Token on every contact who submits your form. The Comet Token is the identifier the Cometly pixel gives each visitor, and it links that visitor to the ads and channels that brought them to your site. You add a hidden field to the form, and a short script fills it in.

This matters because the events you send from HubSpot (conversions such as a new lead or a won deal) happen in your CRM, not on your website. With the token stored on the contact, Cometly can tie each of those events back to the right visitor, so you can see which ads produce your HubSpot leads and deals.

HubSpot has two types of forms:

1. **Legacy forms**, built with the old editor.
2. **New forms**, built with the updated editor.

This page is for **new forms**. If your form was built with the legacy editor, follow [HubSpot legacy forms](https://docs.cometly.com/integrations/forms/hubspot-legacy-forms.md) instead.

To check which type you have, click **Marketing > Forms** in the HubSpot menu and look at the label under each form name:

![HubSpot forms list with arrows marking a new form, labeled Form, and a legacy form, labeled Form (Legacy editor)](https://mintcdn.com/cometly/4NU5YV9iL1PADmGE/images/integrations/forms/hubspot/01.webp?fit=max\&auto=format\&n=4NU5YV9iL1PADmGE\&q=85\&s=dc4ed1e124ef20d4cdbc2464eff3d249)

> [!WARNING]
>
> This setup only works for embedded HubSpot lead capture marketing forms built with the **new** editor. It does not work for embedded meeting links where a prospect books a time.

## Step 1: Install and verify the Cometly pixel

Make sure the Cometly pixel (the tracking script that records the visitors who reach your site) is installed on every web page that holds one of your HubSpot forms.

If you have not installed and verified the pixel yet, see [Install the Cometly pixel](https://docs.cometly.com/getting-started/install-pixel.md).

## Step 2: Add a hidden field to your HubSpot form

**1. Add a Multi-line text field**

In the HubSpot form editor, click the **+** sign in the top left to add a new field. Drag a **Multi-line text** field onto your form, above the form button.

![HubSpot form editor Add to form panel with an arrow on the Multi-line text field](https://mintcdn.com/cometly/4NU5YV9iL1PADmGE/images/integrations/forms/hubspot/02.webp?fit=max\&auto=format\&n=4NU5YV9iL1PADmGE\&q=85\&s=534307bcc1009a8a8303d9d5187eb821)

**2. Create a new property**

Click **Create new property**.

![HubSpot Edit field panel with an arrow on Create new property under Connected property](https://mintcdn.com/cometly/4NU5YV9iL1PADmGE/images/integrations/forms/hubspot/03.webp?fit=max\&auto=format\&n=4NU5YV9iL1PADmGE\&q=85\&s=6d384520d8f44a311a18b0fa6c75b833)

**3. Name the property comet\_token**

For the **Property label**, enter exactly `comet_token`.

* Make sure **Object type** is set to **Contact**.
* Make sure **Group** is set to **Contact information**.

Click **Create**.

![HubSpot Create a new property dialog with Property label comet\_token and the Create button](https://mintcdn.com/cometly/4NU5YV9iL1PADmGE/images/integrations/forms/hubspot/04.webp?fit=max\&auto=format\&n=4NU5YV9iL1PADmGE\&q=85\&s=099bcbea0abe257ad1df8a7d60726cd2)

**4. Check the connected property**

After the property is created, make sure `comet_token` is the connected property of the Multi-line text field.

![HubSpot Edit field panel showing the field connected to the comet\_token contact property](https://mintcdn.com/cometly/4NU5YV9iL1PADmGE/images/integrations/forms/hubspot/05.webp?fit=max\&auto=format\&n=4NU5YV9iL1PADmGE\&q=85\&s=6c052425a51b00c48f28b07c184098ab)

**5. Hide the field and publish**

Scroll to the bottom of the field options and turn on **Hidden field** for the `comet_token` field. Do not set it as a required field.

Save your changes by clicking **Review and update**.

![HubSpot Edit field panel with Hidden field turned on and the Review and update button](https://mintcdn.com/cometly/4NU5YV9iL1PADmGE/images/integrations/forms/hubspot/06.webp?fit=max\&auto=format\&n=4NU5YV9iL1PADmGE\&q=85\&s=1544312dde2d0c89daa5f1df088dd43b)

## Step 3: Add the script to your landing page footer

Place this code just before the closing `</body>` tag of your web page HTML, on every page where your new HubSpot form is embedded. It fills the hidden field with the visitor's Comet Token once the HubSpot form has loaded.

```html theme={null}
<script>
window.addEventListener('hs-form-event:on-ready', async (event) => {
  HubSpotFormsV4.getFormFromEvent(event).setFieldValue('0-1/comet_token', cometToken());
});
</script>
```

## Step 4: Map comet\_token in your HubSpot events

When you send events from HubSpot to Cometly, map the **Comet Token** field to the `comet_token` property from HubSpot. In the **Configure Mapping** step of the event, click **Add Field**, choose **Comet Token** under **Cometly Fields**, and select the `comet_token` property under **Data Fields**. This lets Cometly attribute the event to the right visitor.

To create HubSpot events in Cometly, see the [HubSpot integration](https://docs.cometly.com/integrations/platforms/hubspot.md).

## Check it worked

Submit a test entry on a page that holds your form, then open the new contact in HubSpot: its `comet_token` property should hold a value. In Cometly, once your HubSpot event is active and its trigger fires for that contact, the event is listed in the **Events Log** tab of **Events Manager**.

## Frequently asked questions

### What is the Comet Token in a HubSpot form?

The Comet Token is a unique identifier from the Cometly pixel that links a visitor's browser session to their attribution data. Saving it in the hidden `comet_token` field stores it on the HubSpot contact. When HubSpot later sends an event for that contact, Cometly uses the token to attribute the event to the right visitor.

### Why is the comet\_token property empty on my HubSpot contacts?

The script reads the token from the Cometly pixel, so the pixel must be installed on the page that holds the form. Also check that the script from step 3 is on that same page, that the form was built with the new editor, and that the property is named exactly `comet_token`.

### Do I still need to map Email when I map the Comet Token?

Yes. **Email** and **Event Time** are required in the **Configure Mapping** step of a HubSpot event. **Comet Token** is an extra field you add with **Add Field**.

## Next steps

* [Create HubSpot events with the HubSpot integration](https://docs.cometly.com/integrations/platforms/hubspot.md)
* [Check incoming events in the Events Log](https://docs.cometly.com/support/troubleshooting/general/event-log.md)
* [Test form tracking on your pages](https://docs.cometly.com/guides/form-tracking/testing.md)
* [Set up HubSpot legacy forms](https://docs.cometly.com/integrations/forms/hubspot-legacy-forms.md)
* [Learn how events work in Cometly](https://docs.cometly.com/guides/events/how-events-work.md)

Still have questions or need a hand? We're happy to help. Reach our team at [support@cometly.com](mailto:support@cometly.com).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.