Menu
Guides
API Reference

Guides

VTEX Ads Stories Package Content Security Policy

Allow the hosts and directives that the vtex-ads-story-carousel element needs in a store with a Content Security Policy to request ads, send events, and load media.

3 min read

The <vtex-ads-story-carousel> element of the @vtex/ads-stories package reaches several hosts to request ads from the VTEX Ads API, send ad events, and load Story media and product images. If your store has a Content Security Policy (CSP), the policy must allow those hosts. This guide lists each host and its directive, explains how the element's styles work under a CSP, and provides an example policy.

If you haven't installed the package yet, see the VTEX Ads Stories Package Quickstart.

Story ads are off by default. Request enablement for your store through VTEX Support before displaying Stories. For the setup steps, see Before you begin.

Blocked hosts

When the policy blocks a host, the browser reports a CSP violation in its console, and what that host serves is missing:

  • VTEX Ads API host: The element renders nothing.
  • Story media hosts: A card appears without its video.
  • Event host: The events are never counted.

Hosts to allow

Allow each host in the directive listed in the following table:

DirectiveHostUsed for
connect-srchttps://newtail-media.newtail.com.brThe VTEX Ads API, which the element requests the Stories from.
connect-srchttps://events.newtail-media.newtail.com.brThe event URLs (impression_url, view_url, and click_url) in the VTEX Ads API response. See Event host.
connect-srchttps://{account-name}.vtexcommercestable.com.brProduct hydration with the default Intelligent Search strategy. {account-name} is the value of the element's account-name attribute.
media-srchttps://cdn.newtail.com.br and https://cdn2.newtail.com.brStory videos.
img-srchttps://cdn.newtail.com.br and https://cdn2.newtail.com.brStory covers.
img-srcYour store's catalog image hostsProduct images. See Product images.
script-srchttps://unpkg.com or https://cdn.jsdelivr.netOnly when you load the package from the CDN script.

The element sends the ad events with navigator.sendBeacon or fetch, and both follow connect-src.

If your store uses a custom hydration strategy, allow the hosts that its fetcher calls instead of the Intelligent Search host.

A store that builds its own carousel on the VTEX Ads API, instead of using the element, must allow each of the VTEX Ads API, event, and Story media hosts that its pages reach from the browser. See Integrating Story ads.

Event host

The event URLs come in the VTEX Ads API response, and VTEX Ads can set up a publisher with an event host other than the default one. If the events are blocked, check the host of impression_url in the VTEX Ads API response, in the browser's network tab, and allow that host.

Product images

A product's image_url is your store's own catalog image. VTEX Ads sends the URL as is and doesn't copy the image. On VTEX stores, the host is usually https://*.vteximg.com.br or https://*.vtexassets.com. Your store's img-src directive likely allows these hosts already.

Styles

The element doesn't need 'unsafe-inline' in style-src. Its styles are constructable stylesheets in its shadow DOM, and the few styles it sets on elements go through the CSSOM, which a CSP doesn't block.

Browsers without constructable stylesheets (Safari before 16.4) get the styles as <style> elements instead. To keep those styles working without 'unsafe-inline', set the page's nonce in window.litNonce before the element loads:


_10
<script nonce="the-page-nonce">
_10
window.litNonce = "the-page-nonce";
_10
</script>

Example policy

The following policy is for a VTEX store that installs the package from npm. It leaves out the other directives the store already has. Replace {account-name} with the value of the element's account-name attribute.


_10
Content-Security-Policy:
_10
connect-src 'self' https://newtail-media.newtail.com.br
_10
https://events.newtail-media.newtail.com.br
_10
https://{account-name}.vtexcommercestable.com.br;
_10
media-src 'self' https://cdn.newtail.com.br https://cdn2.newtail.com.br;
_10
img-src 'self' https://cdn.newtail.com.br https://cdn2.newtail.com.br
_10
https://*.vteximg.com.br https://*.vtexassets.com;

If you load the package from the CDN script, also add the CDN host you use, https://unpkg.com or https://cdn.jsdelivr.net, to script-src.

Next steps