虽然 @Felipe Hoffa 是正确的,COUNT(DISTINCT x, 10000) 可以让您获得更精确的数字,但可以通过将 10,000 进一步提高数量高达 1,000,000(我认为这是目前最大的“采样”率:BigQuery Documentation of Count Distinct)。由于在 BigQuery 中使用 Google Anaytics Premium 数据的人并不多,因此这些问题的社区非常小。作为每天在 BigQuery 中使用 GA 数据的人,我可以告诉您,我的研究和验证表明,以下指标定义与 Google Analytics UnSampled Report 将告诉您的内容非常接近。
会话
count(distinct concat(fullvisitorid, string(visitid)), 1000000) as sessions
用户
count(distinct fullvisitorid, 1000000) as users
新用户
count(distinct (case when totals.newvisits <> 0 then concat(fullvisitorid, string(visitid)) end), 1000000) as new_users
浏览量
sum(case when hits.type = "PAGE" then 1 else 0 end) as pageviews
独特的浏览量
count(distinct (case when hits.type = "PAGE" then concat(fullvisitorid, string(visitid), hits.page.pagepath) end), 1000000) as unique_pageviews
反弹
count(distinct (case when totals.bounces <> 0 then concat(fullvisitorid, string(visitid)) end), 1000000) as bounces