Menu
Guides
Storefront Development

Storefront Development

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/cli package.
  • 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 uses contentSource.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:

_10
yarn add @vtex/faststore-plugin-ads

Add it to plugins in discovery.config.js:

_10
module.exports = {
_10
// ...
_10
plugins: ['@vtex/faststore-plugin-ads'],
_10
}

In a monorepo, install the package in the discovery workspace, where the FastStore CLI can find it in node_modules. Configure the workspace's nohoist rule 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:

_10
mkdir -p cms/faststore/components
_10
cp 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:

_10
module.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:

_10
vtex login {accountName}

Then synchronize the section schema:

_10
vtex 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:
  1. In the VTEX Admin, go to Storefront > Content > All content.
  2. Open the page where the carousel will appear.
  3. Click Add section and select VTEX Ads Stories.
  4. Turn on Show sponsored Stories.
  5. Enter the placement name in Placement.
  6. Configure the other fields as needed. See Section fields.
  7. 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.
FieldKeyTypeRequiredDefaultDescription
Show sponsored StoriesenabledbooleanNoOffEnables the section. When off, the section renders nothing.
HeadingtitlestringNoBlankSets the heading displayed above the carousel.
PlacementplacementstringYesNoneSets 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 cartopenCartOnAddbooleanNoOffOpens the minicart after a shopper adds a Story product to the cart.
Number of StoriesquantityintegerNo8Sets how many Stories to request. Accepted values range from 1 through 20.
Highlight duration (ms)slide-durationintegerNo5000Sets how long each Story stays highlighted before advancing, in milliseconds.
Play the other Stories' videos, mutedinactive-autoplaybooleanNoOffPlays visible Stories without the highlight. These videos remain muted.
Ad request time limit (ms)timeoutintegerNo2000Sets the time limit for the Story ad request, in milliseconds.
Product datahydrationOption: Intelligent Search (current price and stock) or None (ad data only)NoIntelligent 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-timeoutintegerNo5000Sets the time limit for the product data request, in milliseconds.
Add to cart button textlabel-add-to-cartstringNoBlankOverrides the localized add to cart button text.
View product button textlabel-view-productstringNoBlankOverrides the localized view product link text.
Unavailable product button textlabel-unavailablestringNoBlankOverrides the localized disabled button text for an unavailable product.
Sold out textlabel-sold-outstringNoBlankOverrides the localized sold out text.
AppearanceAppearance groupobjectNoBlankGroups the visual settings listed below.
› Font familyfontFamilystringNoBlankSets the carousel font family.
› Text colorcolorTextstringNoBlankSets text color outside the video.
› Secondary text colorcolorMutedstringNoBlankSets secondary text and disabled control colors.
› Card background colorcolorSurfacestringNoBlankSets the product panel, button, and single-Story background color.
› Accent colorcolorAccentstringNoBlankSets the product panel button color.
› Text color on the accentcolorAccentContraststringNoBlankSets the text color on accent buttons.
› Corner radiusradiusstringNoBlankSets 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:
AttributeValue
publisher-idThe publisher ID from vtexAds.publisherId in discovery.config.js.
session-idA random, opaque session UUID stored in the browser. The session lasts 14 days.
user-idA random, opaque shopper UUID stored in the browser.
account-nameThe store ID from the FastStore configuration. This also enables product hydration through Intelligent Search by default.
channelsite
currencyThe currency from the FastStore session.
langThe 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-ads is present in node_modules. In a monorepo, check the discovery workspace.
  • yarn dev starts 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

ProblemPossible causeSolution
VTEX Ads Stories is missing from the CMSThe 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.11The 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 CMSThe 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 nothingShow sponsored Stories is off or Placement is blank.Enable the section and enter a placement name.
The section renders nothingThe 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 nothingThe page isn't served through HTTPS or localhost.Use HTTPS in production or localhost during development.
The section renders nothingStory 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 violationThe 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 outProduct 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 usedThe value was changed without creating a new build.Rebuild and redeploy the storefront.

Next steps