Skip to main content
Version: 1.2.0

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.

Using Partials

The main description for this schema should be kept in the original JSON schema file.

Use partials like this one to add supplementary content, such as images, complex markdown, or other React components.

DataLayer Example

window.dataLayer.push({
"$schema": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/add-to-cart-event.json",
"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
$schemastringrequired
"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/add-to-cart-event.json"
Defines the structure of the event. This can be used to validate an event against the schema provided.
const: "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/add-to-cart-event.json"
eventstringrequired
"add_to_cart"
The name of the event indicating a add_to_cart has occurred.
const: "add_to_cart"
{}ecommerceobjectEcommerce related data for the purchase event.
valuenumber
30.03
99.99
45.5
The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.
currencystringrequired
"USD"
"EUR"
"GBP"
The currency of the items in ISO 4217 three-letter format. Required when value is set.
[]itemsarrayrequiredThe products added to the cart.
minItems: 1
item_idstring
"SKU_12345"
"PROD_98765"
The ID of the item. Either item_id or item_name is required.
item_namestring
"Stan and Friends Tee"
"Blue Running Shoes"
The name of the item. Either item_id or item_name is required.
affiliationstring
"Google Merchandise Store"
"Nike Store"
A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.
couponstring
"SUMMER_FUN"
"WELCOME20"
"SAVE10"
The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.
discountnumber
2.22
5
10.5
The monetary value of the discount per unit applied to the item.
indexnumber
0
1
2
The index or position of the item in a list.
item_brandstring
"Google"
"Nike"
"Adidas"
The brand of the item.
item_categorystring
"Apparel"
"Footwear"
"Electronics"
The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.
item_category2string
"Adult"
"Women"
"Men"
The second category hierarchy or additional taxonomy of the item.
item_category3string
"Shirts"
"Shoes"
"Boots"
The third category hierarchy or additional taxonomy of the item.
item_category4string
"Crew"
"Running"
"Casual"
The fourth category hierarchy or additional taxonomy of the item.
item_category5string
"Short sleeve"
"Long distance"
"Lightweight"
The fifth category hierarchy or additional taxonomy of the item.
item_list_idstring
"related_products"
"search_results"
"recommendations"
The 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_namestring
"Related Products"
"Search Results"
"Recommended Items"
The 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_variantstring
"green"
"Blue Size 10"
"M-Black"
The item variant or unique code or description for additional item details/options.
location_idstring
"ChIJIQBpAG2ahYAR_6128GcTUEo"
"store_123"
"location_sf"
The 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.
pricenumber
10.01
21.01
89.99
The 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.
quantitynumberdefault: 1
1
2
3
The item quantity. If not set, quantity is set to 1.
promotion_idstring
"P_12345"
"PROMO_001"
The ID of the promotion associated with the item.
promotion_namestring
"Summer Sale"
"Black Friday"
"Flash Deal"
The name of the promotion associated with the item.
creative_namestring
"summer_banner2"
"holiday_email_v1"
The name of the promotion creative.
creative_slotstring
"featured_app_1"
"top_banner"
"sidebar"
The name of the creative slot associated with the item.
google_business_verticalstring
"retail"
"ecommerce"
The business vertical for the item (e.g., 'retail').
View Raw JSON Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/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": "./events/components/dataLayer.json"
}
],
"required": [
"$schema",
"event"
],
"properties": {
"$schema": {
"type": "string",
"description": "Defines the structure of the event. This can be used to validate an event against the schema provided.",
"const": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/add-to-cart-event.json"
},
"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.",
"required": [
"currency",
"items"
],
"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": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://tracking-docs-demo.buchert.digital/schemas/1.2.0/events/components/product.json",
"title": "A Product",
"description": "A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.",
"type": "object",
"required": [],
"properties": {
"item_id": {
"type": "string",
"description": "The ID of the item. Either item_id or item_name is required.",
"examples": [
"SKU_12345",
"PROD_98765"
]
},
"item_name": {
"type": "string",
"description": "The name of the item. Either item_id or item_name is required.",
"examples": [
"Stan and Friends Tee",
"Blue Running Shoes"
]
},
"affiliation": {
"type": "string",
"description": "A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.",
"examples": [
"Google Merchandise Store",
"Nike Store"
]
},
"coupon": {
"type": "string",
"description": "The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.",
"examples": [
"SUMMER_FUN",
"WELCOME20",
"SAVE10"
]
},
"discount": {
"type": "number",
"description": "The monetary value of the discount per unit applied to the item.",
"examples": [
2.22,
5,
10.5
]
},
"index": {
"type": "number",
"description": "The index or position of the item in a list.",
"examples": [
0,
1,
2
]
},
"item_brand": {
"type": "string",
"description": "The brand of the item.",
"examples": [
"Google",
"Nike",
"Adidas"
]
},
"item_category": {
"type": "string",
"description": "The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.",
"examples": [
"Apparel",
"Footwear",
"Electronics"
]
},
"item_category2": {
"type": "string",
"description": "The second category hierarchy or additional taxonomy of the item.",
"examples": [
"Adult",
"Women",
"Men"
]
},
"item_category3": {
"type": "string",
"description": "The third category hierarchy or additional taxonomy of the item.",
"examples": [
"Shirts",
"Shoes",
"Boots"
]
},
"item_category4": {
"type": "string",
"description": "The fourth category hierarchy or additional taxonomy of the item.",
"examples": [
"Crew",
"Running",
"Casual"
]
},
"item_category5": {
"type": "string",
"description": "The fifth category hierarchy or additional taxonomy of the item.",
"examples": [
"Short sleeve",
"Long distance",
"Lightweight"
]
},
"item_list_id": {
"type": "string",
"description": "The 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.",
"examples": [
"related_products",
"search_results",
"recommendations"
]
},
"item_list_name": {
"type": "string",
"description": "The 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.",
"examples": [
"Related Products",
"Search Results",
"Recommended Items"
]
},
"item_variant": {
"type": "string",
"description": "The item variant or unique code or description for additional item details/options.",
"examples": [
"green",
"Blue Size 10",
"M-Black"
]
},
"location_id": {
"type": "string",
"description": "The 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.",
"examples": [
"ChIJIQBpAG2ahYAR_6128GcTUEo",
"store_123",
"location_sf"
]
},
"price": {
"type": "number",
"description": "The 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.",
"examples": [
10.01,
21.01,
89.99
]
},
"quantity": {
"type": "number",
"description": "The item quantity. If not set, quantity is set to 1.",
"examples": [
1,
2,
3
],
"default": 1
},
"promotion_id": {
"type": "string",
"description": "The ID of the promotion associated with the item.",
"examples": [
"P_12345",
"PROMO_001"
]
},
"promotion_name": {
"type": "string",
"description": "The name of the promotion associated with the item.",
"examples": [
"Summer Sale",
"Black Friday",
"Flash Deal"
]
},
"creative_name": {
"type": "string",
"description": "The name of the promotion creative.",
"examples": [
"summer_banner2",
"holiday_email_v1"
]
},
"creative_slot": {
"type": "string",
"description": "The name of the creative slot associated with the item.",
"examples": [
"featured_app_1",
"top_banner",
"sidebar"
]
},
"google_business_vertical": {
"type": "string",
"description": "The business vertical for the item (e.g., 'retail').",
"examples": [
"retail",
"ecommerce"
]
}
}
}
}
}
}
}
}
Prefer JSON for Descriptions

Whenever possible, keep descriptions and other schema-related information within the JSON schema file itself.

Why? This ensures that the schema is a single, self-contained source of truth. It makes the schema more portable and easier to use with other tools that might not be aware of these documentation partials.