Skip to content

Commit

Permalink
Improvements to channel mapping based on Google's definitions (Velir#245
Browse files Browse the repository at this point in the history
)

* update formatting, paid search, organic social, paid social

* refactor direct

* update referral

* update sms
  • Loading branch information
adamribaudo-velir authored Jun 30, 2023
1 parent a5fd154 commit 7cfbd3e
Showing 1 changed file with 54 additions and 27 deletions.
81 changes: 54 additions & 27 deletions macros/default_channel_grouping.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,76 @@

{% macro default__default_channel_grouping(source, medium, source_category) %}
case
when {{source}} is null and {{medium}} is null
when
(
{{source}} is null
and {{medium}} is null
)
or (
{{source}} = '(direct)'
and ({{medium}} = '(none)' or {{medium}} = '(not set)')
)
then 'Direct'
when {{source}} = '(direct)'
and ({{medium}} = '(none)' or {{medium}} = '(not set)')
then 'Direct'

when REGEXP_CONTAINS({{source}}, r"^(facebook|instagram|pinterest|reddit|twitter|linkedin)") = true
and REGEXP_CONTAINS({{medium}}, r"^(cpc|ppc|paid)") = true
when
(
REGEXP_CONTAINS({{source}}, r"^(facebook|instagram|pinterest|reddit|twitter|linkedin)") = true
or {{source_category}} = 'SOURCE_CATEGORY_SOCIAL'
)
and REGEXP_CONTAINS({{medium}}, r"^(.*cp.*|ppc|retargeting|paid.*)$") = true
then 'Paid Social'
when REGEXP_CONTAINS({{source}}, r"^(facebook|instagram|pinterest|reddit|twitter|linkedin)") = true
or REGEXP_CONTAINS({{medium}}, r"^(social|social-network|social-media|sm|social network|social media)") = true
or {{source_category}} = 'SOURCE_CATEGORY_SOCIAL'
when
REGEXP_CONTAINS({{source}}, r"^(facebook|instagram|pinterest|reddit|twitter|linkedin)") = true
or {{medium}} in ("social","social-network","social-media","sm","social network","social media")
or {{source_category}} = 'SOURCE_CATEGORY_SOCIAL'
then 'Organic Social'
when REGEXP_CONTAINS({{medium}}, r"email|e-mail|e_mail|e mail") = true
or REGEXP_CONTAINS({{source}}, r"email|e-mail|e_mail|e mail") = true
when
REGEXP_CONTAINS({{medium}}, r"email|e-mail|e_mail|e mail") = true
or REGEXP_CONTAINS({{source}}, r"email|e-mail|e_mail|e mail") = true
then 'Email'
when REGEXP_CONTAINS({{medium}}, r"affiliate|affiliates") = true
when
REGEXP_CONTAINS({{medium}}, r"affiliate|affiliates") = true
then 'Affiliates'
when {{source_category}} = 'SOURCE_CATEGORY_SHOPPING' and REGEXP_CONTAINS({{medium}},r"^(.*cp.*|ppc|paid.*)$")
when
{{source_category}} = 'SOURCE_CATEGORY_SHOPPING'
and REGEXP_CONTAINS({{medium}},r"^(.*cp.*|ppc|paid.*)$")
then 'Paid Shopping'
when ({{source_category}} = 'SOURCE_CATEGORY_VIDEO' AND REGEXP_CONTAINS({{medium}},r"^(.*cp.*|ppc|paid.*)$"))
or {{source}} = 'dv360_video'
when
({{source_category}} = 'SOURCE_CATEGORY_VIDEO' AND REGEXP_CONTAINS({{medium}},r"^(.*cp.*|ppc|paid.*)$"))
or {{source}} = 'dv360_video'
then 'Paid Video'
when REGEXP_CONTAINS({{medium}}, r"^(display|cpm|banner)$")
or {{source}} = 'dv360_display'
when
REGEXP_CONTAINS({{medium}}, r"^(display|cpm|banner)$")
or {{source}} = 'dv360_display'
then 'Display'
when REGEXP_CONTAINS({{medium}}, r"^(cpc|ppc|paidsearch)$")
when
{{source_category}} = 'SOURCE_CATEGORY_SEARCH'
and REGEXP_CONTAINS({{medium}}, r"^(.*cp.*|ppc|retargeting|paid.*)$")
then 'Paid Search'
when REGEXP_CONTAINS({{medium}}, r"^(cpv|cpa|cpp|content-text)$")
when
REGEXP_CONTAINS({{medium}}, r"^(cpv|cpa|cpp|content-text)$")
then 'Other Advertising'
when {{medium}} = 'organic' or {{source_category}} = 'SOURCE_CATEGORY_SEARCH'
when
{{medium}} = 'organic' or {{source_category}} = 'SOURCE_CATEGORY_SEARCH'
then 'Organic Search'
when REGEXP_CONTAINS({{medium}}, r"^(.*video.*)$") or {{source_category}} = 'SOURCE_CATEGORY_VIDEO'
when
{{source_category}} = 'SOURCE_CATEGORY_VIDEO'
or REGEXP_CONTAINS({{medium}}, r"^(.*video.*)$")
then 'Organic Video'
when {{source_category}} = 'SOURCE_CATEGORY_SHOPPING'
when
{{source_category}} = 'SOURCE_CATEGORY_SHOPPING'
then 'Organic Shopping'
when {{medium}} = 'referral'
when
{{medium}} in ("referral", "app", "link")
then 'Referral'
when {{medium}} = 'audio'
when
{{medium}} = 'audio'
then 'Audio'
when {{medium}} = 'sms'
when
{{medium}} = 'sms'
or {{source}} = 'sms'
then 'SMS'
when REGEXP_CONTAINS({{medium}}, r"(mobile|notification|push$)") or {{source}} = 'firebase'
when
REGEXP_CONTAINS({{medium}}, r"(mobile|notification|push$)") or {{source}} = 'firebase'
then 'Push Notifications'
else '(Other)'
end
Expand Down

0 comments on commit 7cfbd3e

Please sign in to comment.