- Find the host your pixel uses.
- Add that host to your
script-srcandconnect-srcdirectives. - Check that nothing is blocked, then verify the pixel in Cometly.
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
srcof your pixel snippet (see the table below). - Automatically fires an
initevent 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.CSP directives to update
script-src: allows loading scripts from the listed sources.connect-src: permits sending data to the listed endpoints.
Example CSP configuration
For the standard snippet, allow the script host:connect-src directive must also allow the host the pixel sends its requests to. Use the console check in 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:
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 automaticinitevent.
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.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’ssrc changes. For example, when you turn on First-party domain tracking, 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
- Serve the pixel from your own subdomain with first-party domain tracking
- Fix the base code not detected error
- Fix the Init not detected error
- Check your pixel and events with the Cometly Pixel Helper