Implementing VTEX Ads Stories in FastStore
Install and configure the VTEX Ads plugin to add a Story ads section with cart and analytics support to a FastStore storefront.
8 min read
In this guide, you'll learn how to install and configure the
@vtex/faststore-plugin-ads plugin and add VTEX Ads Stories to a FastStore storefront.The plugin provides the VTEX Ads Stories CMS section, which renders the
@vtex/ads-stories carousel. It also connects the carousel's commerce events to the FastStore cart and analytics. The plugin currently provides only the Stories section.Story ads are off by default. Before your store can show them, open a ticket with VTEX Support to request Story enablement for your store (for a network, it's enabled once for the whole network). Then, on the VTEX Ads platform, select Story in Settings > Ad types and add Story to the ad types of each advertiser that can run Story campaigns in Settings > Advertisers.
Before you begin
Make sure your store meets these requirements:
- FastStore 4.7 or later. Stores on versions 4.4 through 4.6 must first update the
@faststore/clipackage. - A FastStore project onboarded through WebOps.
- The CMS for FastStore storefronts, configured with
contentSource.type: "CP". - The VTEX Ads publisher ID provided by your VTEX Ads contact during implementation.
- A placement name chosen by your store, such as
home_stories. - HTTPS in production. Local development can use
localhost.
The plugin doesn't support Headless CMS (legacy), which usescontentSource.type: "CMS".
You don't need to register a placement before using its name. Registration on the VTEX Ads platform is optional and lets you filter results and view performance by placement. A store can use multiple placement names, but every Story placement currently returns the same Stories.
Instructions
Step 1 - Install the plugin
From the root of your FastStore project, install the plugin:
_10yarn add @vtex/faststore-plugin-ads
Add it to
plugins in discovery.config.js:
_10module.exports = {_10 // ..._10 plugins: ['@vtex/faststore-plugin-ads'],_10}
In a monorepo, install the package in thediscoveryworkspace, where the FastStore CLI can find it innode_modules. Configure the workspace'snohoistrule if your package manager would otherwise hoist the plugin.
FastStore 4.7 through 4.11
On FastStore versions 4.7 through 4.11, copy the plugin's CMS schema into the store before synchronizing the CMS:
_10mkdir -p cms/faststore/components_10cp node_modules/@vtex/faststore-plugin-ads/cms/faststore/components/*.jsonc cms/faststore/components/
Repeat the copy after upgrading the plugin in case its schema changed.
On FastStore 4.12 or later, the CLI merges schemas supplied by plugins automatically. Skip the copy step on these versions.
Step 2 - Configure the publisher ID
In
discovery.config.js, set the VTEX Ads publisher ID with a literal value or a NEXT_PUBLIC_ environment variable:
_10module.exports = {_10 // ..._10 plugins: ['@vtex/faststore-plugin-ads'],_10 vtexAds: {_10 publisherId: process.env.NEXT_PUBLIC_VTEX_ADS_PUBLISHER_ID,_10 },_10}
Set
NEXT_PUBLIC_VTEX_ADS_PUBLISHER_ID in WebOps > Variables and Secrets. The publisher ID isn't a secret because the browser sends it to the ad server. The NEXT_PUBLIC_ prefix is required for the value to reach the browser. Other process.env values are unavailable there, and the section renders nothing.Changing the publisher ID requires a new storefront build.
Step 3 - Synchronize the CMS section
Log in to your VTEX account:
_10vtex login {accountName}
Then synchronize the section schema:
_10vtex faststore cms-sync
The command detects the store's content source, generates the schema, and prompts you to confirm the store ID and schema version before publishing. To test the section in an Admin branch first, upload a prerelease schema version, such as
1.13.0-beta.1, and select that version in the branch.On FastStore 4.12 or later, the command includes the plugin schema automatically. On versions 4.7 through 4.11, it includes the schema copied in Step 1.
For details about the prompts and schema synchronization, see Creating a new section.
Step 4 - Add the section to a page
After synchronizing the schema, add the VTEX Ads Stories section:
- In the VTEX Admin, go to Storefront > Content > All content.
- Open the page where the carousel will appear.
- Click
Add sectionand select VTEX Ads Stories. - Turn on Show sponsored Stories.
- Enter the placement name in Placement.
- Configure the other fields as needed. See Section fields.
- Save and publish the page.
The section renders only after Show sponsored Stories is on and Placement has a value.
Section fields
Only Placement is required. Blank optional fields keep the underlying
<vtex-ads-story-carousel> element's defaults. Fields prefixed with › belong to the Appearance group.| Field | Key | Type | Required | Default | Description |
|---|---|---|---|---|---|
| Show sponsored Stories | enabled | boolean | No | Off | Enables the section. When off, the section renders nothing. |
| Heading | title | string | No | Blank | Sets the heading displayed above the carousel. |
| Placement | placement | string | Yes | None | Sets the placement name used in the Story request, such as home_stories. Every Story placement currently returns the same Stories. |
| Open the minicart after add to cart | openCartOnAdd | boolean | No | Off | Opens the minicart after a shopper adds a Story product to the cart. |
| Number of Stories | quantity | integer | No | 8 | Sets how many Stories to request. Accepted values range from 1 through 20. |
| Highlight duration (ms) | slide-duration | integer | No | 5000 | Sets how long each Story stays highlighted before advancing, in milliseconds. |
| Play the other Stories' videos, muted | inactive-autoplay | boolean | No | Off | Plays visible Stories without the highlight. These videos remain muted. |
| Ad request time limit (ms) | timeout | integer | No | 2000 | Sets the time limit for the Story ad request, in milliseconds. |
| Product data | hydration | Option: Intelligent Search (current price and stock) or None (ad data only) | No | Intelligent Search (current price and stock) | Selects whether the section retrieves current product data through Intelligent Search or uses only the ad response. |
| Product request time limit (ms) | hydration-timeout | integer | No | 5000 | Sets the time limit for the product data request, in milliseconds. |
| Add to cart button text | label-add-to-cart | string | No | Blank | Overrides the localized add to cart button text. |
| View product button text | label-view-product | string | No | Blank | Overrides the localized view product link text. |
| Unavailable product button text | label-unavailable | string | No | Blank | Overrides the localized disabled button text for an unavailable product. |
| Sold out text | label-sold-out | string | No | Blank | Overrides the localized sold out text. |
| Appearance | Appearance group | object | No | Blank | Groups the visual settings listed below. |
| › Font family | fontFamily | string | No | Blank | Sets the carousel font family. |
| › Text color | colorText | string | No | Blank | Sets text color outside the video. |
| › Secondary text color | colorMuted | string | No | Blank | Sets secondary text and disabled control colors. |
| › Card background color | colorSurface | string | No | Blank | Sets the product panel, button, and single-Story background color. |
| › Accent color | colorAccent | string | No | Blank | Sets the product panel button color. |
| › Text color on the accent | colorAccentContrast | string | No | Blank | Sets the text color on accent buttons. |
| › Corner radius | radius | string | No | Blank | Sets the corner radius for cards, pills, panels, and related controls. |
For the behavior and limits of the carousel options, see VTEX Ads Stories Package Configuration. See Layout and player for carousel and sold-out behavior, and Product hydration for product prices and availability.
Values set by the plugin
The plugin supplies these element attributes, so they aren't editable in the CMS:
| Attribute | Value |
|---|---|
publisher-id | The publisher ID from vtexAds.publisherId in discovery.config.js. |
session-id | A random, opaque session UUID stored in the browser. The session lasts 14 days. |
user-id | A random, opaque shopper UUID stored in the browser. |
account-name | The store ID from the FastStore configuration. This also enables product hydration through Intelligent Search by default. |
channel | site |
currency | The currency from the FastStore session. |
lang | The language from the FastStore session. |
If browser storage isn't available, the plugin creates new IDs for each page view. The generated IDs don't contain personal data. Don't replace them with an email address, name, phone number, document number, or a hash of any of these values. See Session and user IDs.
Cart and analytics behavior
The plugin listens to the carousel's add-to-cart and remove-from-cart events. You don't need to add event listeners to connect Stories to the FastStore cart.
When a shopper adds a product, the plugin updates an existing cart line or retrieves the product and adds a new line. Cart lines are identified by SKU and seller. The plugin uses the seller from the Story when available, or the product's first offer otherwise. Invalid cart changes are ignored.
The plugin also sends the Google Analytics 4
add_to_cart and remove_from_cart events through the FastStore SDK. If Open the minicart after add to cart is enabled, adding a product opens the minicart.To listen to the commerce events for another integration, see VTEX Ads Stories Package Events.
Verify the integration
Check the following:
@vtex/faststore-plugin-adsis present innode_modules. In a monorepo, check thediscoveryworkspace.yarn devstarts without plugin or schema errors.- VTEX Ads Stories appears in the CMS after synchronization.
- The published page displays the carousel when eligible Stories are available.
- Adding a Story product updates the FastStore cart.
- The minicart opens after an addition when Open the minicart after add to cart is enabled.
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| VTEX Ads Stories is missing from the CMS | The schema wasn't synchronized or published. | Run vtex faststore cms-sync, confirm the store ID and schema version, and publish the schema. |
| VTEX Ads Stories is missing from the CMS on versions 4.7 through 4.11 | The plugin schema wasn't copied into the store. | Repeat the schema copy from Step 1, then synchronize again. |
| VTEX Ads Stories is missing from the CMS | The store uses Headless CMS (legacy) or a FastStore version earlier than 4.7. | Use the CMS with contentSource.type: "CP" and upgrade FastStore to version 4.7 or later. |
| The section renders nothing | Show sponsored Stories is off or Placement is blank. | Enable the section and enter a placement name. |
| The section renders nothing | The publisher ID is missing or uses an environment variable without the NEXT_PUBLIC_ prefix. | Set vtexAds.publisherId to a literal or a NEXT_PUBLIC_ variable, then create a new build. |
| The section renders nothing | The page isn't served through HTTPS or localhost. | Use HTTPS in production or localhost during development. |
| The section renders nothing | Story ads aren't enabled or no eligible Stories are available. | Complete the Story enablement steps and confirm that the store has an approved, eligible Story campaign. |
| The browser reports a CSP violation | The policy blocks an API, event, media, or product data host. | Follow VTEX Ads Stories Package Content Security Policy. |
| Prices are outdated or available products show as Sold out | Product hydration is disabled, timed out, or uses the Intelligent Search stock rule. | Review Product data and Product request time limit (ms), then see Product hydration. |
| A changed publisher ID isn't used | The value was changed without creating a new build. | Rebuild and redeploy the storefront. |
Next steps
- VTEX Ads Stories Package Quickstart: Learn about the web component rendered by the plugin.
- VTEX Ads Stories Package Configuration: Review the carousel attributes, labels, language, and visual settings.
- VTEX Ads Stories Package Layout and Player: Understand carousel, player, destination, and sold-out behavior.
- VTEX Ads Stories Package Product Hydration: Understand product prices and availability.
- VTEX Ads Stories Package Events: Review commerce and ad events.
- VTEX Ads Stories Package Content Security Policy: Allow the hosts required by the integration.
- VTEX Ads JavaScript SDK: Explore the SDK used by custom storefront integrations.