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

岁酱吖の 提交于 2020-01-14 13:44:07

问题


https://support.google.com/analytics/answer/1257084?hl=en-GB#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?


回答1:


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.

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

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.




回答2:


The other queries didn't match the Unique Pageviews metric in my Google Analytics account, but the following did:

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
)



回答3:


For uniquePageViews you better want to use something like this:

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;


来源:https://stackoverflow.com/questions/31041127/how-to-get-the-google-analytics-definition-of-unique-page-views-in-bigquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!