Skip to main content

Event: Add to Cart

The Add to Cart event is used to track customer cart addition activities. This event is important for understanding purchase intent and abandoned cart analysis, which are critical for conversion optimization and personalization.

API Endpoint

Method: POST
URL: https://<PA_END_POINT>/3.0/events/add-to-carts

Request Header

NameValue
Content-Typeapplication/json
AuthorizationBearer ACCESS_TOKEN

Request Parameters (Body)

ParameterTypeRequiredDescription
customerIdGUIDUnique identifier for the customer, obtained from the Config API. This identifier persists throughout the customer's lifetime on the platform. For details on retrieving a customer ID, please refer to the Config API documentation.
sessionIdGUIDUnique identifier for the session, consistent throughout the session's duration. For information on obtaining a session ID, please refer to the Config API documentation.
eventsArray of objectsArray of objects detailing add to cart events. Each add to cart event object contains the following properties:

Event Object Definition

ParameterTypeRequiredDescription
currentUrlstringURL of the page where the product was added to cart.
eventTimedateTimeUTC timestamp of when the product was added to cart.
productobjectObject containing product information.
product.refIdstringUnique identifier for the product added to cart.
product.quantityintegerQuantity of the product added to cart.
product.pricenumberPrice of the product added to cart.
referralUrlstringURL that referred the user to the page where they added the product.
clickIdGUIDUnique identifier for the click event that led to this add to cart.
widgetIdGUIDIdentifier for the widget a slot belongs to. This information is available as part of the Recommendations API response payload.
routeIdGUIDRoute identifier that led to the widget display. This information is available as part of the Recommendations API response payload.
recommenderIdGUIDIdentifier of the recommender that populated the slot.
campaignIdGUIDIdentifier of the campaign that populated the slot.
tacticIdGUIDIdentifier of the tactic that populated the slot.
tacticLabelstringHuman-readable label for the tactic that populated the slot.
bannerIdGUIDIdentifier of the banner if the add to cart is related to a banner element.
placementIdGUIDIdentifier for the placement position where the add to cart occurred.
keywordIdGUIDIdentifier for the keyword that triggered the recommendation leading to the add to cart.
Route, Widget & Tactic

Route ID, Widget ID and Tactic ID are important for tracking the performance and effectiveness of the recommendation strategies. These are available as part of the Recommendations API response payload from where the slot's data was collected. Please refer to the Recommendations API documentation and Personalization Overview page for more information.

Retailer Boost Campaign

The following properties are related to the Retailer Boost event tracking and are used for Retailer Boost analytics and reporting.

ParameterTypeRequiredDescription
retailBoostCollectionCampaignIdGUIDThe identifier of the Retailer Boost Collection Campaign. This is provided as part of the slot data for the product in the Recommendations API response payload.

Retail Media

The following properties are related to the Retail Media event tracking and are used for Retail Media analytics and spend calculation.

ParameterTypeRequiredDescription
adSetIdGUIDThe identifier of the Ad Set. This is provided as part of the slot data for the product in the Recommendations API response payload.
adSetVersionintegerThe version of the Ad Set. This is provided as part of the slot data for the product in the Recommendations API response payload.
costPerClickdecimalThe cost per click on a sponsored slot. This is provided as part of the slot data for the product in the Recommendations API response payload.
costPerActiondecimalThe cost per action on a sponsored slot, if applicable. This is provided as part of the slot data for the product in the Recommendations API response payload.
costPerMilledecimalThe cost per mille on a sponsored slot, if applicable. This is provided as part of the slot data for the product in the Recommendations API response payload.
timeStamptimestampThe timestamp provided as part of the product's slot data in the Recommendations API response payload. This is the timestamp when the slot was populated.
hmacSaltstringString of 16 random characters generated by recommender. Used for calculating and validating HMAC field. This is provided as part of the slot data for the product in the Recommendations API response payload.
hmacstringThe hash-based message authentication code (HMAC) generated using the adSetId, hmacSalt, costPerClick, timeStamp. This is used to validate the authenticity of the slot impression event. This is provided as part of the slot data for the product in the Recommendations API response payload.
supplierIdGUIDThe identifier of the supplier associated with the retail media campaign.
note

If sending Retail Media tracking data, the cost parameters, timestamp, and HMAC-related fields are recommended to be included for proper analytics.

