×

Google Analytics 4 Custom Metrics Guide

Eric Huguenin

At first glance, a custom metric might seem straightforward — and it is. You add a custom parameter that uses numerical values to your events.

However, it’s important to account for multiple factors, such as measurement units, counting techniques, deciding between using an Event count (or Event value) versus a custom metric, and the potential for skewed data due to sampling.

This post aims to demystify Google Analytics 4 custom metrics, address some common challenges with examples, and guide you through creating them.

GA4 For Beginners

Master the basics with our FREE GA4 Course for Beginners

🚨Note: This is not mandatory as this post covers the essentials. However, as a prerequisite to making the most of this post, it’s better to have a good grasp of what events and parameters are and custom dimensions (also known as custom definitions) in Google Analytics 4.

What we’ll cover:

Let’s dive in!

What is a GA4 Metric?

A metric is a way to measure or count data using numbers. For instance, if you want to know the number of visitors to your website today, the 100 visitors is a quantitative measurement, which is a metric.

In analytics, this specific metric is called Total users.

Essentially, a metric answers the question, “How much?” or “How many?”

One simple way to understand metrics is that you can apply math to them. An example is the event count metric, which shows how many times an event occurred.

For example, if you click a button five times, the event count will show as five.

What are Google Analytics 4 Custom Metrics?

A custom metric in GA4 is numerical information sent as additional information with your Events, and it can be counted or measured. It is a type of custom parameter.

GA4 provides a list of parameters you should use with their events. However, if these don’t apply to your situation, the data you provide becomes custom parameters. If this data uses numbers, then it is a custom metric.

But that is only the general understanding.

There are two types of Google Analytics 4 custom metrics:

  1. Custom metrics
  2. Calculated metrics

1. Custom metrics

Here GA4 is reusing the same definition.

2. Calculated metrics

Calculated metrics are mathematical formulas applied to a combination of existing metrics or custom metrics. This allows you to create new metrics that are more useful to your needs.

A good example provided by the Analytics help center is the Shipping revenue as a percentage of purchase revenue.

Here are some benefits of using the Shipping revenue as a percentage of revenue for businesses:

  1. Understanding if shipping fees are covering logistics delivery costs. If the percentage is too low, this means they may be undercharging.
  2. Benchmarking to compare shipping fees with competitors.
  3. Developing a pricing strategy to find relationships between shipping and purchase revenue. If the percentage is high, this may lead to cart abandonment as customers may perceive your shipping costs as too high.

The issue is that the shipping revenue as a percentage of the purchase revenue metric doesn’t exist in GA4. Therefore, you’ll have to create it.

This is how you’ll create it in GA4:

Calculated metrics example

🚨Note: MeasureSchool has a dedicated post on calculated metrics. Please check it out.

How Do I Add Custom Metrics?

We’ll cover two examples later step-by-step, but here’s an overview of the steps involved when creating a custom metric: 

  1. Don’t create a custom event parameter if a predefined metric already exists. If it does, you don’t need to create a custom metric. 
  2. Add the custom event parameter to your website or mobile app. Usually, you will use Google Tag Manager (GTM) to do it. It’ll look something like this:
Example of custom event parameter
  1. Make sure the custom event parameter is being collected. For example, you can select an event in the Event count by Event name card in the Realtime report. To illustrate:
Incoming events in the real-time report
  1. Make sure you’re an editor or administrator.

Then in GA4, follow these steps:

  1. Go to Admin.
  2. Click Custom Definitions under Data Display.
  3. Click the Custom Metrics tab.
  4. Click Create Custom Metric.
Steps to create a custom metric

You can copy our setup:

New custom metric fields

Understanding the New Custom Metrics Fields

