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

# CallTrackingMetrics integration

> Set up the CallTrackingMetrics Cometly integration so each tracked phone call is recorded as an event and tied to the ad that produced it.

The CallTrackingMetrics Cometly integration records phone calls from CallTrackingMetrics as events in Cometly (an event is an action a person takes on the way to becoming a customer, such as a call, a lead or a purchase). You pass your Cometly tracking token (`comet_token`, the ID Cometly gives each visitor) into CallTrackingMetrics, then send call webhooks back to Cometly.

This matters when leads phone you instead of filling in a form. When CallTrackingMetrics sends the `comet_token` with each call, Cometly can match the call back to the ads and traffic sources that generated it, so you can see which campaigns make the phone ring.

> [!NOTE]
>
> Cometly only records a call when the webhook includes the `comet_token` custom field. Calls that arrive without it are rejected, so complete every step below.

## Prerequisites

Before you start, make sure:

* You have **admin rights** in CallTrackingMetrics.
* Your CallTrackingMetrics account is on a **Marketing Pro plan or higher**.

## Step 1: Buy a tracking number

1. Log in to your CallTrackingMetrics account.

2. In the left-hand menu, click **Numbers**, then **Tracking Numbers**.

   ![CallTrackingMetrics Numbers menu with Tracking Numbers circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/01.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=0203da82286fe3102440c3e7266639b6)

3. Click the **Buy Numbers** button.

4. Select a number and click the **+** icon.

5. Click **Confirm & Purchase** to complete your purchase.

## Step 2: Create a target number

1. Go to **Numbers**, then **Target Numbers**.

   ![CallTrackingMetrics Numbers menu with Target Numbers circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/02.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=95267d7fd0fdf17881283c6807f48107)

2. Click **New Target Number**.

3. In the **Target Number** field, enter the phone number displayed on your landing page. CallTrackingMetrics replaces this number dynamically.

4. Set **Match Type** to **Phone Match**.

5. Click **Save Changes**.

## Step 3: Create a tracking source

1. Go to **Numbers**, then **Tracking Sources**.

   ![CallTrackingMetrics Numbers menu with Tracking Sources circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/04.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=ca1baffb8ac279562526c15819cf10e6)

2. Click **New Tracking Source**.

3. In the **General** section:

   * Enter a **Tracking Source Name**.
   * Toggle **Onsite (dynamic)** on.
   * Click **Save Changes**.

   ![Tracking source General section with the name, Onsite (dynamic) toggle and Save Changes circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/05.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=f5501770d64e3aa3f43dd11ecfeeb52c)

4. In the **Matching Conditions** section, open the **Landing URL** tab:

   * Enter your landing page URL.
   * Click **Save Changes**.

## Step 4: Install the tracking code

1. Go to **Numbers**, then **Tracking Code**.

   ![CallTrackingMetrics Numbers menu with Tracking Code circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/06.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=15961608e966eb3fafb4b332d8f9e77c)

2. Copy your **Tracking Code Script** and paste it into the `<head>` section of your landing page.

3. Scroll down to **Advanced Options**, then expand the **Custom Tracking Code** section.

