Skip to content

Commit

Permalink
Improve google-cpc detection
Browse files Browse the repository at this point in the history
Some google/cpc visits appear in BigQuery as referrals from either safeframe.googlesyndication.com or doubleclick.net. This update handles those conditions.
  • Loading branch information
paulmkoch authored Jul 29, 2024
1 parent df85449 commit d356951
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion models/staging/stg_ga4__events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,30 @@ detect_gclid as (
select
* except (event_source, event_medium, event_campaign),
case
when (page_location like '%gclid%' and event_source is null) then "google"
when (
page_location like '%gclid%'
and (
event_source is null
or event_source like '%safeframe.googlesyndication.com%'
or event_source like '%doubleclick.net%'
)
) then "google"
else event_source
end as event_source,
case
when (page_location like '%gclid%' and event_medium is null) then "cpc"

when (page_location like '%gclid%' and event_medium = 'organic') then "cpc"

when (
page_location like '%gclid%'
and (
event_source is null
or event_source like '%safeframe.googlesyndication.com%'
or event_source like '%doubleclick.net%'
)
and event_medium = 'referral'
) then "cpc"
else event_medium
end as event_medium,
case
Expand Down

0 comments on commit d356951

Please sign in to comment.