简体   繁体   English

如何在 Bigquery 中获取独特页面浏览量的 Google Analytics 定义

[英]How to get the Google Analytics definition of unique page views in Bigquery

https://support.google.com/analytics/answer/1257084?hl=en-GB#pageviews_vs_unique_views https://support.google.com/analytics/answer/1257084?hl=zh-CN#pageviews_vs_unique_views

I'm trying to calculate the sum of unique page views per day which Google analytics has on its interface How do I get the equivalent using bigquery?我正在尝试计算 Google Analytics 在其界面上每天的独特页面浏览量的总和 如何使用 bigquery 获得等效值?

There are two ways how this is used: 使用方法有两种:

1) One is as the original linked documentation says, to combine full visitor user id, and their different session id: visitId, and count those. 1)一个是原始链接文档所说的,用于组合完整的访问者用户ID和他们的不同会话ID:visitId,并计算这些。

SELECT
  EXACT_COUNT_DISTINCT(combinedVisitorId)
FROM (
  SELECT
    CONCAT(fullVisitorId,string(VisitId)) AS combinedVisitorId
  FROM
    [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910]
  WHERE
    hits.type='PAGE' )

2) The other is just counting distinct fullVisitorIds 2)另一个是计算不同的fullVisitorIds

SELECT
  EXACT_COUNT_DISTINCT(fullVisitorId)
FROM
  [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910]
WHERE
  hits.type='PAGE'

If someone wants to try out this on a sample public dataset there is a tutorial how to add the sample dataset . 如果有人想在示例公共数据集上尝试此操作,则有一个如何添加示例数据集教程

The other queries didn't match the Unique Pageviews metric in my Google Analytics account, but the following did: 其他查询与我的Google Analytics帐户中的“唯一身份浏览量”指标不符,但以下情况如下:

SELECT COUNT(1) as unique_pageviews
FROM (
    SELECT 
        hits.page.pagePath, 
        hits.page.pageTitle,
        fullVisitorId,
        visitNumber,
        COUNT(1) as hits
    FROM [my_table]
    WHERE hits.type='PAGE' 
    GROUP BY 
        hits.page.pagePath, 
        hits.page.pageTitle,
        fullVisitorId,
        visitNumber
)

For uniquePageViews you better want to use something like this: 对于uniquePageViews,你最好使用这样的东西:

SELECT
  date,
  SUM(uniquePageviews) AS uniquePageviews
FROM (
  SELECT
    date,
    CONCAT(fullVisitorId,string(VisitId)) AS combinedVisitorId,
    EXACT_COUNT_DISTINCT(hits.page.pagePath) AS uniquePageviews
  FROM
    [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910]
  WHERE
    hits.type='PAGE'
  GROUP BY 1,2)
GROUP EACH BY 1;

So, in 2022 EXACT_COUNT_DISTINCT() seems to be deprecated..因此,在 2022 年,EXACT_COUNT_DISTINCT() 似乎已被弃用。
Also for me the following combination of对我来说还有以下组合
fullvisitorid+visitNumber+visitStartTime+hits.page.pagePath fullvisitorid+visitNumber+visitStartTime+hits.page.pagePath
was always more precise than the above solutions:总是比上述解决方案更精确:

SELECT 
    SUM(Unique_PageViews)
FROM
    (SELECT 
        COUNT(DISTINCT(CONCAT(fullvisitorid,"-",CAST(visitNumber AS string),"-",CAST(visitStartTime AS string),"-",hits.page.pagePath))) as Unique_PageViews
    FROM 
        `mhsd-bigquery-project.8330566.ga_sessions_*`,
        unnest(hits) as hits
    WHERE 
        _table_suffix BETWEEN '20220307'
        AND '20220313' 
        AND hits.type = 'PAGE')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM