Sub topic 2
Everything Is an Event
Assume you know what a website or app does and can read basic JavaScript. You should also understand that an analytics tag sends data from a site or app to GA4. This chapter uses the gtag.js syntax for web tracking.
Events are the unit of measurement
GA4 records interactions as events. An event is a named record that says something happened at a particular time. Examples include a page loading, a video starting, a product being added to a cart, or a form being submitted.
A GA4 event usually contains:
- An event name, such as
page_vieworadd_to_cart - A timestamp
- Event parameters that describe the interaction
- Information about the user and device
- Context from the property and data stream that received it
A property is the GA4 container that stores and reports data. A data stream is a source of data, such as a website, iOS app, or Android app. Events from the streams flow into the property.
An event is not the same thing as a user or a session. A single user can generate many events. A session is a group of events that occur during a period of activity. GA4 derives users and sessions from event data.
Event names and parameters
The event name identifies the action. Parameters add details about that action. For example, add_to_cart identifies the action, while currency, value, and item_id describe what was added.
// Send an ecommerce event after a product is added to the cart.
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 29.99,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoe',
price: 29.99,
quantity: 1
}
]
});Use stable names and consistent parameter types. Sending product_added, addProduct, and cart_add for the same action creates separate event types and makes reporting harder.
| Part of the record | Example | Purpose |
|---|---|---|
| Event name | `add_to_cart` | Identifies what happened |
| Parameter | `currency: 'USD'` | Describes the event |
| Item field | `item_id: 'SKU_123'` | Describes a product in an item list |
Four ways events are collected
GA4 events commonly come from four sources:
- Automatically collected events are sent by GA4 without custom tracking code, such as some first visits or app starts.
- Enhanced measurement events are collected when features are enabled for a web stream. Examples include scrolls, outbound clicks, and site searches.
- Recommended events use Google’s standard names and parameters for common actions, especially ecommerce and account activity.
- Custom events represent actions that do not fit the standard event model.
Recommended events are usually preferable to custom names when they describe the same action. Standard names make reports and integrations easier to understand.
Model interactions as facts
Before adding tracking code, describe the interaction as a fact: what happened, when it happened, and which details explain it. Avoid putting several unrelated actions into one event. For example, send separate events for a search, a product view, and an add-to-cart action.
This event-based model lets GA4 calculate higher-level results later. It also means that changing an event name or parameter can split historical data into separate categories.
Exercise
A visitor views three product pages and adds one product to the cart. How many events should the model contain if each action is tracked separately?
Show answer
Four events: three product-view events and one add-to-cart event. They may belong to one session and one user, but they remain separate event records.