GA360访问ID上的平均Analytics(分析)功能,用于LatencyTracking

时间:2018-08-09 13:02:39

标签: google-analytics google-bigquery

希望从我们的GA 360导出中获取对访问者的平均延迟跟踪。

设置以下查询,但收到以下错误,并且我不确定为什么,因为所有这些都是聚合函数: SELECT列表表达式引用hits.latencyTracking.serverResponseTime,它既不在[3:5时也未进行分组或聚合。 ]

select 
TIMESTAMP_SECONDS(visitStartTime) as visitStartTime,
AVG(hits.latencyTracking.serverResponseTime) OVER (PARTITION BY visitid) as avgServerResponseTime,
AVG(hits.latencyTracking.serverConnectionTime) OVER (PARTITION BY visitid) as avgServerConnectionTime,
AVG(hits.latencyTracking.domInteractiveTime) OVER (PARTITION BY visitid) as avgdomInteractiveTime,
AVG(hits.latencyTracking.pageLoadTime) OVER (PARTITION BY visitid) as avgpageLoadTime
from `xxx.xxx.ga_sessions_2018*`,
UNNEST(hits) AS hits
where hits.latencyTracking.serverResponseTime is not null
group by visitStartTime

2 个答案:

答案 0 :(得分:1)

查询的编写方式-AVG()不仅是Aggregate Function,而且是Aggregate Analytic Function

要使其正常工作,您可以删除OVER(),这样AVG()就会真正成为此处对应于GROUP BY的聚合函数

select 
TIMESTAMP_SECONDS(visitStartTime) as visitStartTime,
AVG(hits.latencyTracking.serverResponseTime) as avgServerResponseTime,
AVG(hits.latencyTracking.serverConnectionTime) as avgServerConnectionTime,
AVG(hits.latencyTracking.domInteractiveTime) as avgdomInteractiveTime,
AVG(hits.latencyTracking.pageLoadTime) as avgpageLoadTime
from `xxx.xxx.ga_sessions_2018*`,
UNNEST(hits) AS hits
where hits.latencyTracking.serverResponseTime is not null
group by visitStartTime   

答案 1 :(得分:0)

同时使用windowsgroup by可能会造成混淆。 在您的情况下,甚至没有必要,也不需要展平-您可以编写简单的子查询来获取每个会话的号码:

SELECT   
  TIMESTAMP_SECONDS(visitStartTime) AS visitStartTime,
  (
    SELECT AVG(latencyTracking.serverResponseTime) 
    FROM t.hits
    WHERE latencyTracking.serverResponseTime IS NOT NULL) AS avgServerResponseTime,
  (
    SELECT AVG(latencyTracking.serverConnectionTime)
    FROM t.hits
    WHERE latencyTracking.serverConnectionTime IS NOT NULL) AS avgServerConnectionTime,
  (
    SELECT AVG(latencyTracking.domInteractiveTime)
    FROM t.hits
    WHERE latencyTracking.domInteractiveTime IS NOT NULL ) AS avgdomInteractiveTime,
  (
    SELECT AVG(latencyTracking.pageLoadTime)
    FROM t.hits
    WHERE latencyTracking.pageLoadTime IS NOT NULL ) AS avgpageLoadTime
FROM `xxx.xxx.ga_sessions_2018*`

它也不涉及分组,这使分组速度更快。