This repository was archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
This repository was archived by the owner on Jan 21, 2023. It is now read-only.
Traffic Attribution Question #9
Copy link
Copy link
Open
Description
Hi David,
I believe there is a problem with how you derive attribution. Currently I see in your session_tags code you extract distinct medium, source, campaign, & page_referrer from last non-direct values, but there is no testing for either a session level medium of 'cpc' or 'gclid' in the page_location indicating google/cpc which should override the event_parameter source/medium. It should be a medium of 'cpc', not 'organic' as it will show at the event_parameter level.
I'm running a few tests now to see if logic like the below helps, but perhaps you have a better solution (or perhaps I'm seeing weird GA4 data):
session_tags as (
select distinct sl.sl_key
, IF ((REGEXP_CONTAINS((select value.string_value from unnest(event_params) where key = 'page_location'), 'gclid|gclsrc') OR (sl.traffic_source.medium = 'cpc')),
'cpc', first_value((select value.string_value from unnest(event_params) where key = 'medium')) over (partition by sl.sl_key order by sl.event_timestamp desc)) AS medium
, IF (REGEXP_CONTAINS((select value.string_value from unnest(event_params) where key = 'page_location'), 'gclid|gclsrc'),
'google', first_value((select value.string_value from unnest(event_params) where key = 'source')) over (partition by sl.sl_key order by sl.event_timestamp desc)) AS source
, IF (REGEXP_CONTAINS((select value.string_value from unnest(event_params) where key = 'page_location'), 'gclid|gclsrc'),
traffic_source.name, first_value((select value.string_value from unnest(event_params) where key = 'campaign')) over (partition by sl.sl_key order by sl.event_timestamp desc)) AS campaign
, first_value((select value.string_value from unnest(event_params) where key = 'page_referrer')) over (partition by user_pseudo_id order by sl.event_timestamp desc) AS page_referrer
from session_list_with_event_history sl
where sl.event_name in ('page_view')
and (select value.string_value from unnest(sl.event_params) where key = 'medium') is not null -- NULL medium is direct, filtering out nulls to ensure last non-direct.
),
Please let me know if I'm off base with my observations.
Paul
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels