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

# Use Cometly with a Content Security Policy

> Allow the Cometly pixel in your Content Security Policy (CSP): the hosts to add to script-src and connect-src so the pixel loads and sends data.

You installed the Cometly pixel (the script that tracks where your website visitors come from), but it does not load or send data. Your browser's developer console shows an error that names a Cometly URL and the Content Security Policy directive that blocked it, and the check in Cometly shows **Pixel not detected**.

Content Security Policy (CSP) is a security standard that helps prevent cross-site scripting (XSS), clickjacking and other code injection attacks. If your website uses a CSP and you install the Cometly pixel, you need to adjust your CSP so the pixel can work. Cometly only tracks the pages where the pixel runs, so a blocked pixel means those visits are not recorded.

To allow the Cometly pixel in your Content Security Policy:

1. Find the host your pixel uses.
2. Add that host to your `script-src` and `connect-src` directives.
3. Check that nothing is blocked, then verify the pixel in Cometly.

Each step is covered below.

## Why adjust your CSP for Cometly

By default, a CSP restricts the sources your website can load resources from, such as scripts, styles and images. The Cometly pixel loads an external script and sends data back to Cometly's servers, so your CSP may block it unless you explicitly allow it.

The Cometly pixel:

* Loads a script from the host in the `src` of your pixel snippet (see the table below).
* Automatically fires an `init` event upon loading, which involves network requests to Cometly's servers.

## Find the host your pixel uses

The host to allow depends on the snippet installed on your website. To see your current snippet, go to **Setup** > **Install the Cometly pixel** in Cometly and look at the code under **Install the pixel**.

| Your snippet | Host to allow |
| - | - |
| Standard snippet | `https://js.comet-serve.com` |
| [First-party domain tracking](https://docs.cometly.com/guides/tracking/first-party-domain.md) is on | Your own tracking subdomain, for example `https://data.yourdomain.com` |
| Older snippet that loads from `t.cometlytrack.com` | `https://t.cometlytrack.com` |

## CSP directives to update

1. **`script-src`**: allows loading scripts from the listed sources.
2. **`connect-src`**: permits sending data to the listed endpoints.

## Example CSP configuration

For the standard snippet, allow the script host:

```http theme={null}
Content-Security-Policy:
  script-src 'self' https://js.comet-serve.com;
```

Your `connect-src` directive must also allow the host the pixel sends its requests to. Use the console check in [Check that nothing is blocked](#check-that-nothing-is-blocked) to see which host that is on your site.

For an older snippet that loads from `t.cometlytrack.com`, the script and the pixel's network requests use the same host:

```http theme={null}
Content-Security-Policy:
  script-src 'self' https://t.cometlytrack.com;
  connect-src 'self' https://t.cometlytrack.com;
```

What each directive does:

* **`script-src`**: add your pixel host so the browser can load the Cometly pixel script.
* **`connect-src`**: add the host the pixel sends its network requests to, including the automatic `init` event.

## Check that nothing is blocked

After you change your CSP, load a page that has the pixel and open your browser's developer console. When a CSP blocks a request, the browser logs an error that names the blocked URL and the directive that blocked it. If you see an error for a Cometly host, add that host to the directive named in the message.

Then confirm the pixel works: in Cometly, go to **Setup** > **Install the Cometly pixel** and click **Verify** next to your domain under **Verify your pixel**. The issue is resolved when the console shows no CSP error for a Cometly host and the domain shows **Pixel detected**. See [Install and verify the Cometly pixel](https://docs.cometly.com/getting-started/install-pixel.md).

## Frequently asked questions

### Do I need a Content Security Policy to use Cometly?

No. This page only applies if your website already uses a CSP. Without one, the browser does not restrict where scripts load from, so you install the pixel as usual.

### Can a Content Security Policy make the Cometly pixel show as not detected?

Yes. A CSP restricts the sources your website can load scripts from, so it may block the pixel unless you explicitly allow it. Allow the host your pixel uses, then click **Retry** next to the domain under **Verify your pixel**.

### Do I need to update my CSP if my Cometly pixel script changes?

Only if the host in the script's `src` changes. For example, when you turn on [First-party domain tracking](https://docs.cometly.com/guides/tracking/first-party-domain.md), the script under **Install the pixel** changes to load from your own subdomain, so add that subdomain to your CSP when you swap the script on your site.

## Next steps

* [Install and verify the Cometly pixel](https://docs.cometly.com/getting-started/install-pixel.md)
* [Serve the pixel from your own subdomain with first-party domain tracking](https://docs.cometly.com/guides/tracking/first-party-domain.md)
* [Fix the base code not detected error](https://docs.cometly.com/support/troubleshooting/pixel/base-code-not-detected.md)
* [Fix the Init not detected error](https://docs.cometly.com/support/troubleshooting/pixel/init-not-detected.md)
* [Check your pixel and events with the Cometly Pixel Helper](https://docs.cometly.com/guides/tracking/pixel-helper.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.