根据hits.page.pageTitle计算会话数

时间:2017-10-23 11:24:31

标签: session google-analytics google-bigquery page-title

我正在查询包含Google Analytics导出的BigData。 寻找访问包含字符串' rafinha'的页面的所有会话。所以我使用这个查询

SELECT
channelGrouping as Default_Channel_Grouping, 
SUM (totals.visits) as Sessions,
SUM(case when hits.page.pageTitle CONTAINS ('rafinha - Dugout') then 1 else 0 end) as Rafinha_Sessions
FROM

(TABLE_DATE_RANGE([133338516.ga_sessions_], 
                TIMESTAMP('2017-10-01'), 
                TIMESTAMP('2017-10-20')))   
GROUP BY Default_Channel_Grouping
ORDER BY Sessions DESC

我没有得到BigQuery和Google Analytics之间的数字匹配>收购>信道

2 个答案:

答案 0 :(得分:0)

尝试

SELECT
  channelGrouping,
  COUNT(1) AS Sessions,
  SUM(isRafinhaSession)
FROM (
  SELECT
    channelGrouping,
    SOME(hits.page.pageTitle CONTAINS ('rafinha - Dugout')) WITHIN RECORD     isRafinhaSession
  FROM (TABLE_DATE_RANGE([133338516.ga_sessions_], TIMESTAMP('2017-10-01'), TIMESTAMP('2017-10-20')))
  WHERE
    totals.visits=1)
GROUP BY
  1
ORDER BY
  Sessions DESC

内部查询在会话级别(WITHIN RECORD)查找您的条件(SOME聚合多个具有OR的布尔值) - 而外部查询允许对整个表进行分组和聚合。

答案 1 :(得分:0)

这是与数据相关的问题,因此使用较低的比较解决了问题,如下所示,谢谢你们。

SELECT
  channelGrouping,
  COUNT(1) AS Sessions,
  SUM(nvl(isRafinhaSession,1)) as RafinhaSession
FROM (
  SELECT
    channelGrouping,
    some(LOWER(hits.page.pageTitle) CONTAINS LOWER(('rafinha - Dugout')) ) WITHIN RECORD     isRafinhaSession
  FROM (TABLE_DATE_RANGE([133338516.ga_sessions_], TIMESTAMP('2017-10-01'), TIMESTAMP('2017-10-20')))
  WHERE
    totals.visits=1)
GROUP BY
  1
ORDER BY
  Sessions DESC