Velir / dbt-ga4

dbt Package for modeling raw data exported by Google Analytics 4. BigQuery support, only.
MIT License
312 stars 134 forks source link

Update to gclid traffic attribution is missing evaluation for the campaign name "(organic)" #314

Closed cfrye2 closed 6 months ago

cfrye2 commented 6 months ago

The gclid attribution update in #306 is not considering the campaign value of (organic). "(organic)" is the value I'm seeing in my GA4 datasets

gclid campaign mis-attribution

Medium and Source are cleanly updated, but without adding one more line to change (organic) to (cpc), the attribution for the newly recategorized data retains the campaign value of "(organic)" while the source and medium are updated to "cpc". I was able to resolve the issue by adding one line of code to stg_ga4__events.sql

Can someone confirm if they're seeing the same mis-attributed values for (organic) in their datasets with the merged-but-not-yet-published update? @dgitis

Currently:

detect_gclid as (
    select
        * except (event_source, event_medium, event_campaign),
        case
            when (page_location like '%gclid%' and event_source is null) 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"
            else event_medium
        end as event_medium,
        case
            when (page_location like '%gclid%' and event_campaign is null) then "(cpc)"
            when (page_location like '%gclid%' and event_campaign = 'organic') then "(cpc)"
            else event_campaign
        end as event_campaign
    from include_event_key
),

Proposed update includes one new line in the campaign-related case statement:

detect_gclid as (
    select
        * except (event_source, event_medium, event_campaign),
        case
            when (page_location like '%gclid%' and event_source is null) 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"
            else event_medium
        end as event_medium,
        case
            when (page_location like '%gclid%' and event_campaign is null) then "(cpc)"
            when (page_location like '%gclid%' and event_campaign = 'organic') then "(cpc)"
            when (page_location like '%gclid%' and event_campaign = '(organic)') then "(cpc)"
            else event_campaign
        end as event_campaign
    from include_event_key
),
adamribaudo-velir commented 6 months ago

Thanks. I just merged your PR https://github.com/Velir/dbt-ga4/pull/315 which should resolve this. I haven't seen it myself, but your screenshot seems like sufficient proof and it's a harmless check to add.