我使用以下查询查询每个主机名的浏览量,匹配数,事件和会话数(普通SQL):
SELECT
hits.page.hostname,
SUM(IF(hits.type = 'PAGE',1,0)) AS pageviews,
COUNT(hits.hitNumber) AS hits,
SUM(IF(hits.type = 'EVENT',1,0)) AS events,
COUNT(DISTINCT CASE WHEN hits.isInteraction IS TRUE THEN CONCAT(CAST(fullvisitorid as string),CAST(visitid as string)) END) AS sessions
FROM `XXX_sessions_*`, UNNEST(hits) AS hits
WHERE _TABLE_SUFFIX BETWEEN '20181231' AND '20181231'
GROUP BY 1
如果将结果与Google Analytics(分析)进行比较,则浏览量和匹配数是相同的,但是事件和会话之间却有所不同。为什么?我做错了什么? 感谢您的帮助!
编辑: 我设法通过以下方式获得了正确的事件数:
COUNT(hits.eventInfo.eventCategory) AS totalEvents
但仍然存在会话问题。
Edit2: 我找到了解决方案。 Google Analytics(分析)不考虑主机在会话中是否发生更改。因此,仅考虑第一个命中的主机。
(SELECT page.hostname FROM UNNEST(hits) WHERE hitnumber = (SELECT MIN(hitnumber) FROM UNNEST(hits)))