2 个特定 Google Analytics(分析)页面点击之间的 Bigquery 时间
Posted
技术标签:
【中文标题】2 个特定 Google Analytics(分析)页面点击之间的 Bigquery 时间【英文标题】:Bigquery time between 2 specific Google Analytics page hits 【发布时间】:2019-09-25 14:54:55 【问题描述】:纽比在这里。我试图找出我们网站上的用户从一个页面(获取报价)到另一个页面(申请)所花费的平均时间。在 BigQuery 中使用 Google Analytics 数据。我想按频道划分,但最初我只是想为每个用户获取时间。
我尝试过内连接和左连接,但两者都返回 table*table 的结果数。单独运行时,两个子查询看起来都是正确的(引号返回 925,应用程序返回 117),但是当加入它们时,我得到了重复。
注释掉的位用于最终查询,可以忽略,只包括上下文。
-- SELECT
-- channelGrouping,
-- ROUND(AVG(timeQ2A/60000),2) AS avgMinsQ2A
-- FROM (
SELECT
CONCAT(CAST(visitId AS STRING),'_',fullVisitorId) AS sessionId,
apps.channelGrouping,
(quote.quoteTime) as quoteTime,
(CAST(hits.time AS INT64)) AS appTime,
(CAST(hits.time AS INT64) - (quote.quoteTime)) AS timeQ2A
FROM
`project.dataset.ga_sessions_20190923` AS apps,
UNNEST(hits) AS hits
INNER JOIN (
SELECT
MIN(CAST(hits.time AS INT64)) AS quoteTime,
CONCAT(CAST(visitId AS STRING),'_',fullVisitorId) AS sessionId
FROM
`project.dataset.ga_sessions_20190923`,
UNNEST(hits) AS hits
WHERE
hits.type = "PAGE"
AND hits.page.pagePath = "/get-a-quote/"
AND hits.time > 0
GROUP BY
2) AS quote
ON
sessionId = quote.sessionId
WHERE
hits.type = "PAGE"
AND hits.page.pagePath = "/application-complete/"
GROUP BY
1,
2,3,4
ORDER BY 1,2,3
-- )
-- GROUP BY
-- 1
-- ORDER BY
-- 2 DESC
我希望只获得 117 行(所有已申请的用户都将在报价表中,因此内部和左侧应该相同),但我得到 108k。
非常感谢任何帮助。
【问题讨论】:
【参考方案1】:如果我不得不猜测,我会说您在每个会话中有多个点击,其中hits.page.pagePath = "/application-complete/"
为真。您在内部查询中获取时间戳的最小值,而不是外部查询。
如果是我,我会像这样构造我的查询:
-- Get all relevant GA Data
with ga as (
select
CONCAT(CAST(visitId AS STRING),'_',fullVisitorId) AS sessionId,
channelGrouping,
hits.time as hit_ts,
hits.page.pagePath
from `project.dataset.ga_sessions_20190923`
left join unnest(hits) AS hits
where hits.type = 'PAGE' and hits.page.pagePath in ('/get-a-quote/','/application-complete/') and hits.time > 0
),
-- Get first instance of quote
first_quote as (
select
sessionId,
channelGrouping,
min(hit_ts) as quote_ts
from ga
where pagePath = '/get-a-quote/'
group by 1,2
),
-- Get first instance of app-complete
first_app_complete as (
select
sessionId,
channelGrouping,
min(hit_ts) as app_complete_ts
from ga
where pagePath = '/application-complete/'
group by 1,2
),
-- Join it all together and calc differences
joined as (
select
sessionID,
channelGrouping,
timestamp_diff(app_complete_ts, quote_ts, second) as ts_diff_seconds
from first_quote
inner join first_app_complete using(sessionID,channelGrouping)
)
select * from joined
-- select channelGrouping, count(sessionID) as session_count, avg(ts_diff_seconds) as average_seconds_to_complete from joined group by 1
【讨论】:
这绝对是一种更好的查询结构,而且它有效 - 非常感谢以上是关于2 个特定 Google Analytics(分析)页面点击之间的 Bigquery 时间的主要内容,如果未能解决你的问题,请参考以下文章
2.3.9Google Analytics高级应用——波士顿矩阵分析方法 Haran
Google Analytics(分析) - 事件 - 类别,操作和标签是不够的
BigQuery 中的 Google Analytics(分析)站点搜索