Sub topic 2
Everything is an event
This chapter explains the event as GA4's unit of measurement. It assumes you can read basic JavaScript (the gtag examples) and basic SQL (the BigQuery example). You should also know what a web analytics tool does and how pages or screens load. The previous chapter covered properties and data streams. This one covers what arrives in them.
The core idea
In Google Analytics 4 (GA4), every interaction is recorded as an event. An event is one timestamped record that says something happened. A page view is an event. A click on an outbound link is an event. A purchase is an event.
Earlier versions of Google Analytics (Universal Analytics) had several hit types: pageview, event, transaction, social, and so on. Each had its own fields. GA4 has one shape. Everything is an event with a name and a set of parameters.
Two other things you see in reports are not stored as records. They are calculated from events:
- A user is derived from identifiers carried on events.
- A session is derived from events that share a session identifier.
So when a report shows "Sessions: 1,204", nobody sent 1,204 session records. GA4 grouped events and counted the groups. Keep this in mind for the rest of the tutorial, because most confusing numbers come from forgetting it.
Anatomy of an event
Every event has the same basic parts.
| Part | What it is | Example |
|---|---|---|
| Event name | A string that says what happened | `add_to_cart` |
| Event parameters | Key-value pairs that describe this occurrence | `currency: 'USD'`, `value: 29.99` |
| Timestamp | When the event occurred | Set by the collection code |
| User identifiers | Who sent it, as a client ID, and optionally a User-ID | `user_pseudo_id`, `user_id` |
| User properties | Attributes of the person that persist across events | `plan_type: 'premium'` |
| Context | Device, geography, traffic source, and similar | Added by GA4 on collection |
You supply the name and the parameters. The browser or app SDK and GA4's servers add most of the rest.
Here is an event with parameters and an items array:
// 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
}
]
});The name is add_to_cart. The parameters currency and value describe this one add-to-cart. The items array describes the product. Later chapters cover parameters and items in detail. For now, notice that the event is the container and everything else hangs off it.
What "event-based" changes in practice
One shape, many meanings
Because every record has the same shape, GA4 does not need a separate pipeline for each kind of interaction. A page_view and a purchase travel the same way. What differs is the name and which parameters you attach.
This also means the name carries the meaning. If you send signup, sign_up, and Sign_Up from different parts of your site, GA4 treats them as three different events. Event names are case-sensitive.
Counting events versus counting people
An event count is the number of event records. It says nothing about how many people did the thing. If one visitor scrolls on ten pages, you get ten scroll events and one user.
Some reports show event count per user or users who triggered the event. These answer different questions:
- How many times did it happen? Use event count.
- How many people did it? Use the number of users with the event.
- How often does a person do it? Use event count per user.
Nothing is stored as a "page" or "screen" concept by default
A page view is just a page_view event with parameters such as page_location and page_title. An app screen view is a screen_view event with firebase_screen. If you want to know which pages are popular, GA4 counts these events grouped by the parameter value.
Limits you should know
GA4 sets limits on what you can send. The standard-property limits below are the commonly cited ones. Confirm them against Google's current documentation, because they can change.
| Item | Limit (standard property) |
|---|---|
| Event name length | 40 characters |
| Parameters per event | 25 |
| Parameter name length | 40 characters |
| Parameter value length | 100 characters |
| User property name length | 24 characters |
| Distinct event names per property (non-automatic) | 500 |
Event names must start with a letter and may contain only letters, numbers, and underscores. A name that breaks these rules can be dropped or rejected. Some names and prefixes are reserved, such as ga_, google_, and firebase_. Do not use them for your own events.
Event names versus event parameters
A common design question is whether to create a new event or add a parameter to an existing one. Compare two ways to track clicks on three buttons.
Many event names:
gtag('event', 'click_signup_button');
gtag('event', 'click_pricing_button');
gtag('event', 'click_demo_button');One event name with a parameter:
gtag('event', 'cta_click', { cta_name: 'signup' });
gtag('event', 'cta_click', { cta_name: 'pricing' });
gtag('event', 'cta_click', { cta_name: 'demo' });The second version is usually better. You use one name from your 500-name budget. You can compare all calls to action in one report. You add a new button by sending a new value, not a new event.
One caveat applies. A parameter is not available in standard reports until you register it as a custom dimension. A later chapter covers that step. Until then, the data is collected but you cannot break down a report by cta_name.
Choose a separate event name when:
- The interaction is conceptually different (for example
sign_upversuslogin). - You want to mark it as a key event.
- A Google-recommended event already exists for it.
Choose a parameter when the interaction is the same kind of thing and only a detail varies.
A worked example
Suppose a visitor lands on a product page, scrolls, adds a shoe to the cart and buys it. The event stream for that visit might look like this:
From these five events, GA4 derives:
- Event count: 5.
- Sessions: 1, because the events share one session ID.
- Users: 1, because they share one client ID.
- Purchases: 1, from the
purchaseevent.
You can verify numbers like these in the BigQuery export, where each row is one event. This query counts events, users and sessions per day:
-- Count events, users, and sessions per day from the GA4 BigQuery export
SELECT
event_date,
COUNT(*) AS event_count,
COUNT(DISTINCT user_pseudo_id) AS users,
COUNT(DISTINCT CONCAT(
user_pseudo_id,
'.',
CAST((SELECT ep.value.int_value
FROM UNNEST(event_params) AS ep
WHERE ep.key = 'ga_session_id') AS STRING)
)) AS sessions
FROM `my-project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
GROUP BY event_date
ORDER BY event_date;COUNT(*) counts rows, and each row is an event. Users and sessions use COUNT(DISTINCT ...) because they are derived by grouping. The session count combines user_pseudo_id with the ga_session_id parameter, because a session ID alone is a timestamp and can repeat across users. A later chapter on the BigQuery schema explains this in more detail.
Seeing events while you build
You do not have to wait for reports to check your tracking. Reports can lag by hours, and the standard reports apply processing. Two tools show events as they arrive:
- Realtime report: shows events from roughly the last 30 minutes.
- DebugView: shows a detailed, per-event timeline for devices in debug mode, including each event's parameters.
When an event does not appear, check these in order:
- Is the
gtagor tag manager code running on the page? Check for blocked scripts or consent settings. - Is the measurement ID correct for the data stream?
- Is the event name valid and within the limits?
- Is the event arriving but filtered, for example by an internal traffic filter?
Common mistakes with the event model
- Treating events as sessions or users. Event count is not user count. Do not report "5,000 signups" from an event count if some people signed up through a retry that fired the event twice.
- Firing duplicates. A tag that fires on every render can send the same event many times. Check that your trigger fires once per real action.
- Inconsistent names.
Purchaseandpurchaseare different events. Agree on lowercase snake_case and keep a tracking plan. - Expecting parameters in reports at once. Custom parameters are collected immediately. They show in standard reports only after you register them as custom dimensions or metrics.
- Exceeding limits silently. Parameters beyond the cap per event may not be recorded, and the cap on distinct names can be reached by dynamic naming.
Summary
Every interaction in GA4 is an event with a name and parameters. Users and sessions are not stored directly. GA4 derives them by grouping events by identifiers. Decide between a new event name and a parameter by asking whether the interaction is a different kind of thing or a different detail of the same thing. Use Realtime and DebugView to confirm what you send.
Exercise
A visitor scrolls on four pages and then adds one product to the cart. How many events, users, and sessions does this produce at minimum, assuming one visit and only the events named here? Which of these is a stored record and which is derived?
Show answer
At minimum there are five events: four scroll events and one add_to_cart. Counting page_view and session_start would add more, but the question asks only for the named events. There is one user and one session. The events are the stored records. The user and the session are derived by grouping events on the client ID and on the session ID.
Exercise
Your team tracks three buttons with the events click_signup, click_pricing, and click_demo. Propose a better design and name one thing you must do before you can break down a standard report by the button name.
Show answer
Use one event, such as cta_click, with a parameter such as cta_name whose value is signup, pricing, or demo. This saves event-name budget and keeps the clicks in one comparable event. Before the standard reports can break down by cta_name, you must register it as an event-scoped custom dimension in the property.
Exercise
In the BigQuery export, why does the session count in the example query combine user_pseudo_id with ga_session_id instead of counting distinct ga_session_id values alone?
Show answer
The ga_session_id value is a timestamp of when the session began. Two different users can start sessions at the same second and share the same value. Combining it with user_pseudo_id makes each session identifier unique across users.