VTEX Ads Core Package Quickstart
Get started with @vtex/ads-core package for fundamental advertising functionality in any JavaScript environment.
The @vtex/ads-core package provides the fundamental advertising functionality for any JavaScript environment. This package is ideal when you're not using React or need maximum flexibility and control.
Installation
Install the package using npm or yarn:
_10npm install @vtex/ads-core_10# or_10yarn add @vtex/ads-core
Minimal example
Here's a minimal example to get you started:
_35import { getRawAds } from "@vtex/ads-core";_35_35// Configure your ad request_35const adRequest = {_35 identity: {_35 accountName: "your-account-name",_35 publisherId: "your-publisher-id",_35 userId: "user-123",_35 sessionId: "session-456",_35 channel: "web", // optional: 'web' | 'mobile'_35 },_35 search: {_35 term: "smartphone", // optional search term_35 selectedFacets: [_35 // optional filters_35 { key: "brand", value: "Acme" },_35 { key: "category", value: "Tools" },_35 ],_35 skuId: "SKU-123", // optional specific product_35 },_35 placements: {_35 search_top_product: {_35 quantity: 3,_35 types: ["product"],_35 },_35 },_35};_35_35// Get raw ads_35try {_35 const rawAds = await getRawAds(adRequest);_35 console.log("Raw ads:", rawAds.sponsoredProducts);_35} catch (error) {_35 console.error("Failed to fetch ads:", error);_35}