Sub topic 1
How GA4 models events and parameters
This chapter explains the data model that every later chapter relies on. E-commerce tracking in GA4 is a set of events with a specific parameter shape. If you understand the model, the item and purchase rules in later chapters follow from it.
Prerequisites
This chapter assumes you already have the following:
- Basic familiarity with the GA4 interface: properties, data streams, and standard reports.
- Basic understanding of JavaScript objects and arrays.
- Basic familiarity with JSON.
- Awareness of how a web shop's product, cart, and checkout pages work.
You do not need to have implemented any tracking yet.
Everything is an event
Universal Analytics, the previous Google Analytics, had several hit types: pageviews, events, transactions, and so on. GA4 has one. Every interaction is an event, including page views, scrolls, clicks, and purchases.
An event has two parts:
- A name, such as
page_view,add_to_cart, orpurchase. - Zero or more parameters, which are key-value pairs that describe the event.
GA4 also attaches context automatically. That context includes the timestamp, the device, the location, the traffic source, and a client identifier that groups events from one browser. You do not send these yourself.
The four kinds of events
GA4 groups event names by who defined them. This matters because it decides which names and parameters get built-in treatment in reports.
| Kind | Who defines the name | Example | E-commerce relevance |
|---|---|---|---|
| Automatically collected | GA4 | `page_view`, `first_visit` | Provides the context around a purchase |
| Enhanced measurement | GA4, if enabled | `scroll`, `file_download` | Not used for shopping data |
| Recommended | Google documents the name and parameters, you implement it | `add_to_cart`, `purchase`, `refund` | The core of this tutorial |
| Custom | You | `size_guide_opened` | Useful for site-specific behavior |
Recommended events are not collected unless you send them. They are a naming contract. If you send purchase with the documented parameters, GA4 fills its monetization reports. If you invent order_complete, GA4 records it as a custom event and the revenue reports ignore it.
Event names are case-sensitive. Purchase and purchase are different events, and only the lowercase one is the recommended event.
Parameters
A parameter adds detail to one event. Parameters have a name and a value. The value is a string or a number.
gtag('event', 'select_item', {
item_list_name: 'Search results',
currency: 'USD'
});Here item_list_name and currency are parameters of select_item. Parameters belong to the single event that carried them. They do not persist to the next event unless you send them again.
Some parameters are defined by Google and have a fixed meaning. In e-commerce, currency, value, transaction_id, coupon, tax, shipping, and items are the ones you will use most. Others are yours to define.
The items parameter is special
Most parameters hold a single string or number. items holds an array of objects, one per product. Each object has its own set of item parameters, such as item_id and price. This nested shape is what allows one purchase event to describe several products. The next chapters cover it in detail.
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
}
]
});Event-level parameters (currency, value) sit beside the items array. Item-level parameters (item_id, price) sit inside each object of the array. Mixing these levels is a common mistake.
How an event travels
The flow from your page to a report has several stages.
Three sending methods feed the same model:
- gtag.js, called directly from your page code.
- Google Tag Manager, which reads a
dataLayerand fires a GA4 tag. - The Measurement Protocol, an HTTP API for servers.
The event name and parameters are the same whichever method you choose. Only the delivery mechanism differs.
DebugView and Realtime show events within seconds. Standard reports can take 24 to 48 hours to finish processing. Because of that delay, check new tracking in DebugView first.
Registration: parameters are collected, but not always reportable
Sending a parameter and seeing it in reports are separate steps.
- GA4 stores every parameter you send with an event.
- Several parameters are built in and appear in reports automatically. Examples are
currency,value,transaction_id, and the item parameters used by e-commerce reports. - Your own parameters become dimensions or metrics in reports and explorations only after you register them as custom definitions in the property's admin settings.
Custom definitions have a scope: event, user, or item. For example, a parameter inside an items object can be registered as an item-scoped dimension. A later chapter covers that. For now, remember that a parameter that is not in a report is not necessarily missing. It may simply be unregistered.
Properties also have limits on the number of event names, parameter names, and custom definitions, and on parameter name and value length. Check Google's current documentation for exact figures, since they change and differ for standard and 360 properties.
Event-scoped values and numeric types
GA4 reads value as a number. Send 49.98, not '$49.98' or '49,98'. A string with a symbol or a comma is not valid as a number, and the revenue will not be counted correctly.
currency is a three-letter ISO 4217 code such as USD or EUR. A value without a valid currency is ambiguous, so GA4 cannot treat it as revenue. Chapter content on currency and value covers this in depth.
Checking your understanding of the model
When you design a tracking plan, ask the same questions for every event:
- Is there a recommended event name for this action?
- Which event-level parameters does it need?
- Does it carry products, and if so, what goes in each item object?
- Do any custom parameters need registering before I can report on them?
If you answer these before writing code, most later debugging problems disappear.
Common errors at this level
- Using a custom event name where a recommended name exists, so reports show no revenue.
- Placing
priceoritem_idat the event level instead of insideitems. - Sending
valueas a formatted string. - Changing event name capitalization between pages.
- Expecting an unregistered custom parameter to appear as a dimension.
- Checking standard reports immediately after deploying and concluding that tracking failed.
Exercise
A developer sends this event. Name two problems that would stop GA4 from treating it as a correct e-commerce add-to-cart event. gtag('event', 'AddToCart', { value: '$49.98', itemid: 'SKU1001', price: 24.99 });
Show answer
First, the event name AddToCart is not the recommended name add_to_cart, and names are case-sensitive, so GA4 records it as a custom event. Second, value is a formatted string instead of the number 49.98, and there is no currency parameter. A further problem is that item_id and price are at the event level instead of inside an items array of objects.
Exercise
You add a custom parameter gift_wrap to your purchase events, and it appears in DebugView. Two days later you cannot find it as a dimension in an exploration. What is the likely cause and the fix?
Show answer
The parameter was collected but is not registered as a custom definition. Register gift_wrap as an event-scoped custom dimension in the property's admin settings. It will then be available as a dimension for data collected after registration.