Documentation
Feedback
Guides
API Reference

Guides
Guides

Retrieving ads

Learn how to fetch relevant ads based on context like search terms, categories, or behavior.

The VTEX Ads API allows you to retrieve three types of ad formats:

  • Sponsored products (Product ads)
  • Sponsored brands
  • Banner / Display ads

Use the POST Get ads endpoint to fetch both formats through a unified interface.

Responses are cached for 10 minutes.

All ad requests require:

  • A context (search, category, brand, product, or home)
  • User identification (user_id and session_id)
  • Placement configuration

Learn more about each field in the API Reference.

Request best practices

  • HTTP persistence: Prefer persistent connections (Connection: keep-alive).
  • Timeout: Apply a 500–600 ms timeout to the ad query.

Context and ad eligibility rules

It's not possible to filter by specific placement. Ad selection is based on context and request parameters.

Understanding which ad types are eligible for each context is crucial for setting up your ad requests correctly.

Search context

Used when retrieving ads for search results pages.

Eligible ad types:

  • Banner/Video/Sponsored Brands Ads that are keyword-based.
  • Sponsored Products (any product campaign).

Keyword matching in the search context is exact (no stemming/synonyms). This means the advertiser must specify exactly which keywords they want to use in Banner/Video/Sponsored Brands campaigns. If a user searches for "nike shoes", the ad will only be eligible if the advertiser registered exactly the keyword "nike shoes". There is no approximate matching or similar word matching.


_11
{
_11
"context": "search",
_11
"term": "desodorante",
_11
"user_id": "6a746448-cf59-42bc-aa3d-a426844ad115",
_11
"session_id": "f361661f-5986-4779-9009-a34562f18347",
_11
"tags": ["Mega Maio"],
_11
"placements": {
_11
"placementName1": { "quantity": 1, "size": "desktop", "types": ["banner"] },
_11
"placementName2": { "quantity": 2, "size": "tamanho3", "types": ["product"] }
_11
}
_11
}

Category context

Used for category pages.

Eligible ad types:

  • Banner/Video/Sponsored Brands Ads that use the corresponding category.
  • Sponsored Products from the category.

_10
{
_10
"context": "category",
_10
"category_name": "Telefones e Celulares > Smartphones > iPhone",
_10
"user_id": "6a746448-cf59-42bc-aa3d-a426844ad115",
_10
"session_id": "f361661f-5986-4779-9009-a34562f18347",
_10
"placements": {
_10
"placementName1": { "quantity": 1, "size": "tamanho1", "types": ["banner"] },
_10
"placementName2": { "quantity": 2, "size": "tamanho3", "types": ["product"] }
_10
}
_10
}

Brand context

Used for brand-specific pages.

Eligible ad types:

  • Banner/Video/Sponsored Brands Ads for the brand.
  • Sponsored Products from the brand.

_10
{
_10
"context": "brand",
_10
"brand_name": "iphone",
_10
"user_id": "6a746448-cf59-42bc-aa3d-a426844ad115",
_10
"session_id": "f361661f-5986-4779-9009-a34562f18347",
_10
"placements": {
_10
"placementName1": { "quantity": 1, "size": "tamanho1", "types": ["banner"] },
_10
"placementName2": { "quantity": 2, "size": "tamanho3", "types": ["product"] }
_10
}
_10
}

Product context (PDP)

Used on product detail pages.

Eligible ad types:

  • Sponsored Products related to the viewed product.

_14
{
_14
"context": "product_page",
_14
"product_sku": "120210",
_14
"product_attributes": {
_14
"category_name": "Telefones e Celulares > Smartphones > iPhone",
_14
"brand": "iphone"
_14
},
_14
"user_id": "6f92d1e9-00b6-4f8b-9645-faeab321e1cc",
_14
"session_id": "5898b8d1-c250-4bb5-931b-8b9d0ee7b499",
_14
"placements": {
_14
"placementName1": { "quantity": 1, "size": "tamanho1", "types": ["banner"] },
_14
"placementName2": { "quantity": 2, "size": "tamanho3", "types": ["product"] }
_14
}
_14
}

Home context

Used for homepage or non-targeted contexts. Shows ads most relevant to the user based on their history.

Eligible ad types:

  • Banner/Video/Sponsored Brands Ads that use category as a targeting criterion.
  • Sponsored Products.

_10
{
_10
"context": "home",
_10
"user_id": "6f92d1e9-00b6-4f8b-9645-faeab321e1cc",
_10
"session_id": "5898b8d1-c250-4bb5-931b-8b9d0ee7b499",
_10
"placements": {
_10
"placementName1": { "quantity": 1, "size": "tamanho1", "types": ["banner"] },
_10
"placementName2": { "quantity": 2, "size": "tamanho3", "types": ["product"] }
_10
}
_10
}

Response structure

Successful responses return HTTP code 200.

The response is a dictionary where:

  • Each key corresponds to a placement name from the request.
  • Results maintain the same order as the query.
  • Each ad includes tracking URLs for clicks, impressions and views.

Standard ad response example


