Sub topic 3
The items array: describing products in an event
This chapter covers how GA4 describes products inside an e-commerce event. It assumes you know what a GA4 event and parameter are, can read JavaScript objects and arrays, and can read JSON. Item-level parameters such as price and category get a fuller treatment in the next chapter. Here the focus is on the array itself: its shape, its limits, and how GA4 uses it.
What the items array is
An event such as add_to_cart has event-level parameters like currency and value. Those describe the event as a whole. A cart can hold several products, so GA4 needs a place to describe each product. That place is the items parameter, an array of objects. Each object is one product line.
Event-level parameters answer "what happened and how much was it worth?". The items array answers "which products were involved?".
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 49.98,
items: [
{
item_id: 'SKU_1001',
item_name: 'Trail Running Shoe',
item_brand: 'Acme',
item_category: 'Shoes',
item_variant: 'blue',
price: 24.99,
quantity: 2
}
]
});This event adds two blue shoes to the cart. The items array has one object because there is one product line. The quantity is 2, so the event's value is 24.99 × 2 = 49.98.
How the array relates to the event
The diagram shows the parent-child structure.
Two consequences follow from this structure:
- Event-level and item-level parameters are separate. A
priceinside an item is a unit price. It is not the same thing as the event'svalue. - Reports that show product data, such as item name or item revenue, are built from the items array. If it is missing, the event can still count, but the product reports have nothing to show.
Required and recommended fields
Every item object needs at least one of item_id or item_name. In practice, send both. The ID is stable and suits joins and filtering. The name is readable in reports. If you send only names, a product renamed in your catalog splits into two rows in reports.
Other fields are optional for GA4 to accept the event, but they decide how useful your reports are.
| Field | Role | Common mistake |
|---|---|---|
| `item_id` | Stable product identifier | Using a different ID on list pages and product pages |
| `item_name` | Readable name | Changing the string between events |
| `price` | Unit price as a number | Sending `"24.99"` with a currency symbol |
| `quantity` | Units in this line | Omitting it, so GA4 treats it as 1 |
| `item_category` | Top-level category | Sending a full path in one field |
| `item_variant` | Size, color, or similar | Folding the variant into `item_name` |
Building an array with several lines
A multi-product cart has one object per line. This purchase has two lines. The index parameter records each item's position in the list.
const cart = [
{ id: 'SKU_1001', name: 'Trail Running Shoe', price: 24.99, qty: 2 },
{ id: 'SKU_2040', name: 'Wool Running Sock', price: 9.50, qty: 3 }
];
const items = cart.map((line, i) => ({
item_id: line.id,
item_name: line.name,
price: line.price,
quantity: line.qty,
index: i
}));
const value = cart.reduce((sum, line) => sum + line.price * line.qty, 0);
gtag('event', 'begin_checkout', {
currency: 'USD',
value: Number(value.toFixed(2)),
items: items
});Building the array from your own cart data is safer than writing it by hand. The same value calculation then always matches the items, which avoids a common mismatch. Rounding with toFixed(2) and converting back to a number keeps floating-point noise such as 78.47999999 out of your data.
Limits and edge cases
- Item count. GA4 accepts up to 200 items in one event. Extra items are dropped, which matters for very large carts or long product lists. For list events, send only the products currently visible.
- Payload size. A web hit has a size cap of about 16 KB for the request body, so many items with long strings can overflow it.
- Item parameters. An item can carry up to 10 custom parameters in addition to the standard ones.
- Types.
priceandquantitymust be numbers, not strings. Strings with currency symbols or thousands separators are not parsed as numbers. - Empty or malformed arrays. An
itemsparameter that is not an array, or an array of strings instead of objects, produces events with no usable product data. - Consistency. The same product should carry the same
item_idanditem_namein every event, from list view to purchase. Otherwise funnel reports by product break apart.
Check the current limits in Google's documentation before relying on them, since they can change.
Reusing items across the funnel
Most funnel events use the same item shape, with small differences:
- List events (
view_item_list) send many items and useindexplus list fields such asitem_list_name. view_itemandadd_to_cartusually send one item.begin_checkoutandpurchasesend every line in the cart.
Write one function that converts a product into an item object and call it from every event. A single mapping prevents drift between events.
function toItem(product, quantity = 1, index = 0) {
return {
item_id: product.sku,
item_name: product.title,
item_brand: product.brand,
item_category: product.category,
item_variant: product.variant,
price: product.price,
quantity: quantity,
index: index
};
}Common errors
- Sending
valuewithout matching items, or items with avaluethat ignores quantity. - Putting
priceat the event level and expecting item reports to use it. - Sending different IDs for the same product on different pages.
- Reusing a variable that still holds the previous cart contents.
- Sending an object instead of an array when only one product is involved. Always wrap a single item in
[ ... ].
Exercise
A shopper adds 3 units of a product priced at 12.50 USD to the cart. Write the value and the items array for the add_to_cart event, and say why wrapping the item in an array matters even for one product.
Show answer
The value is 37.50 (12.50 × 3), sent with currency 'USD'. The items array is [{ itemid: 'SKUX', item_name: 'Product X', price: 12.50, quantity: 3 }]. The wrapping array matters because GA4 expects items to be an array of objects. An object that is not in an array produces events without usable product data.
Exercise
Your reports show the same shoe as two separate rows, one named "Trail Running Shoe" and one named "Trail Shoe". Which item parameter should you check first, and what is the fix?
Show answer
Check item_id and item_name across the events. The name changed between events, or the ID is missing so GA4 groups by name. Send the same stable item_id and one consistent item_name everywhere, ideally from a single mapping function.