The keywordId is only needed if the Retail Media slot was populated as part of a Keyword Targeting campaign.

Example Request Payload

{
"customerId": "xxxxxxxxxxxxxxxxxxxxxxx",
"sessionId": "xxxxxxxxxxxxxxxxxxxxxxx",
"events": [
{
"currentUrl": "https://www.example.com/products/product-123",
"eventTime": "2024-03-01T14:00:00.000Z",
"product": {
"refId": "product-123",
"quantity": 2,
"price": 49.99
},
"referralUrl": "https://www.example.com/category/clothing",
"clickId": "xxxxxxxxxxxxxxxxxxxxxxx",
"widgetId": "xxxxxxxxxxxxxxxxxxxxxxx",
"routeId": "xxxxxxxxxxxxxxxxxxxxxxx",
"recommenderId": "xxxxxxxxxxxxxxxxxxxxxxx",
"campaignId": "xxxxxxxxxxxxxxxxxxxxxxx",
"tacticId": "xxxxxxxxxxxxxxxxxxxxxxx",
"tacticLabel": "Featured Products",

// Retailer Boost event tracking
"retailBoostCollectionCampaignId": "xxxxxxxxxxxxxxxxxxxxxxx",

// Retail Media event tracking
"adSetId": "xxxxxxxxxxxxxxxxxxxxxxx",
"adSetVersion": 1,
"costPerClick": 0.5,
"costPerAction": 1.0,
"costPerMille": 0.25,
"timeStamp": 638481477292391000,
"hmacSalt": "xxxxxxxxxxxxxxxxxxxxxxx",
"hmac": "xxxxxxxxxxxxxxxxxxxxxxx"
}
]
}

Response

On Success

On successful post, the returned status code will be 202, and the payload will contain the status message "Accepted" and a transaction ID.

{
"transactionId": "xxxxxxxxxxxxxxxxxxxxxxx",
"status": "Accepted"
}

On Error

If there are any errors, the response status code will not be 202, and the relevant error messages will be provided as part of "errors" in the returned message. Here is an example:

{
"errors": {
"events[0].Product.RefId": [
"'RefId' must not be empty."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "xxxxxxxxxxxxxxxxxxx"
}

Example Usage (JavaScript)

Here's an example code snippet using JavaScript's Fetch API:

const url = 'https://<PA_END_POINT>/3.0/events/add-to-carts';
const accessToken = 'YOUR_ACCESS_TOKEN'; // Replace with your actual access token
const body = {
customerId: 'xxxxxxxxxxxxxxxxxxxxxxx',
sessionId: 'xxxxxxxxxxxxxxxxxxxxxxx',
events: [
{
currentUrl: 'https://www.example.com/products/product-123',
eventTime: '2024-03-01T14:00:00.000Z',
product: {
refId: 'product-123',
quantity: 2,
price: 49.99
},
widgetId: 'xxxxxxxxxxxxxxxxxxxxxxx',
routeId: 'xxxxxxxxxxxxxxxxxxxxxxx',
recommenderId: 'xxxxxxxxxxxxxxxxxxxxxxx',

// Retail Media tracking
adSetId: 'xxxxxxxxxxxxxxxxxxxxxxx',
adSetVersion: 1,
costPerClick: 0.5,
timeStamp: 638481477292391000,
hmacSalt: 'xxxxxxxxxxxxxxxxxxxxxxx',
hmac: 'xxxxxxxxxxxxxxxxxxxxxxx'
}
]
};

fetch(url, {
method: 'POST',
headers: {
"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/json"
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => console.log('Add to Cart Recorded:', data))
.catch(error => console.error('Error recording Add to Cart:', error));

Summary

This document provides details about the Add to Cart API, which is essential for tracking user purchase intent in your eCommerce application:

  • The API is used to capture customer add to cart activities for analytics, personalization, and abandoned cart analysis
  • The endpoint uses a POST method with URL https://<PA_END_POINT>/3.0/events/add-to-carts
  • Required parameters include customer ID, session ID, current URL, event time, and product information (refId and quantity)
  • Optional parameters allow for more detailed tracking, including widget, route, and campaign information
  • Special parameters for retail media and retailer boost provide comprehensive attribution
  • The API returns a 202 status code with a transaction ID on successful recording
  • Error responses include relevant error messages and a 400 status code