显示来自在其会话中看到X页面的用户的交易

问题描述 投票:1回答:1

我正在使用BigQuery中的Google Analytics数据。

我想显示访问会话中网站上某个特定页面的用户的交易ID列表,我已经发布了hits.page.pagepath以识别特定页面,但由于我不知道实际交易的哪一行我将无法返回有意义的结果。

我的代码看起来像这样,但返回0结果,因为所有事务ID都是NULL值,因为它们不会发生在页面路径满足AND hits.page.pagePath LIKE "%clear-out%"条件的行上:

SELECT hits.transaction.transactionId AS orderid
FROM `xxx.xxx.ga_sessions_20*` AS t
  CROSS JOIN UNNEST(hits) AS hits
WHERE parse_date('%y%m%d', _table_suffix) between 
DATE_sub(current_date(), interval 1 day) and
DATE_sub(current_date(), interval 1 day)
AND totals.transactions  > 0
AND hits.page.pagePath LIKE "%clear-out%"
AND hits.transaction.transactionId IS NOT NULL

例如,如何在用户查看AND hits.page.pagePath LIKE "%clear-out%"的所有会话中返回事务ID?

sql google-analytics google-bigquery
1个回答
2
投票

交叉加入时,您将为每次点击重复整个会话。每次点击使用此嵌套信息来查找您的页面 - 而不是交叉连接点击。不幸的是,你给的是同一个名字。保持它们分开更好 - 这就是它的样子:

SELECT
  h.transaction.transactionId AS orderId
  --,ARRAY( (SELECT AS STRUCT hitnumber, page.pagePath, transaction.transactionId FROM t.hits ) ) AS hitInfos -- test: show all hits in this session
FROM
  `google.com:analytics-bigquery.LondonCycleHelmet.ga_sessions_20130910` AS t 
  CROSS JOIN t.hits AS h
WHERE
  totals.transactions > 0 AND h.transaction.transactionId IS NOT NULL
  AND
  -- use the repeated hits nest (not the cross joined 'h') to check all pagePaths in the session
  (SELECT LOGICAL_OR(page.pagePath LIKE "/helmets/%") FROM t.hits )

LOGICAL_OR()OR的聚合函数 - 所以如果任何命中符合条件它返回TRUE

(此查询使用来自Google的公开可用的GA数据。它有点陈旧但很适合玩。)

© www.soinside.com 2019 - 2024. All rights reserved.