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

# Set up call tracking

> Set up call tracking with the Cometly API so each phone call, and the purchase that follows it, is attributed to the ad or channel behind it.

Call tracking with the Cometly API records a phone call as an event (an action a person takes on the way to becoming a customer) and ties it to the visit that led to it. To set it up you capture the [`comet_token`](https://docs.cometly.com/concepts/comet-token) on your website, store it in your backend, and send it with each event.

This matters when leads phone you instead of filling in a form. A caller often has no email address yet, so without the token the call, and any purchase that follows it, cannot be traced to an ad. With it, you can see which ad or channel produced each call and each sale that came from one.

> [!NOTE]
>
> This is an advanced integration and needs a developer. Keep the [Cometly API documentation](https://docs.cometly.com/api-reference/overview.md) open for the technical details.

> [!TIP]
>
> If you use CallRail, CallTrackingMetrics, Nimbata or MarketCall, connect it from **Integrations** > **Calls** instead. Those integrations do not need the API. See [CallTrackingMetrics](https://docs.cometly.com/integrations/platforms/calltrackingmetrics.md), [Nimbata](https://docs.cometly.com/integrations/platforms/nimbata.md) and [MarketCall](https://docs.cometly.com/integrations/platforms/marketcall.md).

## Before you start

* The Cometly pixel is installed on your site. See [Install the Cometly pixel](https://docs.cometly.com/getting-started/install-pixel.md).
* You have a Cometly API token. See [Cometly API](https://docs.cometly.com/integrations/api.md).
* You have created a custom event for the phone call. See [Create and configure events](https://docs.cometly.com/getting-started/events.md).

## Why the comet\_token matters

* Cometly uses the `comet_token` to connect an event to the visitor's original journey.
* A caller often has no email address yet. Storing the `comet_token` keeps the call attributed while the contact details are incomplete.
* When an email address becomes available later, it is used for attribution in the events that follow.

## Set up call tracking

**1. Capture the comet\_token from the pixel**

The `comet_token` is the unique identifier of the visitor's journey. Your developer reads it from the Cometly pixel on your website.

* Use your call tracking platform (for example Invoca) to capture the `comet_token` when a call is made.
* Save the `comet_token` in your backend system so you can send it with later events.

**2. Send the first event (the phone call)**

When a call is made, send an event with the [Create Event](https://docs.cometly.com/api-reference/endpoint/create-event.md) endpoint. This event links the call to the original journey.

Fields to send:

* `event_name`: a custom event you created in Cometly. Custom events use names from `custom_event_1` to `custom_event_50`. You can find the name of each one under **Events Manager** > **Manage custom events**. See [Manage custom events](https://docs.cometly.com/guides/events/custom-events.md).
* `comet_token`: the token captured from the pixel.
* `phone`: the caller's phone number.

```json theme={null}
{
  "event_name": "custom_event_1",
  "comet_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "phone": "+1234567890"
}
```

**3. Send later events (for example a purchase)**

When more details become available (an email address, a purchase), send a second event. This step is what attributes the full journey.

Fields to send:

* `event_name`: the event that happened, for example `purchase`.
* `comet_token`: the token stored in your backend system.
* `email`: the contact's email address.
* `phone`: the caller's phone number.
* `amount`: the purchase amount.
* `first_name` and `last_name` (or `full_name`).

```json theme={null}
{
  "event_name": "purchase",
  "comet_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "email": "customer@example.com",
  "phone": "+1234567890",
  "amount": "99.99",
  "first_name": "John",
  "last_name": "Doe"
}
```

## Check it worked

Make a test call, then open **Events Manager** in Cometly and click the **Events Log** tab. Set **Source** to **Server** and look for the event you sent. If it is listed, Cometly received the call event.

## Best practices

1. **Store the comet\_token in your backend system.** It must be saved so you can include it in future events, especially those without an email address.
2. **Move to email-based attribution when you can.** Once an email address is captured, later events use the email address as the primary identifier. Until then, the `comet_token` is essential.
3. **Send every event through the Cometly API.** Both the first event (the phone call) and the events that follow (for example a purchase) are sent with the API.

## Notes for developers

* The `comet_token` is the link between a visitor's activity and their original journey in Cometly.
* With platforms like Invoca, capture the `comet_token` at the time of the call and pass it to your backend system.
* Any later event without an email address must include the `comet_token` to be attributed.

## Frequently asked questions

### Can I track phone calls in Cometly without a developer?

Yes, if you use CallRail, CallTrackingMetrics, Nimbata or MarketCall. You connect those from **Integrations** > **Calls**, and they do not need the API. The API method on this page is for other call tracking platforms and needs a developer.

### How do I get the comet\_token from my website?

The Cometly pixel provides a `cometToken()` function that returns the token as a string. Your developer calls it on the page and passes the value to your call tracking platform or backend. The pixel must be installed on the site for the function to be available. See [Comet Token](https://docs.cometly.com/concepts/comet-token.md).

### Can I send a call event to Cometly without an email address?

Yes. The Create Event endpoint needs at least one way to identify the person, and the `comet_token` counts as one, so an event with only `event_name`, `comet_token` and `phone` is accepted. Add the email address to later events once you have it.

## Next steps

* [Cometly API documentation](https://docs.cometly.com/api-reference/overview.md)
* [Create Event endpoint reference](https://docs.cometly.com/api-reference/endpoint/create-event.md)
* [Using the Events Log](https://docs.cometly.com/support/troubleshooting/general/event-log.md)
* [Manage custom events](https://docs.cometly.com/guides/events/custom-events.md)
* [How events work](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.