Skip to main content

Add to Cart Event

An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.

DataLayer Example

window.dataLayer.push({
"event": "add_to_cart",
"ecommerce": {
"value": 30.03,
"currency": "USD",
"items": [
{
"item_id": "SKU_12345",
"item_name": "Stan and Friends Tee",
"affiliation": "Google Merchandise Store",
"coupon": "SUMMER_FUN",
"discount": 2.22,
"index": 0,
"item_brand": "Google",
"item_category": "Apparel",
"item_category2": "Adult",
"item_category3": "Shirts",
"item_category4": "Crew",
"item_category5": "Short sleeve",
"item_list_id": "related_products",
"item_list_name": "Related Products",
"item_variant": "green",
"location_id": "ChIJIQBpAG2ahYAR_6128GcTUEo",
"price": 10.01,
"quantity": 1,
"promotion_id": "P_12345",
"promotion_name": "Summer Sale",
"creative_name": "summer_banner2",
"creative_slot": "featured_app_1",
"google_business_vertical": "retail"
}
]
}
});

Event Properties

PropertyTypeConstraintsExamplesDescription
eventstringconst: "add_to_cart"The name of the event indicating a add_to_cart has occurred.
ecommerceobjectEcommerce related data for the purchase event.
ecommerce { }
PropertyTypeConstraintsExamplesDescription
valuenumber30.03, 99.99, 45.5The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.
currencystringrequiredUSD, EUR, GBPThe currency of the items in ISO 4217 three-letter format. Required when value is set.
itemsarrayrequiredThe products added to the cart.
minItems: 1
items [ ]
PropertyTypeConstraintsExamplesDescription
item_idstringSKU_12345, PROD_98765The ID of the item. Either item_id or item_name is required.
item_namestringStan and Friends Tee, Blue Running ShoesThe name of the item. Either item_id or item_name is required.
affiliationstringGoogle Merchandise Store, Nike StoreA product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.
couponstringSUMMER_FUN, WELCOME20, SAVE10The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.
discountnumber2.22, 5, 10.5The monetary value of the discount per unit applied to the item.
indexnumber0, 1, 2The index or position of the item in a list.
item_brandstringGoogle, Nike, AdidasThe brand of the item.
item_categorystringApparel, Footwear, ElectronicsThe category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.
item_category2stringAdult, Women, MenThe second category hierarchy or additional taxonomy of the item.
item_category3stringShirts, Shoes, BootsThe third category hierarchy or additional taxonomy of the item.
item_category4stringCrew, Running, CasualThe fourth category hierarchy or additional taxonomy of the item.
item_category5stringShort sleeve, Long distance, LightweightThe fifth category hierarchy or additional taxonomy of the item.
item_list_idstringrelated_products, search_results, recommendationsThe ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.
item_list_namestringRelated Products, Search Results, Recommended ItemsThe name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.
item_variantstringgreen, Blue Size 10, M-BlackThe item variant or unique code or description for additional item details/options.
location_idstringChIJIQBpAG2ahYAR_6128GcTUEo, store_123, location_sfThe physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.
pricenumber10.01, 21.01, 89.99The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.
quantitynumber1, 2, 3The item quantity. If not set, quantity is set to 1.
promotion_idstringP_12345, PROMO_001The ID of the promotion associated with the item.
promotion_namestringSummer Sale, Black Friday, Flash DealThe name of the promotion associated with the item.
creative_namestringsummer_banner2, holiday_email_v1The name of the promotion creative.
creative_slotstringfeatured_app_1, top_banner, sidebarThe name of the creative slot associated with the item.
google_business_verticalstringretail, ecommerceThe business vertical for the item (e.g., 'retail').
View Raw JSON Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/add-to-cart-event.json",
"title": "Add to Cart Event",
"description": "An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.",
"type": "object",
"allOf": [
{
"$ref": "./components/dataLayer.json"
}
],
"properties": {
"event": {
"type": "string",
"const": "add_to_cart",
"description": "The name of the event indicating a add_to_cart has occurred."
},
"ecommerce": {
"type": "object",
"description": "Ecommerce related data for the purchase event.",
"properties": {
"value": {
"type": "number",
"description": "The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.",
"examples": [
30.03,
99.99,
45.5
]
},
"currency": {
"type": "string",
"description": "The currency of the items in ISO 4217 three-letter format. Required when value is set.",
"examples": [
"USD",
"EUR",
"GBP"
]
},
"items": {
"type": "array",
"description": "The products added to the cart.",
"minItems": 1,
"items": {
"$ref": "./components/product.json"
}
}
},
"required": [
"currency",
"items"
]
}
}
}