FieldDescription
Metric nameThe name that appears in reports should be descriptive. For example: ‘Points after level.’
You don’t need to use the snake case, etc.
ScopeCan’t change this. Custom metrics are always event-scoped.
DescriptionOptional text used to identify the custom metric.
Event parameterType the parameter name that you used for collection. For example, that will be the event parameter name you used in Google Tag Manager. For example: “game_points”
You can’t change this field after you save the new dimension.
Unit of measurementStandard
This is a standard total count: when you want to accumulate the frequency value of an action, you can assign a specific value to each occurrence. For example, if each click has a value of 1, then five clicks will accumulate to a total of 5. So, if you assign a value of 5 to each click, 10 clicks will accumulate to a total of 50.
Currency
When you select Currency, you must also identify if the custom metric is a cost and/or revenue metric under Data type. When you identify the custom metric as a cost and/or revenue metric, you can restrict access to it when you configure user roles that restrict access to cost and/or revenue metrics.
Distance
Feet – Miles – Meters – Kilometers
These options allow you to compare distances with different units of measurement. For example, you can compare a metric in meters with one in kilometers.
Time
Milliseconds – Seconds – Minutes – Hours
These options allow you to compare times with different units of measurement. For example, you can compare a metric in seconds with one in minutes.

Lastly, wait around 24 hours for the data to be processed. Then: 

  1. In your left navigation panel, click Explore and start a new exploration.
Creating an Exploration
  1. Click the plus + sign near Metrics to add a metric.
Adding a metric
  1. Go to the Custom tab and expand the Custom field.
Expanding the custom metric name field
  1. Select your custom metric to import it.
  2. Click Import.

Google Analytics 4 Custom Metrics Examples

While there are many possibilities, we’ll focus on two situations that will effectively illustrate this concept and help you apply it to your situation. We will explore:

  1. Gaming scenario:
    How to track accumulated points in a game.
  1. Tracking form submissions:
    A method to calculate the number of forms submitted.
    Note that this approach will likely be relevant to most of your needs.

We’ll examine each scenario’s configuration in GTM and GA4.

1. Gaming example

In the online Arkadium snake game, a popup appears with the game score after every play. As you can see here:

Snake game online score example

GTM Configuration:

We will send the GA4 recommended parameter called level_end when a user finishes the game. Then, we add the value parameter.

To capture this value, I used a custom Javascript variable. This is the {{CJS – Game score}} that you see in the screenshot.

GTM gaming GA4 event configuration

This custom JavaScript variable uses a JavasScrip that returns the CSS value. If you’re interested in trying it out, in GTM go to Variables → User-Defined Variables → Custom JavaScript. 

Copy-paste this code:

function captureText(){
  var element = document.querySelector(".GameEnd-scoresValue-dX2EI0ud");
  if(element) {
    var text = element.innerText.trim();  
    return text;}  
}

My CSS class is GameEnd-scoresValue-dX2EI0ud. Make sure to replace it in the brackets of the document.querySelector() with yours. 

For the trigger, I used an Element Visibility trigger for the same CSS selector to the score value. If you don’t know what CSS is, please check out Matches CSS Options in Google Tag Manager.

GA4 Configuration:

Use the DebugView or Realtime report to ensure your custom parameter is being collected. 

  1. Go to Reports.
  2. Click Realtime.
  3. Click your event name in the Event count by Event name card.
Accessing an event in the real-time report
  1. Find and click the value in the Event parameter key.
Event parameter key
  1. Click value.
Event parameter value

To create your custom metric, go to: 

  1. Admin.
  2. Click Custom Definitions in the Data Display box.
Accessing Custom definitions
  1. Select the Custom Metrics tab.
  2. Click Create Custom Metric.
Custom metrics tab

2. Number of Form Submissions

We’re going to use the form submission example to show you how to track an accumulating value. This can be applied to almost any scenario, such as how often a video has been viewed.

Here, the value of the custom parameter is being accumulated. For example, if we use the value 1, and 5 people submit the form, we’ll see 5 forms submitted in GA4. So, 1+1+1+1+1.

In Tag Manager, the setup in your GA4 event parameters will, therefore, be:

Event parameter for the number of form submissions

Here’s what the setup looks like in GA4:

Number of forms sent custom metric in GA4

So, instead of using Event count, you could use a more descriptive metric such as the form_sent parameter we used.

Event count vs custom metric comparison

Avoid These Two Confusing Factors 

The creation and analysis of Google Analytics 4 custom metrics can sometimes be muddled by two factors:

  1. The Value Parameter
  2. Sampling

