Sub topic 1
How GA4 Models Events and Parameters
GA4 represents an online store as a stream of events. An event is a recorded action, such as viewing a product or completing a purchase. Each event has a name and a set of parameters that describe what happened.
Prerequisites
This chapter assumes that you understand GA4 properties and web data streams, JavaScript objects and arrays, and the basic flow of a web shop from product page to checkout.
The event model
An event name identifies the action:
view_itemmeans that a shopper viewed one product.add_to_cartmeans that a shopper added a product to the cart.purchasemeans that an order was completed.
Parameters are key-value pairs attached to an event. They provide context, such as the order amount, currency, or product details.
An e-commerce event normally uses these levels of data:
| Level | Examples | Purpose |
|---|---|---|
| Event | `purchase`, `currency`, `value` | Describes the action as a whole |
| Item | `item_id`, `item_name`, `price`, `quantity` | Describes each product in the action |
| User or session | User and session identifiers | Connects actions across visits |
The items parameter is an array. An array is an ordered list. Each element in the array is an object describing one product. A cart containing three products has three item objects, even if two products have the same name.
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 49.98,
items: [
{
item_id: 'SKU_1001',
item_name: 'Trail Running Shoe',
price: 24.99,
quantity: 2
}
]
});In this example, value describes the total value of the event. The item object describes the product and its quantity. GA4 can use the item data to calculate product-level metrics and the event data to calculate totals.
How the data fits together
A parameter belongs to the event unless it is placed inside an item object. For example, currency and value describe the transaction or action. item_brand and item_category describe a particular product.
A valid event structure does not guarantee accurate reporting. Your implementation must also send the correct currency, calculate values consistently, and avoid sending the same purchase more than once.
Exercise
In a purchase event containing two products, where should the order total and product price be stored?
Show answer
Store the order total in the event-level value parameter. Store each product's unit price inside its corresponding object in the items array.