Sub topic 6
Sending parameters and user properties
This chapter assumes you know what a GA4 event is, can find Admin and DebugView in the interface, and can read basic JavaScript or use Google Tag Manager (GTM). Here you will send event parameters, user properties and item parameters from a page, from GTM and from a server. Registering them as custom dimensions comes in a later chapter. Sending alone does not make them appear in standard reports.
What you are sending
GA4 accepts three kinds of extra data, and each kind is sent differently.
| Kind | Describes | Sent with | Later registered as |
|---|---|---|---|
| Event parameter | The single event | The event itself | Event-scoped custom dimension or custom metric |
| User property | The user, on every later event | A separate user-properties call or field | User-scoped custom dimension |
| Item parameter | One product in an `items` array | Inside an ecommerce event | Item-scoped custom dimension |
Sending event parameters with gtag.js
With gtag.js, the third argument of gtag('event', ...) is an object of parameters. Each key is a parameter name and each value is a string or a number.
gtag('event', 'select_plan', {
plan_tier: 'pro',
billing_cycle: 'annual'
});This sends one select_plan event with two parameters, plan_tier and billing_cycle. Once you register them, you can break down select_plan events by tier and by billing cycle.
Some rules apply to parameter names and values:
- Names must start with a letter. They may contain letters, numbers and underscores only.
- Names are case-sensitive.
plan_tierandPlan_Tierare different parameters. - Do not use names that GA4 reserves, such as ones starting with
google_,ga_orfirebase_. - Keep values short. Long strings are truncated, and the limit is lower for some fields than for others.
- Send numbers as numbers, not as strings. A value like
'184'is stored as text and cannot be used as a custom metric.
Sending user properties
A user property describes the person or device, not one action. You set it once. GA4 then attaches it to the events that follow from that user.
gtag('set', 'user_properties', {
customer_type: 'subscriber'
});Call this when you learn the value, for example after login. Two behaviors cause most mistakes:
- The value is attached to events sent after the call. It does not change events that were already sent.
- The value stays until you set a new one or the user's storage is cleared. If a user changes from
trialtosubscriber, send the new value. Do not assume the old one disappears.
Do not use a user property for something that changes on every event. Use an event parameter for that.
Sending item parameters
Item parameters live inside the items array of an ecommerce event. GA4 defines standard keys such as item_id and item_name. Any other key you add is a custom item parameter.
gtag('event', 'view_item', {
currency: 'USD',
value: 29.99,
items: [{
item_id: 'SKU_123',
item_name: 'Trail Shoe',
item_color: 'green'
}]
});Here item_color is a custom item parameter. After you register it as an item-scoped custom dimension, you can report on it next to item revenue. Send it consistently on every ecommerce event that carries the item, such as view_item, add_to_cart and purchase. A report that joins them is only as complete as the events that include the parameter.
Sending data through Google Tag Manager
With GTM, your page pushes data to the dataLayer, and a GA4 event tag reads it. The page code contains no gtag call.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'video_complete',
video_length_seconds: 184
});The push alone sends nothing to GA4. You must complete the setup in GTM:
- Create a Data Layer Variable named, for example,
dlv - video_length_seconds, pointing at the keyvideo_length_seconds. - Create a Custom Event trigger whose event name is
video_complete. - Create a GA4 Event tag with the event name
video_complete. Under Event Parameters, add a row with the namevideo_length_secondsand the variable as the value. - For user properties, use the User Properties section of the same tag, or of your Google tag settings, and add a row with a name and a variable.
- Attach the trigger, then preview the container.
The parameter name you type in the tag row is the name GA4 receives. The data layer key and the GA4 parameter name do not have to match, but using the same name avoids confusion.
Sending data from a server with the Measurement Protocol
The Measurement Protocol sends events by HTTP POST. It suits events that happen outside a browser, such as an offline sale. The body is JSON, and parameters go in a params object.
{
"client_id": "555.1234567890",
"events": [
{
"name": "offline_sale",
"params": {
"store_region": "north",
"basket_size": 4
}
}
]
}You send this to the collection endpoint with your Measurement ID and an API secret, both created in the data stream settings:
const url = 'https://www.google-analytics.com/mp/collect'
+ '?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_SECRET';
const body = {
client_id: '555.1234567890',
user_properties: { customer_type: { value: 'subscriber' } },
events: [{
name: 'offline_sale',
params: { store_region: 'north', basket_size: 4 }
}]
};
fetch(url, { method: 'POST', body: JSON.stringify(body) })
.then(r => console.log('status', r.status));Note the shape difference. In the Measurement Protocol, each user property is an object with a value key, as in { value: 'subscriber' }. In gtag.js it is a plain value.
Keep these points in mind:
- The
client_idmust match the one the browser uses if you want server events tied to the same user. - The endpoint returns a success status even for many invalid payloads, so the status code does not prove the data was accepted. Use the validation endpoint at
/debug/mp/collectduring development. It returns messages about problems. - Keep the API secret on the server. Never put it in browser code.
Comparing the three routes
| Concern | gtag.js | GTM | Measurement Protocol |
|---|---|---|---|
| Where the code lives | Your page | The data layer plus the GTM container | Your server |
| User property format | Plain value | Name and variable rows in the tag | Object with `value` |
| Best for | Simple sites, developer control | Teams that change tracking without deploys | Offline or back-end events |
| Main risk | Hard-coded names drift | Missing variable values | Silent acceptance of bad payloads |
Common mistakes
- Sending a parameter and expecting it in a standard report immediately. It needs registration first, and only data collected after registration is filled in.
- Using different names for the same idea on different pages, such as
planTierandplan_tier. - Putting personal data such as email addresses in parameter values. This breaks Google's terms and creates privacy risk.
- Sending a unique value, such as an order ID or a timestamp, as a dimension value. Such values create very many distinct values, which a later chapter covers.
- Firing the user property call after the event it should describe.
Exercise
A site sets gtag('set', 'user_properties', { customer_type: 'subscriber' }) after the user's first purchase event has already fired in the same page view. Will that purchase event carry customer_type, and which later events will?
Show answer
The first purchase event will not carry customer_type, because user properties attach only to events sent after the call. Later events from that user will carry it, until you set a different value or the user's stored data is cleared. To tag the purchase, set the property before the event is sent.
Exercise
A developer pushes { event: 'video_complete', video_length_seconds: 184 } to the dataLayer, but no video_length_seconds value appears in GA4. Name three GTM pieces that must exist, and one way to find the fault.
Show answer
A Data Layer Variable reading video_length_seconds, a Custom Event trigger for video_complete, and a GA4 Event tag with video_length_seconds added under Event Parameters. To find the fault, use GTM Preview and check whether the trigger fires and what value the variable holds at that moment.