Sub topic 5
The items array for ecommerce
This chapter assumes you know what a GA4 event and an event parameter are, and that you can read basic JavaScript and SQL. It covers how GA4 describes products inside ecommerce events, how those products appear in reports, and where the common mistakes are.
Why a separate array exists
Most event parameters hold one value for the whole event. A page_view has one page_location. An ecommerce event often involves several products at once. A purchase can contain three different shoes and a bag. A single flat parameter cannot describe that.
GA4 solves this with the items parameter. It is an array of objects, and each object describes one product. The event-level parameters, such as currency, value, and transaction_id, describe the action as a whole. The items array describes the things the action was about.
A worked example
The next snippet sends an add_to_cart event. It is a recommended event, so GA4 already knows its name and its expected parameters.
// 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
}
]
});Read it in two layers:
currencyandvaluebelong to the event.valueis the total monetary value of the action, here the price times the quantity.- Each object inside
itemsbelongs to one product. The fieldsitem_id,item_name,price, andquantitydescribe that product only.
Item fields you will use
Every item needs at least one of item_id or item_name. In practice send both, and keep item_id stable, because it is the field you will join on later.
| Field | Meaning | Notes |
|---|---|---|
| `item_id` | Your product identifier, such as a SKU | Keep it identical across all events |
| `item_name` | Display name of the product | Used in the Item name dimension |
| `price` | Unit price of one item | A number, without a currency symbol |
| `quantity` | Number of units | Defaults to 1 when missing |
| `item_brand` | Brand | Optional |
| `item_category` to `item_category5` | Up to five levels of category hierarchy | Optional |
| `item_variant` | Variant such as color or size | Optional |
| `item_list_id`, `item_list_name` | The list where the item was shown | Used for list performance reports |
| `index` | Position of the item in a list | Optional |
| `coupon` | Coupon applied to this item | Separate from the event-level `coupon` |
| `discount` | Unit discount amount | Optional |
Which events use items
The recommended ecommerce events follow a shopping journey. Each one expects an items array.
| Event | Moment in the journey |
|---|---|
| `view_item_list` | A list of products is shown |
| `select_item` | A product is chosen from a list |
| `view_item` | A product page is viewed |
| `add_to_wishlist` | A product is saved |
| `add_to_cart` | A product is added to the cart |
| `view_cart` | The cart is viewed |
| `remove_from_cart` | A product is removed |
| `begin_checkout` | Checkout starts |
| `add_shipping_info` | Shipping details are given |
| `add_payment_info` | Payment details are given |
| `purchase` | The order is completed |
| `refund` | An order is refunded |
The purchase event also needs transaction_id. GA4 uses it to ignore duplicate purchases with the same ID, which protects your revenue numbers when a confirmation page is reloaded. Treat it as required in practice.
A purchase with several items
This example sends an order with two different products. The event-level value matches the sum of the item prices times their quantities.
// Send a purchase event with two products
gtag('event', 'purchase', {
transaction_id: 'T_98765',
currency: 'USD',
value: 99.97,
tax: 6.00,
shipping: 5.00,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoe',
price: 29.99,
quantity: 2,
item_category: 'Footwear'
},
{
item_id: 'SKU_456',
item_name: 'Day Pack',
price: 29.99,
quantity: 1,
item_category: 'Bags'
}
]
});Check the arithmetic: 2 × 29.99 plus 1 × 29.99 gives 89.97. Adding the 5.00 shipping and 6.00 tax gives 100.97, so which number should value hold? GA4 does not compute it for you. By Google's documentation, value is the monetary value of the event, and you decide whether it includes tax and shipping. In the example above, value of 99.97 is neither 89.97 nor 100.97, so it is inconsistent. Pick one rule, apply it to every event, and document it. A rule that works for most stores is: value equals the sum of price times quantity, minus discounts, with tax and shipping sent in their own parameters. Under that rule the correct value here is 89.97.
// Compute value from the items instead of typing it by hand
const items = [
{ item_id: 'SKU_123', item_name: 'Trail Shoe', price: 29.99, quantity: 2 },
{ item_id: 'SKU_456', item_name: 'Day Pack', price: 29.99, quantity: 1 }
];
const value = Math.round(
items.reduce((sum, i) => sum + i.price * i.quantity, 0) * 100
) / 100;
gtag('event', 'purchase', {
transaction_id: 'T_98765',
currency: 'USD',
value: value,
tax: 6.00,
shipping: 5.00,
items: items
});Deriving value from the same array you send removes a whole class of mismatches. The rounding step avoids floating-point results such as 89.97000000000001.
Clearing the data layer in Google Tag Manager
If you send events through Google Tag Manager, you push to dataLayer instead of calling gtag. A known trap is that an old ecommerce object stays in the data layer and leaks into the next event. Clear it before each push.
// Clear the previous ecommerce object, then push the new event
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'view_item',
ecommerce: {
currency: 'USD',
value: 29.99,
items: [
{ item_id: 'SKU_123', item_name: 'Trail Shoe', price: 29.99, quantity: 1 }
]
}
});How items show up in reports
Item fields are not ordinary event parameters. GA4 treats them as a separate scope, the item scope, and exposes them through item-scoped dimensions and metrics:
- Dimensions include Item ID, Item name, Item brand, Item category, and Item variant.
- Metrics include Items viewed, Items added to cart, Items purchased, and Item revenue.
Two consequences follow. First, you do not register item_id or item_name as custom dimensions, because they are already built in. Second, you cannot freely mix item-scoped fields with event-scoped or user-scoped fields in every report. A report that combines an item dimension with an incompatible event-scoped metric can show "(not set)" or hide the metric. The Explore tools flag incompatible combinations in the variable panel.
Item-scoped custom dimensions exist. If you add a field such as item_color inside an item, register it in the custom definitions area with the scope Item. Until then it is collected but not reportable. Chapter material on custom definitions covers the registration steps in general.
Items in the BigQuery export
In the BigQuery export, items is a repeated record on each event row. Each product is one element of the array, so you must flatten it with UNNEST to get one row per product.
-- Item revenue and units per product, from purchase events
SELECT
item.item_id,
item.item_name,
SUM(item.quantity) AS units,
SUM(item.item_revenue) AS item_revenue
FROM `my-project.analytics_123456789.events_*`,
UNNEST(items) AS item
WHERE event_name = 'purchase'
AND _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
GROUP BY item.item_id, item.item_name
ORDER BY item_revenue DESC;Here item_revenue is computed by GA4 from price and quantity, less discount. Remember that UNNEST multiplies rows. Counting events after unnesting counts items, not events. To count orders, use COUNT(DISTINCT ecommerce.transaction_id) and do not unnest first.
Limits and edge cases
- GA4 accepts up to 200 items in one event. Extra items are dropped, so a very large cart or list should be split.
- An event, including its items, has a payload size limit. Very long item names or many custom item parameters can push you over it.
- Each item can carry up to 27 custom parameters, subject to the property limits for item-scoped custom dimensions.
pricemust be a number. A string such as"$29.99"is not parsed as a price, and revenue is wrong or missing.- A missing
currencymakesvalueunusable for revenue reporting. Always send it withvalue. - Sending a different
item_idfor the same product inview_itemandpurchasebreaks funnels, because the funnel steps cannot match. - Item metrics depend on the event that carries them. Items added to cart counts items from
add_to_cartonly. If you rename the event, the metric stays at zero. - Non-ecommerce events can carry
items, but standard item metrics only use the recommended ecommerce events.
Common mistakes
- Putting product details in flat parameters such as
product_nameinstead of insideitems. The data is collected but the built-in item reports stay empty. - Sending
valuewithout matching it to the items, as the earlier example showed. - Omitting
transaction_idonpurchase, which allows duplicate orders. - Using display names in
item_id. Names change, and IDs should not. - Forgetting to clear
ecommercein the data layer, so one event inherits another event's items.
Check your understanding
Exercise
A purchase event sends two items, each with price 20.00 and quantity 2, plus shipping of 8.00. Your team's rule is that value excludes tax and shipping. What should value be, and how many rows does UNNEST(items) produce for this one event in BigQuery?
Show answer
Each item contributes 20.00 × 2 = 40.00, so the total is 80.00, and value should be 80.00. The shipping of 8.00 goes in the shipping parameter. UNNEST(items) produces 2 rows, one per item, so counting rows after the unnest counts items and not orders.
Exercise
Your Items added to cart report shows zero, although your site sends a custom event called cart_add with a full items array. Why, and what is the fix?
Show answer
Item metrics such as Items added to cart are tied to the recommended add_to_cart event name. The custom cart_add event is collected, but it does not feed that metric. Rename the event to add_to_cart, or send add_to_cart instead, and keep the same items structure.
Exercise
You add an item_color field inside each item and see it in the BigQuery export, but not in a GA4 report. What step is missing?
Show answer
You must register item_color as a custom dimension with the Item scope. Until it is registered, GA4 collects it and exports it, but standard reports and Explorations cannot use it.