4. Paste the script below into the **Custom Tracking Code** box. Replace `YOUR-COMETLY-PIXEL-HERE` with the `src` URL of your Cometly pixel. To find it, go to **Setup** in Cometly, open the **Install the Cometly pixel** step, and copy the URL inside `src="..."` from the code under **Install the pixel**. See [Install the pixel](https://docs.cometly.com/getting-started/install-pixel.md) for details.

   ```javascript theme={null}
   (function(){
   try {
   var s = document.createElement('script');
   s.src = 'YOUR-COMETLY-PIXEL-HERE';
   s.async = true;
   document.head.appendChild(s);
   } catch(e) {}

   })();

   // 2) Read comet_token and push to CTM cvars

   (function(){

   try {
   window.__ctm_cvars = window.__ctm_cvars || [];
   function q(name){
     try { return new URLSearchParams(location.search).get(name) || ''; } catch(e){ return ''; }
   }
   function ls(){
     try { return localStorage.getItem('ctCartToken') || ''; } catch(e){ return ''; }
   }
   function sanitize(x){
     return (x || '').toString().replace(/[^A-Za-z0-9._~\-]/g,'').slice(0,128);
   }
   var token =
     (typeof window.cometToken === 'function' ? window.cometToken() : '') ||
     q('comet_token') ||
     ls();
   token = sanitize(token);
   if (token) window.__ctm_cvars.push({ _comet_token: token });
   } catch(e) {}

   })();
   ```

   > [!TIP]
   >
   > This script makes sure each call session captures the visitor's Cometly tracking token (`comet_token`), which Cometly needs to attribute the call.

5. Click **Save Changes**.

## Step 5: Create a custom field for the Comet token

1. Go to **Settings**, then **Custom Fields**.

   ![CallTrackingMetrics Settings menu with Custom Fields circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/09.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=3d88c08761668a07f50f931b18273c92)

2. Under the **Contact** section, click **Add Field**.

3. Enter the following details:

   * **Field Name:** Comet token
   * **Type:** Text
   * **Save to:** Activity
   * Check **Log Visible**

   ![Custom field named Comet token, type Text, saved to Activity, with Log Visible checked](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/10.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=d147193076b83f0b21b920c0e2f747fb)

   > [!WARNING]
   >
   > Check that the **API Name** shown under the field is `comet_token`. Cometly reads the token from the custom field with that API name.

4. Click **Save Changes**.

## Step 6: Add an Update Field action

1. After saving the field, click **Add Action**.

2. Select **Update Field**.

3. In the fields list, select **Comet token**.

4. Under **Set value to**, select **Session**.

5. Enter `_comet_token` as the value.

   ![Update Field action setting Comet token to the Session value \_comet\_token](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/11.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=7de189b11c185fddcd91e6d4d45c3808)

6. Click **Save Changes**.

## Step 7: Create a trigger

1. Go to **Flows**, then **Triggers**.

   ![CallTrackingMetrics Flows menu with Triggers circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/12.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=fce42c439d4fd7222bcb25e8451594f8)

2. Click **New Trigger**.

3. In the **General** section:

   * Enter a name for the trigger.
   * Set **Trigger** to **When a website session is associated to the activity record**.
   * Toggle **Trigger for all Activities** on.
   * Click **Save Changes**.

   ![Trigger General section with the name, trigger type, Trigger for all Activities and Save Changes circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/13.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=34b30b69c83661437a6699bdac5a0357)

4. In the **Workflow** section:

   * Click **+ Add Workflow**.
   * Remove the default rule (trash icon).
   * Click **Add Action** and select **Update Field**.
   * Fill in the fields the same way as in step 6 (**Comet token**, **Session**, `_comet_token`).
   * Click **Save Changes**.

## Step 8: Activate CallTrackingMetrics in Cometly

1. Log in to Cometly.

2. Click **Integrations** in the sidebar, select the **Calls** category, and click **Connect** on the **CallTrackingMetrics** card.

   ![The Cometly Apps & Integrations page with the Calls category boxed in the category list and the CallTrackingMetrics card with its Connect button boxed.](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/14.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=c5f519ac681803bc3db444255abf1010)

3. Click **Activate CallTrackingMetrics**.

   ![The CallTrackingMetrics integration page in Cometly before activation, with a box around the Activate CallTrackingMetrics button in step 1 and the Setup Instructions panel on the right.](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/15.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=da543e24fe98305897ab618f01cacf7b)

4. After activation, the page shows two webhook URLs under **Copy the webhook URLs**:

   * **Call Started**
   * **Call Answered**

   Click **Copy** next to the webhook URL of each event type you want to track.

   ![The CallTrackingMetrics integration page in Cometly after activation, showing the Call Started and Call Answered webhook URLs with a box around each Copy button and an event mapping set to Contact with a Save button under each.](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/16.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=10caa5ff71ab8badcf1929ad044a4dc5)

5. Under each webhook URL you plan to use, pick the Cometly event the call should be recorded as in the **Cometly Events** dropdown, then click **Save**. The dropdown starts on **Contact**. Click **Save** even if you keep **Contact**, so the mapping is stored.

## Step 9: Create webhooks in CallTrackingMetrics

1. In CallTrackingMetrics, go to **Settings**, then **Webhooks**.

   ![CallTrackingMetrics Settings menu with Webhooks circled](https://mintcdn.com/cometly/2fSDFk1g6ELl9hsV/images/integrations/platforms/calltrackingmetrics/17.webp?fit=max\&auto=format\&n=2fSDFk1g6ELl9hsV\&q=85\&s=5815efa1cb61eac27458840b92fcb5b1)

2. Click **New Webhook**.

3. Enter a name for your webhook.

4. Choose a trigger:

   * For **Call Started**, select **When an activity is received \[start]**.
   * For **Call Answered**, select **When an agent answers a call queue \[answered]**.

5. In the **Connection** section:

   * Paste the matching webhook URL you copied from Cometly.
   * Set **Request Body Type** to **Log Data**.
   * Click **Save Changes**.

6. Repeat for the other event type if you want to track both.

## Check it worked

Visit your landing page, then call the tracking number it shows. In Cometly, open **Events Manager** and click the **Events Log** tab, with **Source** set to **Server**. The call appears in the log under the Cometly event you mapped it to.

## Frequently asked questions

### Do I need both the Call Started and Call Answered webhooks in CallTrackingMetrics?

No. Each webhook URL works on its own, so you only create a webhook in CallTrackingMetrics for the event types you want to track. Use **Call Started** to record a call as soon as it comes in, and **Call Answered** to record a call when an agent answers it.

### Which Cometly event is a CallTrackingMetrics call recorded as?

By default, both **Call Started** and **Call Answered** are recorded as a **Contact** event. To use a different event, pick it in the **Cometly Events** dropdown under the webhook URL on the CallTrackingMetrics page in Cometly, then click **Save**.

### What call data does CallTrackingMetrics send to Cometly?

Cometly reads the `comet_token` custom field, the caller's name, the caller's phone number and the time of the call from each webhook. The token links the call to the visitor's journey, and the name and phone number are saved with the event.

## Next steps

* [Understand how events work in Cometly](https://docs.cometly.com/guides/events/how-events-work.md)
* [Learn what the comet\_token is and how it links a call to a visit](https://docs.cometly.com/concepts/comet-token.md)
* [Send your call events back to the ad platforms](https://docs.cometly.com/getting-started/send-conversions.md)
* [Set up call tracking with the Cometly API instead](https://docs.cometly.com/guides/events/call-tracking.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.