> ## 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.

# Zendesk Chat integration

> Set up the Zendesk Chat Cometly integration: pass the Cometly tracking token into a Zendesk field so each chat lead is tied to its source.

The Zendesk Chat Cometly integration lets you track chat leads back to their source. It works by passing the Cometly tracking token (the Comet Token, an identifier that links a visitor's browser session to their attribution data) from your website into a custom field in Zendesk.

This matters because a chat lead usually becomes a deal later, inside Zendesk. With the token saved on the lead, Cometly can tie the events you send for that lead back to the ad or channel that brought the visitor to your site, so you can see which ads produce chat leads and sales.

## Prerequisites

* The Cometly pixel (the tracking script you add to your site) is installed on the website where the chat widget runs. The script in step 2 calls `cometToken()`, which only exists when the pixel is on the page. See [Install the Cometly pixel](https://docs.cometly.com/getting-started/install-pixel.md).
* The Zendesk Chat widget is installed on the same website.

## Step 1: Create a custom field for the Cometly tracking token

1. Log in to your Zendesk account.

2. In the **Admin Center**, click **Objects and rules**.

3. Select **Fields** from the menu.

4. On the **Fields** page, click **Add field**.

   ![Zendesk Fields page with the Add field button circled](https://mintcdn.com/cometly/alvP4_0ekdK-CBm_/images/integrations/platforms/zendesk-chat/01.webp?fit=max\&auto=format\&n=alvP4_0ekdK-CBm_\&q=85\&s=c34461defe8c519adf0c0d266042e8e6)

5. Configure the new field:

   * **Field type**: Select **Number**.

     ![Zendesk Add field page with the Number field type highlighted](https://mintcdn.com/cometly/alvP4_0ekdK-CBm_/images/integrations/platforms/zendesk-chat/02.webp?fit=max\&auto=format\&n=alvP4_0ekdK-CBm_\&q=85\&s=4c8c1dd9a272bae008751999bf88f822)

   * **Display name**: Enter `Cometly_tracking_token`.

   * **Permissions**: Select **Customers can edit**.

     ![Zendesk Number field form with the display name and Customers can edit highlighted](https://mintcdn.com/cometly/alvP4_0ekdK-CBm_/images/integrations/platforms/zendesk-chat/03.webp?fit=max\&auto=format\&n=alvP4_0ekdK-CBm_\&q=85\&s=afaec5b01488484d13e3138f4b537091)

   * **Title shown to customers**: Enter **Cometly tracking token**.

     ![Zendesk field form with Title shown to customers highlighted and the Save button circled](https://mintcdn.com/cometly/alvP4_0ekdK-CBm_/images/integrations/platforms/zendesk-chat/04.webp?fit=max\&auto=format\&n=alvP4_0ekdK-CBm_\&q=85\&s=d2774514d68c6d18d95eebf26001ebca)

6. Click **Save**.

## Step 2: Copy the custom field ID and add the script to your website

1. Return to the **Fields** page.

2. Find the new **Cometly\_tracking\_token** field.

3. Copy its **Field ID**.

   ![Zendesk Fields list with the Field ID of the cometly\_tracking\_token field highlighted](https://mintcdn.com/cometly/alvP4_0ekdK-CBm_/images/integrations/platforms/zendesk-chat/05.webp?fit=max\&auto=format\&n=alvP4_0ekdK-CBm_\&q=85\&s=7f096ed5d0a17b568c12a93daee0cc14)

4. In the script below, replace `UPDATE_WITH_FIELD_ID` with the **Field ID** of your `Cometly_tracking_token` field.

   ```html theme={null}
   <script type="text/javascript">
       try {
           const cometTokenValue = cometToken();
           try {
               zE("messenger:on", "open", function() {
                   zE("messenger:set", "conversationFields", [
                       { id: "UPDATE_WITH_FIELD_ID", value: cometTokenValue }
                   ]);
               });
           } catch (error) {
               console.error("Error Zendesk Widget is not set:", error);
           }
       } catch (error) {
           console.error("Error getting comet token:", error);
       }
   </script>
   ```

5. Copy the script and add it to the `<body>` of your website, below your Zendesk Chat widget code.

   > [!WARNING]
   >
   > Make sure the script is below the Zendesk widget code, or it will not work properly.

## Step 3: For testing, add the custom field to the default ticket form

1. Go back to **Objects and rules** in the **Admin Center**.
2. Select **Forms**.
3. On the **Forms** page, click **Default Ticket Form**.
4. From the **Available ticket fields**, find **Cometly\_tracking\_token** and move it to the left column to include it in the form.
5. Click **Save**.

In an incognito or private browser window, enter a form submission through the widget. The `Cometly_tracking_token` field is then filled with the token value. Cometly uses this token to track the lead back to the correct source when it receives an event.

## Step 4: Send events to Cometly from Zendesk

To send events for new leads, deals created and closed won deals, follow the [Zendesk Sell integration guide](https://docs.cometly.com/integrations/platforms/zendesk-sell.md). It shows where to pass the `Cometly_tracking_token` field as the Comet Token.

## Check it worked

Start a chat through the widget in an incognito or private browser window, then open the ticket in Zendesk: the `Cometly_tracking_token` field holds a token value. Once you send events from Zendesk as described in step 4, they appear in Cometly under **Events Manager**, on the **Events Log** tab.

## Frequently asked questions

### Does Zendesk Chat send leads to Cometly automatically?

No. The steps on this page only save the Cometly tracking token on the chat lead in Zendesk. To record the lead in Cometly, send an event that includes the token as the **Comet Token**, for example with Zapier as shown in the [Zendesk Sell integration guide](https://docs.cometly.com/integrations/platforms/zendesk-sell.md).

### Why is the Cometly tracking token field empty in Zendesk?

The script can only fill the field when the Cometly pixel is on the same page as the chat widget and the script sits below the Zendesk widget code. Check both, and check that you replaced `UPDATE_WITH_FIELD_ID` with your **Field ID**. The script sets the value when the visitor opens the widget, so test with a new chat in a private browser window.

## Next steps

* [Send lead and deal events from Zendesk Sell](https://docs.cometly.com/integrations/platforms/zendesk-sell.md)
* [Connect Cometly to Zapier](https://docs.cometly.com/integrations/zapier.md)
* [Create and manage events in Cometly](https://docs.cometly.com/getting-started/events.md)
* [Check incoming events in the Events Log](https://docs.cometly.com/support/troubleshooting/general/event-log.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.