Sub topic 3
The items Array: Describing Products in an Event
This chapter assumes you understand GA4 events, JavaScript objects and arrays, and the basic flow of a web shop from product page to checkout. You will use that knowledge to describe one or more products inside an e-commerce event.
What the items array represents
An items array is a list of products or services associated with an event. Each list entry is an item object. The event describes what happened, while each item object describes which product was involved.
For example, an add_to_cart event can contain one item when a shopper adds one product. A purchase event can contain several item objects when the order contains several products.
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
}
]
});The array uses square brackets, and each product uses braces. The value is the total for the items in this event: 24.99 × 2 = 49.98.
The structure of an item object
Use a stable product identifier whenever possible. item_id is usually a stock-keeping unit, product ID, or another identifier from your commerce system. item_name is the readable product name.
| Parameter | Purpose | Example |
|---|---|---|
| `item_id` | Identifies the product | `SKU_1001` |
| `item_name` | Names the product | `Trail Running Shoe` |
| `price` | Unit price before quantity is applied | `24.99` |
| `quantity` | Number of units | `2` |
| `item_brand` | Product brand | `Acme` |
| `item_category` | Main product category | `Shoes` |
| `item_variant` | Distinguishes a version | `blue` |
A product can also include category levels such as item_category2 through item_category5. Use these consistently. Do not put the same information under different parameter names on different pages.
Event parameters and item parameters
currency and value are event-level parameters. They describe the event total. Parameters such as price, quantity, and item_variant belong inside an item object because they describe a particular product.
Common errors
- Sending
itemsas an object instead of an array. - Omitting
item_idor using a different ID for the same product in different events. - Sending a line total as
priceinstead of the unit price. - Sending text such as
"2"instead of the number2. - Including stale products left over from a previous data layer or event.
- Calculating
valuedifferently from the item prices and quantities.
Exercise
An item has a unit price of 15.50 and a quantity of 3. What should the event-level value be, before tax and shipping?
Show answer
The value should be 46.50, calculated as 15.50 × 3.