Join 2,600+ other professionals and receive a monthly newsletter packed with GA4 & BigQuery news, tips & tricksAlready have an account? Sign in
A lot of Google Analytics 4 dimensions and metrics can be derived straight from the tables without performing calculations on the data. With the help of
parse for dates or timestamps we can do the trick.
Other dimensions and metrics that you might need are a bit harder to access. You will have to (re)calculate them, which can require some serious SQL-skills.
While designing the course Query GA4 Data In Google BigQuery I've learned a lot about best practices to calculate dimensions and metrics. To share this knowledge with you I will provide a combined query for default dimensions and metrics, and a single example query for every non-default dimension or metric.
As always, please let me know if you have any feedback or suggestions to improve the quality of this content.
Default ecommerce dimensions
Default ecommerce metrics
-- commentsin the example query below for names and definitions and copy the part you need from the
selectclause. Make sure that you also add any additional conditions (i.e.
order by) that are necessary to calculate the results correctly. E.g, the query below is ungrouped, so every row corresponds to an event and may contain duplicate rows.
select -- transaction id (dimension | the transaction id of the ecommerce transaction) ecommerce.transaction_id, -- total item quantity (metric | total number of items in this event, which is the sum of items.quantity) sum(ecommerce.total_item_quantity) as total_item_quantity, -- purchase revenue in usd (metric | purchase revenue of this event, represented in usd with standard unit, -- populated for purchase event only) sum(ecommerce.purchase_revenue_in_usd) as purchase_revenue_in_usd, -- purchase revenue (metric | purchase revenue of this event, represented in local currency with standard unit, -- populated for purchase event only) sum(ecommerce.purchase_revenue) as purchase_revenue, -- refund value in usd (metric | the amount of refund in this event, represented in usd with standard unit, -- populated for refund event only) sum(ecommerce.refund_value_in_usd) as refund_value_in_usd, -- refund value (metric | the amount of refund in this event, represented in local currency with standard unit, -- populated for refund event only) sum(ecommerce.refund_value) as refund_value, -- shipping value in usd (metric | the shipping cost in this event, represented in usd with standard unit) sum(ecommerce.shipping_value_in_usd) as shipping_value_in_usd, -- shipping value (metric | the shipping cost in this event, represented in local currency) sum(ecommerce.shipping_value) as shipping_value, -- tax value in usd (metric | the tax value in this event, represented in usd with standard unit) sum(ecommerce.tax_value_in_usd) as tax_value_in_usd, -- tax value (metric | the tax value in this event, represented in local currency with standard unit) sum(ecommerce.tax_value) as tax_value, -- unique items (metric | the number of unique items in this event, based on item_id, item_name, and item_brand) sum(ecommerce.unique_items) as unique_items from -- change this to your google analytics 4 export location in bigquery `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_20201130` where event_name = 'purchase' group by transaction_id