Sub topic 9
Creating Custom Metrics and Choosing Units
Prerequisites and the working model
This chapter assumes that you understand GA4 events, can edit a gtag.js implementation or Google Tag Manager tag, and can open the Admin area of a GA4 property.
A custom metric is a reportable numeric value that you collect as an event parameter. For example, video_length_seconds can record the length of a completed video. GA4 can count events automatically, but it does not automatically make every numeric parameter available as a metric in standard reports. You must register the parameter as an event-scoped custom metric.
The value should describe one event, such as seconds watched, products in a basket, or a score. User properties describe users and belong in custom dimensions, not custom metrics.
Send a numeric parameter
The parameter must be sent with a numeric value. With Google Tag Manager, a data layer variable can provide the value to a GA4 Event tag.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'video_complete',
video_length_seconds: 184
});In Google Tag Manager, create a Data Layer Variable for video_length_seconds. Map that variable to the video_length_seconds event parameter in a GA4 Event tag whose event name is video_complete.
If you use gtag.js, the equivalent event is:
gtag('event', 'video_complete', {
video_length_seconds: 184
});Use a number rather than a formatted string such as "184 seconds". A string may not be usable as a numeric metric. Do not include commas, currency symbols, or units in the value. Store the unit in the metric definition instead.
Validate before registering
Turn on debug mode for your test traffic, trigger the event, and open Admin > Data display > DebugView. Select the event and inspect its parameters. Confirm that:
- The event name is correct.
- The parameter name matches exactly.
- The value is numeric.
- The value is present on the events that should contain it.
- The value is not accidentally zero, null, or a text label.
DebugView is useful for checking incoming data, but it does not prove that historical reports will contain the metric. Registration and report processing happen separately.
Register the metric and choose its unit
In the GA4 interface, open Admin, choose Custom definitions, and select Create custom metric. Enter a clear display name, the event parameter name, and a unit of measurement.
Choose the unit that matches the meaning of the number:
| Data meaning | Example parameter | Suitable unit |
|---|---|---|
| Video duration | `video_length_seconds` | Seconds |
| Distance traveled | `route_distance_km` | Kilometers |
| Order value | `order_value` | Standard or currency-related reporting |
| Survey score | `satisfaction_score` | Standard |
A unit changes how GA4 interprets and displays the value. It does not convert seconds to minutes or dollars to another currency. Convert the value before sending it if conversion is required. Use Standard for counts, scores, quantities, and other values without a physical unit.
Custom metrics are event-scoped. If you need to describe which plan a user selected, use an event-scoped custom dimension such as plan_tier. If you need a persistent classification such as customer_type, use a user-scoped custom dimension.
Use and govern the metric
After processing, the metric can appear in reports, Explorations, audiences, and supported Data API queries. Apply it to the events for which it has meaning. A metric named duration_seconds should not receive milliseconds on some events and seconds on others.
Document the parameter name, event name, unit, owner, and definition. Keep names lowercase with underscores, such as video_length_seconds. Avoid names that hide the unit or combine multiple meanings.
Exercise
You collect basket_size as the number 4 on a purchase event. Which unit should you choose when registering it?
Show answer
Choose Standard because the value is a count, not a time, distance, currency amount, or other physical measurement.