Skip to content

Fixes #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions models/staging/google_analytics/src_google_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
88 changes: 49 additions & 39 deletions models/staging/google_analytics/stg_google_analytics__events.sql
Original file line number Diff line number Diff line change
@@ -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
{{ 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