diff --git a/models/staging/google_analytics/src_google_analytics.yml b/models/staging/google_analytics/src_google_analytics.yml index 4013fba..5d20c9d 100644 --- a/models/staging/google_analytics/src_google_analytics.yml +++ b/models/staging/google_analytics/src_google_analytics.yml @@ -2,8 +2,8 @@ version: 2 sources: - name: google_analytics - database: stacktonic-cloud # gcp-project - dataset: analytics_263482362 # gcp-dataset + database: bigquery-public-data # gcp-project + dataset: ga4_obfuscated_sample_ecommerce # gcp-dataset freshness: warn_after: { count: 24, period: hour } diff --git a/models/staging/google_analytics/stg_google_analytics__events.sql b/models/staging/google_analytics/stg_google_analytics__events.sql index f108d29..9dfd7ad 100644 --- a/models/staging/google_analytics/stg_google_analytics__events.sql +++ b/models/staging/google_analytics/stg_google_analytics__events.sql @@ -1,39 +1,49 @@ -{{ - config( - materialized="view" - ) -}} - -with source as ( - - select - *, - _table_suffix as table_suffix - from {{ source('google_analytics', 'events') }} - where - -- start date (using the _table_suffix_ pseudo column for performance) - (_table_suffix between format_date('%Y%m%d', date('{{ var("start_date") }}')) - and format_date('%Y%m%d', current_date())) - -), - -renamed as ( - - select - user_pseudo_id as fpc_id, -- first-party cookie-id - concat(user_pseudo_id, '.', (select cast(value.int_value as string) from unnest(event_params) where key = 'ga_session_id')) as session_id, - ifnull((select value.string_value from unnest(event_params) where key = 'traffic_type'), 'production') as traffic_type, - * - from source - -), - -filtered as ( - select - * - from renamed - where - traffic_type not in ('development', 'internal') -) - -select * from filtered \ No newline at end of file +{{ config(materialized="view") }} + +with + source as ( + + select *, _table_suffix as table_suffix + from {{ source("google_analytics", "events") }} + where + -- start date (using the _table_suffix_ pseudo column for performance) + ( + _table_suffix between format_date( + '%Y%m%d', date('{{ var("start_date") }}') + ) and format_date('%Y%m%d', current_date()) + ) + + ), + + renamed as ( + + select + user_pseudo_id as fpc_id, -- first-party cookie-id + concat( + user_pseudo_id, + '.', + ( + select cast(value.int_value as string) + from unnest(event_params) + where key = 'ga_session_id' + ) + ) as session_id, + ifnull( + ( + select value.string_value + from unnest(event_params) + where key = 'traffic_type' + ), + 'production' + ) as traffic_type, + * + from source + + ), + + filtered as ( + select * from renamed where traffic_type not in ('development', 'internal') + ) + +select * +from filtered