Sub topic 7
User properties: describing who did it
This chapter assumes you know what an event and an event parameter are, and that you can read basic gtag.js calls and SQL. It covers how user properties differ from event parameters, how to set and register them, and the mistakes people make with them.
What a user property is
An event parameter describes what happened in one event. A user property describes the person (or the browser or device) that performed it. Examples are plan_type, preferred_language, or customer_tier. These values tend to stay the same across many events and many sessions.
GA4 attaches the user property values that are set at the moment you send an event to that event. So user properties are not stored in a separate profile table that you can look up. They travel with events, like parameters do. This explains most of their behavior, including the pitfalls later in this chapter.
Parameters, user properties, and User-ID compared
These three are easy to confuse because all of them are sent from your page or app.
| Item | Describes | Typical lifetime | Example | Reportable by default |
|---|---|---|---|---|
| Event parameter | One event | That event only | `value: 29.99` | No, register a custom dimension or metric |
| User property | The user | Many events and sessions | `plan_type: 'premium'` | No, register a user-scoped custom dimension |
| User-ID | Identity of the user | Across devices | `user_id: 'u_12345'` | Used for identity, not a custom dimension |
Use a parameter when the value can differ from one event to the next, such as the price in an add_to_cart. Use a user property when the value describes the person and you want to segment or compare many of their events by it.
Setting a user property
On the web, you set user properties with the set command of gtag.js. Every event sent after that call includes them.
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
// Set a user property for signed-in visitors
gtag('set', 'user_properties', {
plan_type: 'premium'
});
// Set the User-ID and initialize the stream
gtag('config', 'G-XXXXXXXXXX', {
user_id: 'u_12345'
});This snippet assumes the gtag.js library is loaded on the page. Three details matter here:
- The property is set before
config. Thepage_viewthatconfigsends then carriesplan_type. If you set it afterward, the firstpage_viewgoes out without it. - The
user_idis separate from the user property. It is used for identity, so GA4 can link activity from different devices to the same signed-in user. It does not appear as a user property. - On the web, a value you set with
gtag('set', ...)lasts only for the current page load. When the next page loads, your code must set it again. Mobile SDKs behave differently, because they store user properties on the device until you change them.
You can also send user properties from a server with the Measurement Protocol, using a user_properties object in the request body. This is useful for values that only your backend knows, such as the billing plan.
Updating and clearing values
To change a value, set the property again. Events sent afterward carry the new value. Events already collected keep the old one, because each event stored the value that was current when it was sent.
// The user upgrades during the session
gtag('set', 'user_properties', {
plan_type: 'enterprise'
});To clear a property, set it to null. This stops it being attached to later events. It does not delete anything already collected.
gtag('set', 'user_properties', {
plan_type: null
});Making a user property reportable
Collecting a user property is not enough. As with event parameters, you must register it as a custom dimension before it shows up in standard reports and Explorations. For user properties, you choose the User scope.
- In the GA4 Admin area, open Custom definitions for the property.
- Create a custom dimension.
- Enter a name for display, choose the scope User, and enter the user property name exactly as you send it, for example
plan_type. - Save.
Registration has consequences you should plan for:
- It is not retroactive. Values collected before you registered the dimension do not appear in reports built on that dimension. Register the dimension at the same time you start sending the property.
- The name must match exactly, including case.
Plan_Typeandplan_typeare different properties. - Quotas apply. A standard property allows a limited number of user-scoped custom dimensions (25 at the time of writing, and more on GA4 360). Check the current limits in the Google documentation.
- Each dimension uses one slot. Archiving a dimension may not free the slot at once, so choose names deliberately.
Unregistered user properties are still collected. They are visible in the BigQuery export, which is why the export is a good place to check that your tagging works.
Automatically collected user properties
GA4 also fills in some user-level attributes without any code from you. Examples include the user's country, device category, browser, and language. These show up as built-in dimensions in reports. You do not set or register them. Do not reuse their names for your own properties.
Some names are reserved, such as first_open_time. Also avoid names starting with google_, ga_, or firebase_. GA4 limits the length of user property names (24 characters) and values (36 characters), so store short codes like premium instead of long text.
What not to store
Google's terms prohibit sending personally identifiable information (PII) such as email addresses, phone numbers, or full names to GA4. This applies to user properties as well as parameters. If you need to identify a person, use an opaque ID in user_id that only your own systems can map back to a real person.
How a user property appears in BigQuery
In the export, each event row has a user_properties field. It is a repeated record, one entry for each property set on that event. Each entry has a key and a value record, and the value can be a string, integer, float, or double. A timestamp tells you when the value was last set.
This query counts users by plan type. It reads the plan_type entry from each event:
SELECT
up.value.string_value AS plan_type,
COUNT(DISTINCT user_pseudo_id) AS users
FROM `my-project.analytics_123456789.events_*`,
UNNEST(user_properties) AS up
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
AND up.key = 'plan_type'
GROUP BY plan_type
ORDER BY users DESC;If a user changed plan during January, this query counts that user once under each plan, because events carried both values. If you want one value per user, pick the latest by timestamp, for example with ARRAY_AGG(... ORDER BY event_timestamp DESC LIMIT 1).
Common mistakes
- Using a user property for an event-level value. If you store
last_product_viewedas a user property, each event carries whatever was set most recently. This is easy to confuse with parameters on the event. Use a parameter instead. - Setting the property only on one page. On the web, a property set on the login page and not on later pages is missing from events on those pages. Set it on every page load, for example in your shared tag code.
- Forgetting to register the dimension. Data is collected, but reports show nothing. Check Custom definitions first.
- Expecting history to be rewritten. Changing a property never changes events collected earlier.
- Mixing up scopes. A custom dimension with event scope will not read a user property, even if the names match.
- Sending high-cardinality values. A different value per user, such as a session token, produces report rows with "(other)" and exhausts quotas. Use a user property for categories, not identifiers.
Exercise
A site sets gtag('set', 'user_properties', { plan_type: 'free' }) only on its login page. A user logs in, browses three other pages, and then buys a product. Why might the purchase event show no plan_type, and how do you fix it?
Show answer
On the web, a user property set with gtag('set', ...) lasts only for the current page load. Events on the other pages and the purchase event were sent without it. The fix is to set the property on every page load, for example in the shared tag snippet, before the config call. Registering a User-scoped custom dimension named plan_type is also required for it to appear in reports.
Exercise
You registered plan_type as a user-scoped custom dimension today, but your January reports show no data for it, although you sent the property all month. Why?
Show answer
Custom dimension registration is not retroactive. Reports only include values from events collected after the dimension was registered. The January values are still in the BigQuery export, where you can query them from the user_properties field.