使用Google Big Query构建基本渠道

时间:2018-07-09 16:16:17

标签: google-analytics google-bigquery

我注意到有很多使用Google BigQuery的Google Analytics(分析)用户,但是文档非常有限。是否可以帮助生成一个简单的渠道,以显示访问过/ pageA,/ pageB和/ pageC

的用户

我看到了许多不同的方法-而且我不清楚执行此操作的“正确”方法是什么。

2 个答案:

答案 0 :(得分:0)

在这里检查:https://online-behavior.com/analytics/funnel-analysis

或者,如果您想手动操作:

  1. 选择登录到起始页的所有会话(记录最小的匹配数)
  2. 左侧联接,选择下一页上所有匹配数大于起始页面上匹配数的所有会话(匹配会话ID)
  3. 重复步骤2,直到完成渠道
  4. 计算按页面名称分组的所有会话以进行汇总

答案 1 :(得分:0)

您可以先使用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

运行此命令时,您可以看到新的“原始材料”。在第一步中,将点击数连接起来,在第二步中,为页面创建适当的索引,然后将所有内容重新放入“ hits”数组中。

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

#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

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