Total Sessions in BigQuery vs Google Analytics Reports

后端 未结 3 1095
情歌与酒
情歌与酒 2020-12-01 15:16

I\'m just learning BigQuery so this might be a dumb question, but we want to get some statistics there and one of those is the total sessions in a given day.

To do s

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 15:55

    standardsql

    Simply SUM(totals.visits) or when using COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitStartTime AS STRING) )) make sure totals.visits=1!

    If you use visitId and you are not grouping per day, you will combine midnight-split-sessions!

    Here are all scenarios:

    SELECT
      COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitStartTime AS STRING) )) allSessionsUniquePerDay,
      COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitId AS STRING) )) allSessionsUniquePerSelectedTimeframe,
      sum(totals.visits) interactiveSessionsUniquePerDay, -- equals GA UI sessions
      COUNT(DISTINCT IF(totals.visits=1, CONCAT(fullVisitorId, CAST(visitId AS STRING)), NULL) ) interactiveSessionsUniquePerSelectedTimeframe,
      SUM(IF(totals.visits=1,0,1)) nonInteractiveSessions
    FROM
      `project.dataset.ga_sessions_2017102*`
    

    Wrap up:

    • fullVisitorId + visitId: useful to reconnect midnight-splits
    • fullVisitorId + visitStartTime: useful to take splits into account
    • totals.visits=1 for interaction sessions
    • fullVisitorId + visitStartTime where totals.visits=1: GA UI sessions (in case you need a session id)
    • SUM(totals.visits): simple GA UI sessions
    • fullVisitorId + visitId where totals.visits=1 and GROUP BY date: GA UI sessions with too many chances for errors and misunderstandings

提交回复
热议问题