Could you please share a query that retrieves the “total revenue” from the purchase event in GA4? I would like to add it as a metric.
Thank you!
f
fresh-football-47124
09/13/2024, 4:00 PM
do you have a revenue metric? You can choose the sum aggregation for that metric (or make a copy of it)
w
wide-cartoon-5349
09/13/2024, 4:59 PM
I don't have the revenue metric in GB. I have the purchase event, but since total revenue isn’t tracked as an event (though it is a metric in GA4), I’m not sure how to incorporate it.
Here’s the SQL for the purchase event that we currently use in GA4:
Copy code
SELECT
2 user_pseudo_id as anonymous_id,
3 TIMESTAMP_MICROS(event_timestamp) as timestamp
4FROM
5 `data-coder-429114.analytics_278323540.events_*`
6WHERE
7 (
8 (
9 _TABLE_SUFFIX BETWEEN '{{date startDateISO "yyyyMMdd"}}' AND '{{date endDateISO "yyyyMMdd"}}'
10 )
11 OR (
12 _TABLE_SUFFIX BETWEEN 'intraday_{{date startDateISO "yyyyMMdd"}}' AND 'intraday_{{date endDateISO "yyyyMMdd"}}'
13 )
14 )
15 AND event_name = 'purchase'
wide-cartoon-5349
09/16/2024, 3:33 PM
@strong-mouse-55694 maybe you know how to do this?
For others who may have the same problem - here is a sample Revenue query for a GA4 purchase event
Copy code
SELECT
user_pseudo_id as anonymous_id,
TIMESTAMP_MICROS(event_timestamp) as timestamp,
value_param.value.int_value as value
FROM
`data-coder-429114.analytics_278323540.events_*`,
UNNEST(event_params) AS value_param
WHERE
(
(
_TABLE_SUFFIX BETWEEN '{{date startDateISO "yyyyMMdd"}}' AND '{{date endDateISO "yyyyMMdd"}}'
)
OR (
_TABLE_SUFFIX BETWEEN 'intraday_{{date startDateISO "yyyyMMdd"}}' AND 'intraday_{{date endDateISO "yyyyMMdd"}}'
)
)
AND event_name = 'purchase'
AND value_param.key = 'value'