2017-05-26 67 views
0

我已设法计算ISO周的总事件数,但未使用BigQuery为给定Google Analytics事件计算唯一事件。在检查GA时,total_events与点上的GA接口相匹配,但unique_events已关闭。你知道我怎么能解决这个问题吗?在BigQuery中计数Google Analytics(分析)唯一事件

查询:

SELECT INTEGER(STRFTIME_UTC_USEC(PARSE_UTC_USEC(date),"%V")) iso8601_week_number, 
hits.eventInfo.eventCategory, 
hits.eventInfo.eventAction, 
COUNT(hits.eventInfo.eventCategory) AS total_events, 
EXACT_COUNT_DISTINCT(fullVisitorId) AS unique_events 
FROM 
    TABLE_DATE_RANGE([XXXXXX.ga_sessions_], TIMESTAMP('2017-05-01'), TIMESTAMP('2017-05-07')) 
WHERE 
    hits.type = 'EVENT' AND hits.eventInfo.eventCategory = 'BIG_Transaction' 
GROUP BY 
iso8601_week_number, hits.eventInfo.eventCategory, hits.eventInfo.eventAction 
+0

如果在where子句中添加AND AND totals.visits = 1,会发生什么情况?它工作吗? –

+0

Hi @Will the unique_events在添加AND totals.visits = 1时仍然关闭。你知道我可以尝试的其他事情吗? –

+0

嗯不知道为什么它不工作。其他的事情是确保你的'TABLE_DATE_RANGE'同时不包括intradays和ga_sessions表(可能导致数据重复),也可能确定GA中的分析是否正确完成。除此之外,我在这个查询中看不到任何错误(如果有的话,我看不到它)。另外,我建议您使用标准版本的BQ。 https://cloud.google.com/bigquery/docs/reference/standard-sql/它好多了。 –

回答

0

我认为问题是,你只计算唯一访问者人数已经完成了指定的动作,而GA定义独特的事件“的次数的日期时范围内会话包含特定维度“

因此,我只想改变你的代码下面:

SELECT INTEGER(STRFTIME_UTC_USEC(PARSE_UTC_USEC(date),"%V")) iso8601_week_number, 
hits.eventInfo.eventCategory, 
hits.eventInfo.eventAction, 
COUNT(hits.eventInfo.eventCategory) AS total_events, 
EXACT_COUNT_DISTINCT(CONCAT(fullVisitorId, STRING(visitId))) AS unique_events 
FROM 
    TABLE_DATE_RANGE([XXXXXX.ga_sessions_], TIMESTAMP('2017-05-01'), TIMESTAMP('2017-05-07')) 
WHERE 
    hits.type = 'EVENT' AND hits.eventInfo.eventCategory = 'BIG_Transaction' 
GROUP BY 
iso8601_week_number, hits.eventInfo.eventCategory, hits.eventInfo.eventAction 

这应该给你,有鉴于事件会话的重复计数。

+0

如何用标准SQL语法来完成它? – igsm

0

在谷歌分析的独特事件的定义是:

与类别/操作/标签 值的事件被视为一个会话中至少一次的次数的计数。

换句话说,发送特定事件(由类别,动作和标签定义)的会话数量。在您的查询中,您可以统计具有该事件的唯一身份访问者的数量,而您需要统计会话的数量,并记住具有不同标签的事件应计为不同的唯一事件(尽管我们只对类别感兴趣行动)。

一种可能的方式来解决你的代码是:

SELECT 
    INTEGER(STRFTIME_UTC_USEC(PARSE_UTC_USEC(date),"%V")) iso8601_week_number, 
    hits.eventInfo.eventCategory, 
    hits.eventInfo.eventAction, 
    COUNT(hits.eventInfo.eventCategory) AS total_events, 
    EXACT_COUNT_DISTINCT(CONCAT(fullVisitorId,'-',string(visitId),'-',date,'-',ifnull(hits.eventInfo.eventLabel,'null'))) AS unique_events  
FROM 
    TABLE_DATE_RANGE([XXXXXX.ga_sessions_], TIMESTAMP('2017-05-01'), TIMESTAMP('2017-05-07')) 
WHERE 
    hits.type = 'EVENT' AND hits.eventInfo.eventCategory = 'BIG_Transaction' 
GROUP BY 
    iso8601_week_number, hits.eventInfo.eventCategory, hits.eventInfo.eventAction 

此查询的结果应与在GA接口的数据。

相关问题