Skip to main content

GA4 Calculated Metrics

How-to guide for working with GA4 API calculated metrics in Gauge Widget

Rad Basta avatar
Written by Rad Basta
Updated over 2 weeks ago

Reportz can’t resolve {{metric_compare}} until three things line up:
(1) the exact GA-4 metric slug (average_session_duration)
(2) append _compare only after you’ve switched the widget to Previous period or Custom compare mode
(3) formula wrongly returns a plain number


1 Usual Calculated Metrics Widget and Formula Setup Challenges

Root cause

What’s happening

Wrong placeholder

GA-4 exposes the metric as averageSessionDuration (API) / Average session duration (UI). Reportz expects the slug in snake-case → average_session_duration. If you write {{average_session_duration_compare}} the platform knows what to fetch; {{metric_compare}} is a dummy. 

No comparison window

_compare tokens populate only when the widget’s Compare to switch is on and a previous period is defined. Without that, the placeholder is empty → division by zero or NULL. 

Gauge range mismatch

A week-over-week ratio can easily exceed 100 %. If the Gauge widget is hard-capped at 100 it shows maxed-out (or error). 


2 Grab the right metric

Platform

Metric name

Notes

GA-4 UI

Average session duration

Not shown by default; add it via Customize report. 

GA-4 Data API

averageSessionDuration

Returns seconds (float). 

Reportz slug

average_session_duration

Hover any GA widget → Description tab to confirm slug. 


3 Build the calculated metric

Metric name: Avg Session Duration WoW %

Metric type: Percent

Formula: ( {{average_session_duration}} /

---

{{average_session_duration_compare}} ) * 100

What it does – If this week’s average is 52 s and last week’s is 50 s, the gauge widget reads 104 %. Anything under 100 % means a drop.

Alternative – If you prefer Δ percentage-points (-10 % … +10 %) use:

(({{average_session_duration}}-{{average_session_duration_compare}}) / {{average_session_duration_compare}}) * 100.


4 Widget settings checklist

  • Widget type → Gauge

  • Compare to → Previous 7 days (or custom range)

  • Min / Max

  • Ratio approach → set 0-200 so improvements >100 % show up.

  • Δ approach → set –100 to +100 (Reportz allows negative if you untick “Clamp to 0”).

- Decimals → 0 or 1 for cleaner dial.

- Label → “Avg. Session Duration vs Last Week”.


5 Copy-paste reply for the client

Here’s how to make the gauge work:

Edit the widget and switch Compare to → Previous 7 days.

Click Add calculated metric and paste the formula below:

( {{average_session_duration}} / {{average_session_duration_compare}} ) * 100

Set Metric type → Percent and Gauge range → 0-200 (so improvements over 100 % display).

Save – the needle now shows how this week’s average session duration stacks up against last week.

100 % = same performance; 120 % = 20 % longer sessions; 80 % = 20 % shorter.

Feel free to tweak the range or use the difference formula if you’d rather see +/- percent change.


6 Want to double-check the numbers?

  • In GA-4, open Explore → Free-form, add Date as a dimension, averageSessionDuration as a metric, and compare Last 7 days vs Previous 7 days to ensure the base figures match. 

  • Expect small discrepancies (seconds rounding); Reportz shows the API result, GA-4 UI sometimes applies sampling. 

Did this answer your question?