Sub topic 5
The `items` Array for Ecommerce
Assume you know how GA4 properties receive events and can read basic JavaScript. This chapter focuses on ecommerce events, where one event can describe one or more products.
What the `items` Array Represents
An items array is a list of products or services associated with an ecommerce event. Each entry in the array is an item object. The object contains details such as the product identifier, name, price, and quantity.
The event-level parameters describe the whole transaction. The item-level parameters describe each product within that transaction.
For example:
currencyapplies to the event.valueis the total value associated with the event.item_ididentifies one product.pricedescribes the price of one product.quantitydescribes how many units were involved.
A product view has one item in its array. A purchase can have several items.
// Send a recommended ecommerce event with parameters and an items array
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 29.99,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoe',
price: 29.99,
quantity: 1
}
]
});The event name, add_to_cart, tells GA4 what happened. The items array tells GA4 which product was added. The value is the total value for the event, so it should account for all products and quantities in that event.
Event-Level and Item-Level Data
Do not place product details only in event-level parameters. If a cart contains several products, a single event-level item_name cannot represent them accurately.
| Data level | Example parameter | Meaning |
|---|---|---|
| Event level | `currency: 'USD'` | Currency used for the event |
| Event level | `value: 59.98` | Total value for the event |
| Item level | `item_id: 'SKU_123'` | Identifier for one product |
| Item level | `quantity: 2` | Quantity of one product |
An event can contain multiple item objects:
gtag('event', 'purchase', {
transaction_id: 'T_1007',
currency: 'USD',
value: 59.98,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoe',
price: 29.99,
quantity: 1
},
{
item_id: 'SKU_456',
item_name: 'Hiking Socks',
price: 14.99,
quantity: 2
}
]
});In this example, the array has two product entries. The receiving implementation should calculate value consistently with the prices and quantities it sends.
Standard Fields and Custom Item Data
GA4 recognizes standard ecommerce item fields, including item_id, item_name, price, and quantity. Use these standard names when they match your data. Consistent names allow GA4 ecommerce reports and downstream queries to interpret the products correctly.
You can also send additional item details, such as:
item_branditem_categoryitem_variantitem_list_namediscountcoupon
A custom item parameter can be useful when your catalog has a field that GA4 does not provide by default. However, collecting a parameter does not automatically make it available in standard reports. You may need to register the field as a custom definition, and you should confirm that the definition supports item-scoped data.
How the Data Fits Together
The event identifies the action. The items identify the products involved. This structure lets you analyze actions such as product views, cart additions, and purchases at both levels.
Common Mistakes
- Sending
itemsas a single object instead of an array. - Omitting
item_idor using an unstable identifier. - Putting one product's price in
valuewhen the event contains several products. - Mixing currencies without clearly defining how values are interpreted.
- Using different field names for the same product attribute across events.
- Sending item data for one event type but not for related ecommerce events, making product journeys incomplete.
Exercise
A purchase event contains two products, each with a quantity of one. Where should the product names and prices go, and where should the currency go?
Show answer
Put each product's name and price in a separate object inside the items array. Put the currency in the event-level currency parameter. Put the combined amount in the event-level value parameter.