You've successfully subscribed to GA4BigQuery
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Custom dimensions & metrics

Join 1,800+ other professionals and receive a monthly newsletter packed with GA4 & BigQuery news, tips & tricks

Great! Check your inbox and click the link to confirm your subscription
Please enter a valid email address!
Already have an account? Sign in
💡
This article is about GA3 - Universal Analytics

This example query contains all following Google Analytics custom dimensions and metrics. If you only need one dimension or metric, look at the -- comments in the example query and copy the part you need from the select clause. Make sure that you also add any additional conditions (in the from, where, group by and order by) that are necessary to calculate the results correctly.

Custom dimensions

  • custom dimension xx (user)
  • custom dimension xx (session)
  • custom dimension xx (hit)
  • custom dimension xx (product)

Custom metrics

  • custom metric xx value (hit)
  • custom metric xx value (product)

Example query

-- most sample set custom dimensions return null values

select
  -- custom dimension xx (user)
  (select value from unnest(session.customdimensions) where index = 3 group by value) as custom_dimension_xx_user,
  -- custom dimension xx (session)
  (select value from unnest(session.customdimensions) where index = 4 group by value) as custom_dimension_xx_session,
  -- custom dimension xx (hit)
  (select value from unnest(hits.customdimensions) where index = 2 group by value) as custom_dimension_xx_hit,
  -- custom dimension xx (product)
  (select value from unnest(product.customdimensions) where index = 10 group by value) as custom_dimension_xx_product,
  -- custom metric xx (hit)
  sum((select value from unnest(hits.custommetrics) where index = 1)) as custom_metric_xx_hit,
  -- custom metric xx (product)
  sum((select value from unnest(product.custommetrics) where index = 2)) as custom_metric_xx_product
from
  `bigquery-public-data.google_analytics_sample.ga_sessions_20160801` as session,
  unnest(hits) as hits,
  unnest(product) as product
where
  totals.visits = 1
group by
  custom_dimension_xx_user,
  custom_dimension_xx_session,
  custom_dimension_xx_hit,
  custom_dimension_xx_product
order by
  custom_metric_xx_hit desc