Could you please share a query that retrieves the ...
# ask-questions
w
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
do you have a revenue metric? You can choose the sum aggregation for that metric (or make a copy of it)
w
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'
@strong-mouse-55694 maybe you know how to do this?
s
It'll depend on how your data is structured. Does the purchase event include an amount? If you're using the e-commerce events in GA4, then see this guide: https://www.ga4bigquery.com/ecommerce-dimensions-metrics-ga4/
w
Graham solved this one for me, thank you Ryan!
1
f
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'
🙌 1