gpt4 book ai didi

google-analytics - 使用 Google Big Query 构建基本漏斗

转载 作者:行者123 更新时间:2023-12-03 17:11:20 24 4
gpt4 key购买 nike

我注意到有很多使用 Google BigQuery 的 Google Analytics 用户,但文档非常有限。是否可以帮助生成一个简单的漏斗,显示访问过/pageA 然后/pageB 然后/pageC 的用户

我见过很多不同的方法——我不清楚这样做的“正确”方法是什么。

最佳答案

您可以先使用 array_concat_agg() 连接用户点击,然后根据新的用户范围表进行计算。当然,这在很大程度上取决于您选择的时间范围。

例如,这里有来自 Google 的虚拟数据:

#standardSQL
WITH arrAgg AS (
SELECT
fullvisitorid,
-- concatenate arrays over multiple sessions
ARRAY_CONCAT_AGG(hits ORDER BY visitstarttime ASC) userHits
FROM
`google.com:analytics-bigquery.LondonCycleHelmet.ga_sessions_20130910`
GROUP BY 1
)
, journey AS (
SELECT
fullvisitorId,
-- get a proper running index with combination of unnest and offset of aggregated hits array
ARRAY( (SELECT AS STRUCT index+1 as hitNumber, page FROM UNNEST(userHits) WITH OFFSET AS index)) as hits
FROM arrAgg
)

SELECT * FROM journey

当你运行它时,你可以看到新的“原 Material ”。在第一步中,我连接命中,在第二步中,我为页面创建一个适当的索引并将 eerything 放回“命中”数组中。

您可以使用交叉连接并比较页面的步骤和顺序来构建您的用户旅程:

#standardSQL
WITH arrAgg AS (
SELECT
fullvisitorid,
SUM(totals.visits) sessions,
-- concatenate arrays over multiple sessions
ARRAY_CONCAT_AGG(hits ORDER BY visitstarttime ASC) userHits
FROM
`google.com:analytics-bigquery.LondonCycleHelmet.ga_sessions_20130910`
GROUP BY 1
)
, journey AS (
SELECT
fullvisitorId,
sessions,
-- get a proper running index with combination of unnest and offset of aggregated hits array
ARRAY( (SELECT AS STRUCT index+1 as hitNumber, page FROM UNNEST(userHits) WITH OFFSET AS index WHERE type='PAGE')) as hits
FROM arrAgg
)
-- funnel: homepage: /, login: /login.html, basket: /basket.html, confirm: /confirm.html
SELECT
SUM(sessions) allSessions,
COUNT(1) allUsers,
-- check if any page was home page
SUM( (SELECT IF( LOGICAL_OR(page.pagePath='/'), 1, 0) FROM j.hits) ) step1_home,
-- cross join hits array with itself: combination of all pages with all pages: any of those combinations our two pages? came home before login?: if yes for any given amount add up 1
SUM( (SELECT IF( LOGICAL_OR(a.page.pagePath='/' AND b.page.pagePath='/login.html' AND a.hitNumber < b.hitNumber) ,1, 0 ) FROM j.hits a CROSS JOIN j.hits b) ) step2_login,
-- extend cross join principle to a third page
SUM( (SELECT IF( LOGICAL_OR(
a.page.pagePath='/' AND b.page.pagePath='/login.html' AND c.page.pagePath='/basket.html' AND
a.hitNumber < b.hitNumber AND b.hitNumber < c.hitNumber
) ,1, 0 ) FROM j.hits a CROSS JOIN j.hits b CROSS JOIN j.hits c) ) step3_basket,
-- extend cross join principle to a fourth page
SUM( (SELECT IF( LOGICAL_OR(
a.page.pagePath='/' AND b.page.pagePath='/login.html' AND c.page.pagePath='/basket.html' AND d.page.pagePath='/confirm.html' AND
a.hitNumber < b.hitNumber AND b.hitNumber < c.hitNumber AND c.hitNumber < d.hitNumber
) ,1, 0 ) FROM j.hits a CROSS JOIN j.hits b CROSS JOIN j.hits c CROSS JOIN j.hits d) ) step4_confirm
FROM journey j

由于一切都通过数组上的子查询进行操作,因此由于并行化,它应该可以很好地扩展。
请在使用前对其进行测试——我没有;)但它应该指向正确的方向。

关于google-analytics - 使用 Google Big Query 构建基本漏斗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51249941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com