google-analytics - 使用 BigQuery 进行网站搜索分析
问题描述
我是 BigQuery 导出架构的新手,我正在尝试分析电子商务网站中的网站搜索模式。
一旦有人使用网站中的搜索栏,我想获得每个会话的步骤。我想检索使用的关键字和网址(aka = searchPath、previousSearchPath 和 nextSearchPath)。
对此,我想检查一下:
- 当(在 n 次点击/互动之后)用户考虑在我们的网站中搜索时
- 他/她在搜索之前访问的最后一个 url
- 他搜索后访问的结果页面
- 跟随行动
到目前为止,我得到了这个查询。但是, prev_page_path/step/nextStep 与某些逻辑不匹配。我得到类似的东西:
- 产品列表页面/
- 产品列表页面/2
- 产品列表页面/3
SELECT
CONCAT(fullVisitorId, CAST(visitStartTime AS STRING)) AS sessionId,
IF(cd.index=7,cd.value,NULL) AS customDimension7,
IF(cd.index=179,cd.value,NULL) AS customDimension179,
h.contentGroup.contentGroup2 AS CG,
h.hitNumber AS hitNumber,
h.page.searchKeyword AS keyword,
LAG(h.page.pagePath, 1) OVER (PARTITION BY CONCAT(fullVisitorId, CAST(visitStartTime AS STRING)) ORDER BY h.hitNumber) AS prev_page_path,
h.page.pagePath AS step,
ROW_NUMBER() OVER (PARTITION BY CONCAT(fullVisitorId, CAST(visitStartTime AS STRING)) ORDER BY hitNumber ASC) AS rowNumber,
LEAD(h.page.pagePath, 1) OVER (PARTITION BY CONCAT(fullVisitorId, CAST(visitStartTime AS STRING)) ORDER BY hitNumber ASC) AS nextStep
FROM
`xxx-xx-xxx.xxxxxxxxxxxx.ga_sessions_*`,
UNNEST(hits) AS h,
UNNEST(h.customDimensions) AS cd
WHERE
_TABLE_SUFFIX = FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY))
AND cd.index = 12
AND h.page.searchKeyword IS NOT NULL
AND cd.value >= '1'
LIMIT
100
解决方案
我终于设法为网站搜索跟踪添加了一个事件。因此,我现在拥有触发该事件的会话,以及使用 hit.page.searchKeywords 的结果以及计算所需指标所需的所有其他内容。
WITH event AS (
SELECT
CONCAT(fullVisitorId, visitStartTime) as sessionId,
CASE WHEN hit.eventInfo.eventAction= 'sitesearch' THEN hit.page.pagePath ELSE NULL END AS pagepath_search,
FROM `project.dataset.ga_sessions_*` AS ga, UNNEST(hits) AS hit
WHERE _TABLE_SUFFIX = 'date'
),
keyword AS (
SELECT
CONCAT(fullVisitorId, visitStartTime) as sessionId,
hit.page.searchKeyword as keyword,
hit.page.pagePath AS pagepath_result,
FROM `project.dataset.ga_sessions_*` AS ga, UNNEST(hits) AS hit
WHERE _TABLE_SUFFIX = 'date'
)
SELECT
keyword.keyword,
evento.pagepath_search,
COUNT(DISTINCT keywords.sessionId) AS total_sessions
FROM
event INNER JOIN keyword ON event.sessionId = keyword.sessionId
我一直在学习这方面的知识,所以如果你知道可以更好的东西,请联系我!
推荐阅读
- reactjs - HOC 和 TypeScript 缺少道具
- python - Image.ImageFont.ImageFont.getsize() 命令如何工作?
- c# - 这些 Oracle ORA-00600 错误的原因可能是什么?
- python - 根据家庭大小生成新行到大小 N
- android - 使用 MAJOR.MINOR.PATCH 转换为 Android Manifest 中 versionCode 的整数
- kubernetes - 如何进入K8S中的节点之一
- angularjs - AngularJS 不适用于第三方预渲染服务
- algorithm - 计算树中根左侧的节点数的函数
- c# - C# UWP UI 调度程序优化(Windows IoT Core)
- shopify - 如何创建 shopify 元字段编辑器应用程序?