首页 > 解决方案 > BigQuery 问题 - 使用路径表进行归因建模

问题描述

这可能是一个基本问题,但我就是想不通。样本数据和查询可以在这里找到。

查询的目的是找出将信用归因于哪个位置。在第一次接触模型中,最早的接触导致转化 (FLOODLIGHT) 被记入贷方。所以这里 22 有 1 个学分,11 有 2 个学分。我不太了解第一个棘手的查询,尤其是未嵌套的部分。比较有什么意义prev_conversion_event.event_time < conversion_event.event_time?它们本质上不一样吗?我的意思是他们俩都来自UNNEST(t.*_path.events). 而且attributed_event.event_time也来自同一个地方。我只是在这里感到困惑。非常感谢帮助!

为方便起见,我在下面粘贴示例数据和查询:

样本数据

/* Substitute *_paths for the specific paths table that you want to query. */ SELECT ( SELECT attributed_event_metadata.placement_id FROM ( SELECT AS STRUCT attributed_event.placement_id, ROW_NUMBER() OVER(ORDER BY attributed_event.event_time ASC) AS rank FROM UNNEST(t.*_paths.events) AS attributed_event WHERE attributed_event.event_type != "FLOODLIGHT" AND attributed_event.event_time < conversion_event.event_time AND attributed_event.event_time > ( SELECT IFNULL( ( SELECT MAX(prev_conversion_event.event_time) AS event_time FROM UNNEST(t.*_paths.events) AS prev_conversion_event WHERE prev_conversion_event.event_type = "FLOODLIGHT" AND prev_conversion_event.event_time < conversion_event.event_time), 0)) ) AS attributed_event_metadata WHERE attributed_event_metadata.rank = 1) AS placement_id, COUNT(*) AS credit FROM adh.*_paths AS t, UNNEST(*_paths.events) AS conversion_event WHERE conversion_event.event_type = "FLOODLIGHT" GROUP BY placement_id HAVING placement_id IS NOT NULL ORDER BY credit DESC

标签: google-bigquery

解决方案


比较两者prev_conversion_event.event_time和的点conversion_event.event_time暗示了分配给每个值的名称。

我们想要的是找到两个 Floodlight 之间的所有事件。然后,您需要检查您的事件attributed_event是否不是 Floodlight,并且它位于两个 Floodlight 之间,即

attributed_event.event_type != "FLOODLIGHT"
attributed_event.event_time < conversion_event.event_time
attributed_event.event_time > MAX(prev_conversion_event.event_time)

whereMAX(prev_conversion_event.event_time)必须将以前的 Floodlight 反射到当前的 Floodlight conversion_event.event_time,因此您需要

prev_conversion_event.event_type = "FLOODLIGHT"
conversion_event.event_type = "FLOODLIGHT"
prev_conversion_event.event_time < conversion_event.event_time

当然,所有三个元素 prev_conversion、conversion 和属性都是从相同的事件中获得的(带有额外的过滤),因此您需要从同一列中获取它们

UNNEST(t.*_paths.events) AS prev_conversion_event WHERE ...
UNNEST(t.*_paths.events) AS conversion_event WHERE ...
UNNEST(t.*_paths.events) AS attributed_event WHERE ...

然后,您只需按正确顺序组合前面的条件,并为每个用例(首次接触、最后接触、线性)添加适当的排名和信用。

我希望这个解释足够清楚。如果有不清楚的地方,请告诉我,以便我帮助您进一步理解。


推荐阅读