_13
{
_13
"placementName1": [
_13
{
_13
"ad_id": "6d2d8837-bf5a-4ba4-90d2-5546cb18d5ce",
_13
"media_url": "https://cdn.newtail.com.br/retail_media/ads/2023/05/03/f97a938660e56fe38a9c9ade21c27df8-1280x256-red.png",
_13
"destination_url": null,
_13
"type": "banner",
_13
"click_url": "https://events.newtail-media.newtail.com.br/v1/beacon/click/6d2d8837-bf5a-4ba4-90d2-5546cb18d5ce?publisher_id=0d675bf6-03f6-4b81-9617-e79dffddc3ab&ad_type=banner",
_13
"impression_url": "https://events.newtail-media.newtail.com.br/v1/beacon/impression/6d2d8837-bf5a-4ba4-90d2-5546cb18d5ce?publisher_id=0d675bf6-03f6-4b81-9617-e79dffddc3ab&ad_type=banner",
_13
"view_url": "https://events.newtail-media.newtail.com.br/v1/beacon/view/6d2d8837-bf5a-4ba4-90d2-5546cb18d5ce?publisher_id=0d675bf6-03f6-4b81-9617-e79dffddc3ab&ad_type=banner"
_13
}
_13
]
_13
}

Sponsored brands campaigns have a different response format that includes brand information and related products.

🚧 All events must be triggered for both the ad and its products.

Request example:


_10
{
_10
"context": "search",
_10
"term": "smartphone",
_10
"placements": {
_10
"placement_name": { "quantity": 1, "types": ["sponsored_brand"] }
_10
}
_10
}

Response example:


_34
{
_34
"placement_name": [
_34
{
_34
"type": "sponsored_brand",
_34
"assets": [
_34
{
_34
"type": "image|video",
_34
"url": "Image URL"
_34
}
_34
],
_34
"brand_url": "https://cdn.newtail.com.br/retail_media/brands/logo.jpeg",
_34
"brand_name": "Apple",
_34
"destination_url": "https://www.extra.com.br/c?Filter=D70653",
_34
"headline": "Titanium. Very robust, very light, very pro!",
_34
"description": "",
_34
"view_url": "VIEW URL",
_34
"impression_url": "IMPRESSION URL",
_34
"click_url": "CLICK URL",
_34
"products": [
_34
{
_34
"image_url": "PRODUCT IMAGE URL",
_34
"seller_id": null,
_34
"product_metadata": { },
_34
"product_name": "iPhone 15 Pro MAX",
_34
"product_sku": "55064355",
_34
"destination_url": "PRODUCT URL",
_34
"impression_url": "IMPRESSION URL for a specific PRODUCT",
_34
"view_url": "VIEW URL for a specific PRODUCT",
_34
"click_url": "CLICK URL for a specific PRODUCT"
_34
}
_34
]
_34
}
_34
]
_34
}

Best practices

Placement naming

Adopt a clear standard, such as {channel}_{context}_{position}_{type} (e.g., msite_search_top-shelf_product).

Examples:

  • site_home_middle_banner
  • msite_product_top-shelf_product
  • app_search_top-shelf_product
  • site_category_bottom-shelf_banner

IAB standard image sizes

For banner-type ads, use images in the standard formats defined by the IAB (Interactive Advertising Bureau) to ensure compatibility and a better visual experience:

  • Medium Rectangle: 300x250 pixels
  • Leaderboard: 728x90 pixels
  • Wide Skyscraper: 160x600 pixels
  • Mobile Leaderboard: 320x50 pixels
  • Billboard: 970x250 pixels
  • Half Page: 300x600 pixels

Video size options

For video ad requests, specify the size parameter to filter by video resolution:

  • 1080p (1920x1080 pixels) - Recommended only for full-screen videos
  • 720p (1280x720 pixels) - Recommended only for full-screen videos
  • 480p (854x480 pixels)
  • 360p (640x360 pixels)
  • 320p (568x320 pixels) - Recommended for mobile devices

Use only the resolution identifier (e.g., "720p") in the size parameter, not the full dimensions.

Ad targeting

Target ads to specific audiences to increase relevance by sending demographic or audience data directly in the body of the ad query using the segmentation field.

The segmentation field is an array of objects, where each object contains:

  • key: The type of segmentation (e.g., "STATE", "CITY", "GENDER").
  • values: Array of values for the segmentation.

Segmentation example


_24
{
_24
"context": "search",
_24
"term": "smartphone",
_24
"segmentation": [
_24
{
_24
"key": "STATE",
_24
"values": ["CA"]
_24
},
_24
{
_24
"key": "CITY",
_24
"values": ["San Francisco"]
_24
},
_24
{
_24
"key": "GENDER",
_24
"values": ["M"]
_24
}
_24
],
_24
"placements": {
_24
"site_search_top_product": {
_24
"quantity": 5,
_24
"types": ["product"]
_24
}
_24
}
_24
}

Available segmentation types:

  • STATE - User's state (e.g., "CA", "NY", "TX").
  • CITY - User's city (e.g., "San Francisco", "New York").
  • GENDER - User's gender (e.g., "M", "F").
  • AGE - User's age (e.g., "22", "35").
  • AUDIENCES - Custom audience (e.g., "high_value_customers", "cart_abandoners").
  • NBO_CATEGORIES - Possible categories the user intends to buy (e.g., "Electronics", "Books").

Response codes and errors

  • 200 OK: Query processed successfully (returns JSON per placement).
  • 422 Unprocessable Entity: Field validation error.
  • 400 Bad Request / 404 Not Found: Invalid request or resource not found.
  • 429 Too Many Requests: Rate limit exceeded.
  • 5xx: Internal errors.
Contributors
1
Photo of the contributor
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
1
Photo of the contributor
Was this helpful?
Suggest edits (GitHub)
On this page