1. The Value Parameter

The Analytics Help Center provides an example of how custom metrics work, which we have reproduced (with images) in the Gaming Example section above.

Google’s example is:

In addition to the recommended event parameters for the level_end event, you add a value event parameter that counts the number of points someone earned when they completed a level. To analyze the value event parameter, you create the following custom metric:

  • Metric name: Points after level
  • Description: The number of points at the end of a level
  • Event parameter: value
  • Unit of measurement: Standard

Here are the suggested parameters for the level_end event in GA4’s developer documentation.

Level_end event recommended parameters

Here’s what we have in Tag Manager if we include the value parameter from their example:

Value parameter added

The problem here is the value parameter.

Value is a predefined parameter indicated by the ticks next to it. Before you create a custom metric, you must verify that a similar one doesn’t already exist. This prevents the unnecessary creation of duplicate custom metrics.

The value parameter is widely used, as you’ll find it in many events, such as eCommerce events or recommended events such as generate_lead:

Generate lead value parameter

It’s important to note that once you have used a parameter for a custom metric, you can’t use it again for another custom metric. 

For instance, after using value as a parameter for a custom metric in our gaming example, we can’t use value for another custom metric. Trying this will trigger the following message:

There is already a dimension or metric registered with this parameter name. As in this image:

Existing custom parameters not accepted

So, the next questions are:

  1. Why transform value into a custom metric if it’s a recommended parameter?
  2. Does this mean you won’t be able to use it for other custom metrics?

The confusion comes from not remembering that GA4 creates the Event value metric using the recommended value parameter (the one available in many Recommended events).

If you go to Explorations and try to find the predefined value parameter by writing the value, you won’t find anything. Instead, Event value will be available.

Event value available in Explorations

You can learn more by filtering by value the list of Event parameters:

List of GA4 existing parameters

Many of the dimensions and metrics come from event parameters on your site or app. This means that as a custom metric, the term value is available to be used.

However, registering the word value as a custom metric means you can’t use it again for another custom metric.

If you accidentally reuse it when sending an event, use then the Event count metric in GA4 reports (no need to create a new custom metric) or rename the parameter to create the custom metric.

We strongly recommend using more descriptive parameters like game_points or video_views for better clarity and organization.

2. Sampling

If you’re used to working with custom metric values that don’t include decimals, it can be surprising to see them suddenly appear in your reports.

For example, the game points we tracked in the previous examples should not have had decimals. Yet, here’s what can happen:

Custom metrics with decimals

If you look closely, this Exploration doesn’t use all the data. It’s sampled, which is why you see decimals.

The red data quality icon means GA4 has applied thresholding due to insufficient data. Some data is withheld to protect user privacy by preventing inferences about sensitive information.

You can usually fix this by increasing the date range.

Summary

We’ve covered what you need to know about Google Analytics 4 custom metrics, including what they are and how to use them in various situations.

We’ve also provided examples to help you apply them to your cases. These examples also showed how they appear in your reports and the potential issues you might encounter.

It’s great to know which metrics you need, but applying them effectively is another story. That’s why we recommend our quick read on 11 Google Analytics 4 (GA4) Metrics To Better Understand User Behavior.

Custom metrics are fun! Do you have any examples to share with us?

Eric Huguenin

Eric is a web analytics content creator at MeasureSchool. He holds certifications in Google Analytics and Google Tag Manager at the CXL Institute. He enjoys breaking down marketing topics into easier-to-understand articles.

Related Posts

WooCommerce Google Analytics 4 Tracking blog featured image

WooCommerce Google Analytics 4 Tracking Guide

Eric Huguenin

Google Analytics 4 Cookieless Tracking blog featured image

Demystifying Google Analytics 4 Cookieless Tracking

Eric Huguenin

Google Tag Manager Lookup Table Variable blog featured image

How to Use Google Tag Manager Lookup Table Variable

Usman Qureshi

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

NOW IT'S TIME TO

Start Measuring Like A Master

Itching to jump into the world of MeasureMasters? This is what you have to look forward to.

Ready to take your digital marketing to the next level?

Subscribe to our newsletter and stay ahead with our latest tips and strategies.