Skip to content
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

New session id v2 #354

Open
wants to merge 106 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
003f950
Cluster base table by stream_id to save cost
JumboDVDH0 Apr 18, 2024
02cb8d9
Added client_id to staging table
JumboDVDH0 Apr 18, 2024
fa1b0d0
Fixed type-o
JumboDVDH0 Apr 18, 2024
c970c6a
Forgot one reference
JumboDVDH0 Apr 18, 2024
ca16d32
Fixed grouping issue:
JumboDVDH0 Apr 18, 2024
ac57735
Added Client ID to user_id_mapping
JumboDVDH0 Apr 19, 2024
22901a3
Fixed grouping
JumboDVDH0 Apr 19, 2024
bb3c341
Merge pull request #1 from Springbok-Agency/stream-id-stg_ga4__user_i…
DVDH-000 Apr 23, 2024
a0adf6e
Added Client ID to Derived User Properties
JumboDVDH0 Apr 23, 2024
e9f37e6
Merge pull request #2 from Springbok-Agency/client-id-user-derived-pr…
DVDH-000 Apr 23, 2024
aaf9563
Added stream id
JumboDVDH0 Apr 24, 2024
9811f8f
Added stream_id
JumboDVDH0 Apr 26, 2024
bbf50d9
date range
tessa-beijloos May 6, 2024
f209e0b
Merge pull request #5 from Springbok-Agency/date-filter
tessa-beijloos May 6, 2024
715339c
Update base_ga4__events.sql
tessa-beijloos May 6, 2024
9c80574
Merge pull request #6 from Springbok-Agency/fix-for-base
DVDH-000 May 6, 2024
6e5c212
Update base_ga4__events.sql
tessa-beijloos May 6, 2024
391a432
Merge pull request #7 from Springbok-Agency/base-fix-v2
DVDH-000 May 6, 2024
a7f9885
Update base_ga4__events.sql
tessa-beijloos May 6, 2024
0ee8419
Merge pull request #8 from Springbok-Agency/fix-3-base-table
DVDH-000 May 6, 2024
33f1f2c
Update schema.yml
tessa-beijloos May 6, 2024
190e86e
Merge pull request #9 from Springbok-Agency/change-macro-name
DVDH-000 May 6, 2024
3ba4ed7
Added logging
JumboDVDH0 May 6, 2024
9ddf47e
Merge pull request #10 from Springbok-Agency/add-logging
DVDH-000 May 6, 2024
5c7af5d
Update base_ga4__events.sql
tessa-beijloos May 6, 2024
abc95be
Merge pull request #11 from Springbok-Agency/fix-base-4
DVDH-000 May 6, 2024
07ece65
Update select_date_range.sql
tessa-beijloos May 6, 2024
1df0d35
Merge pull request #12 from Springbok-Agency/change-date-range-function
DVDH-000 May 6, 2024
317e12d
Changed Macro
JumboDVDH0 May 30, 2024
92dc5b0
Merge pull request #13 from Springbok-Agency/fix-macro
DVDH-000 May 30, 2024
43ca797
Moved macro to our own project
JumboDVDH0 May 30, 2024
9b39c73
Merge pull request #14 from Springbok-Agency/move-macro-to-main-project
DVDH-000 May 30, 2024
43684c9
Generate partitions to replace on start and end date
JumboDVDH0 May 31, 2024
c71e5ea
Merge pull request #15 from Springbok-Agency/generate-partitions-to-r…
DVDH-000 May 31, 2024
ac46229
Generate partitions to replace based on start and end date
JumboDVDH0 May 31, 2024
7aa7d28
Generate partitions to replace based on start and end date
JumboDVDH0 May 31, 2024
36aa9d8
Merge pull request #16 from Springbok-Agency/generate-partitions-to-r…
DVDH-000 May 31, 2024
b2930f5
Added stream_id
JumboDVDH0 Jun 3, 2024
fda0221
Added clustering
JumboDVDH0 Jun 3, 2024
98920b6
Merge pull request #17 from Springbok-Agency/add-stream-id-trafffic-s…
DVDH-000 Jun 3, 2024
abd6d75
Fixed Type-O
JumboDVDH0 Jun 3, 2024
9c551cf
Merge pull request #18 from Springbok-Agency/add-stream-id-trafffic-s…
DVDH-000 Jun 3, 2024
49ea67a
Added stream ID
JumboDVDH0 Jun 3, 2024
d491683
JumboDVDH0 Jun 3, 2024
5729b6c
JumboDVDH0 Jun 3, 2024
a86e0a2
Merge pull request #19 from Springbok-Agency/add-stream-id-session-co…
DVDH-000 Jun 3, 2024
a57e8c4
Updated
JumboDVDH0 Jun 3, 2024
f3a363d
Merge pull request #20 from Springbok-Agency/fix-partitions-to-replace
DVDH-000 Jun 3, 2024
ba6f44d
Fixed partitions to replace
JumboDVDH0 Jun 10, 2024
30d8925
Merge pull request #21 from Springbok-Agency/fix-partitions-to-replace
DVDH-000 Jun 10, 2024
6636136
Added test
JumboDVDH0 Jun 10, 2024
548a209
Added test to model
JumboDVDH0 Jun 10, 2024
f4584a7
Backfill is var
JumboDVDH0 Jun 10, 2024
488c0a4
Merge pull request #22 from Springbok-Agency/MAV-7352-add-10-weeks-test
DVDH-000 Jun 10, 2024
50e38bf
Changed var reference
JumboDVDH0 Jun 10, 2024
f9c5740
Merge pull request #23 from Springbok-Agency/MAV-7352-add-10-weeks-test
DVDH-000 Jun 10, 2024
583e3c5
Merge branch 'Velir:main' into master
DVDH-000 Jun 10, 2024
73796ef
Fixed 10 week test so it works better with Airflow
JumboDVDH0 Jun 19, 2024
c7d1d28
Merge pull request #24 from Springbok-Agency/fix-10-week-test
DVDH-000 Jun 19, 2024
82f8e20
Made stg_ga4__sessions_traffic_sources_daily compatible with start an…
JumboDVDH0 Jun 26, 2024
10e2363
Merge pull request #25 from Springbok-Agency/start-end-sessions
DVDH-000 Jun 26, 2024
de1cdb3
Added backfill compatibility start and end date
JumboDVDH0 Jun 26, 2024
09549a1
Merge pull request #26 from Springbok-Agency/start-end-sessions
DVDH-000 Jun 26, 2024
a731e1e
Remove 10 weeks dates
JumboDVDH0 Jul 23, 2024
e00ca7a
Added custom test to save cost
JumboDVDH0 Jul 23, 2024
231003f
Custom name
JumboDVDH0 Jul 23, 2024
a9ecd8f
Macro causes issues, skip for now
JumboDVDH0 Jul 23, 2024
41258db
Actually give the good name
JumboDVDH0 Jul 23, 2024
7e4106d
Working too fast
JumboDVDH0 Jul 23, 2024
41d3702
Proper naming
JumboDVDH0 Jul 23, 2024
4a64671
Renamed
JumboDVDH0 Jul 23, 2024
550e656
Removed tests
JumboDVDH0 Jul 23, 2024
bf2af62
no test
JumboDVDH0 Jul 24, 2024
5f9cc1f
Removed test
JumboDVDH0 Jul 24, 2024
031e67e
Removed test, we do this in our own project now
JumboDVDH0 Jul 24, 2024
429e7cb
Disabled test
JumboDVDH0 Jul 24, 2024
f478206
Dummy test
JumboDVDH0 Jul 24, 2024
7057b3a
Property ID filter
DVDH-000 Dec 12, 2024
55fcd38
Select all selected brands
DVDH-000 Dec 12, 2024
bb108eb
Update base_select.sql
tessa-beijloos Dec 16, 2024
f437c3d
Merge pull request #27 from Springbok-Agency/tessa-beijloos-patch-1
tessa-beijloos Dec 16, 2024
e514ebc
Update base_select.sql
tessa-beijloos Dec 16, 2024
1d4f76b
Merge pull request #28 from Springbok-Agency/tessa-beijloos-patch-2
tessa-beijloos Dec 16, 2024
decf8b0
Update base_select.sql
tessa-beijloos Dec 16, 2024
e51739e
Merge pull request #29 from Springbok-Agency/tessa-beijloos-patch-3
tessa-beijloos Dec 16, 2024
e55eea3
Update base_select.sql
tessa-beijloos Dec 16, 2024
200e0c5
Merge pull request #30 from Springbok-Agency/tessa-beijloos-patch-4
tessa-beijloos Dec 16, 2024
36a4fd8
Update base_select.sql
tessa-beijloos Dec 16, 2024
17f16e3
Merge pull request #31 from Springbok-Agency/tessa-beijloos-patch-5
tessa-beijloos Dec 16, 2024
99c3f97
Update base_select.sql
tessa-beijloos Dec 16, 2024
06207b6
Merge pull request #33 from Springbok-Agency/tessa-beijloos-patch-8
tessa-beijloos Dec 16, 2024
1dfb82e
Update base_select.sql
tessa-beijloos Dec 16, 2024
22a3381
Merge pull request #34 from Springbok-Agency/tessa-beijloos-patch-9
tessa-beijloos Dec 16, 2024
739b47b
Update base_select.sql
tessa-beijloos Dec 16, 2024
e8a3564
Merge pull request #35 from Springbok-Agency/tessa-beijloos-patch-10
tessa-beijloos Dec 16, 2024
1442e39
base select
tessa-beijloos-jumbo Dec 16, 2024
6ba69ee
Merge branch 'master' into new-session-id
tessa-beijloos Dec 16, 2024
b104826
Merge pull request #36 from Springbok-Agency/new-session-id
tessa-beijloos Dec 16, 2024
364a9f3
new session id
tessa-beijloos-jumbo Dec 16, 2024
bdfe060
Merge pull request #37 from Springbok-Agency/new-sessionid
tessa-beijloos Dec 16, 2024
2703969
session-key
tessa-beijloos-jumbo Dec 16, 2024
bee74a4
Merge pull request #38 from Springbok-Agency/new-sessionid
tessa-beijloos Dec 16, 2024
aa49ee5
new session id v2
tessa-beijloos-jumbo Dec 16, 2024
ff4696b
commits
tessa-beijloos-jumbo Dec 16, 2024
6368783
new session id
tessa-beijloos-jumbo Dec 16, 2024
cace7e5
new sessionid
tessa-beijloos-jumbo Dec 16, 2024
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ vars:
ga4:
session_attribution_lookback_window_days: 90
```
# Select Date Range

To select a date range in a where statement you can use `select_date_range` macro. You can use it in your where statement like this:

``` WHERE <statement> (or TRUE) and {{ ga4.select_date_range(start_date, end_date, date_column) }}```



# Custom Events

Expand Down
2 changes: 1 addition & 1 deletion macros/base_select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@
WHEN event_name = 'purchase' THEN 1
ELSE 0
END AS is_purchase
{% endmacro %}
{% endmacro %}
15 changes: 15 additions & 0 deletions macros/generate_date_array.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% macro generate_date_array(start_date_str, end_date_str) %}
{% set date_format_input = '%Y%m%d' %}
{% set date_format_output = '%Y-%m-%d' %}
{% set dates = [] %}
{% set start_date = modules.datetime.datetime.strptime(start_date_str, date_format_input) %}
{% set end_date = modules.datetime.datetime.strptime(end_date_str, date_format_input) %}
{% set diff_days = (end_date - start_date).days %}

{% for i in range(diff_days + 1) %}
{% set current_date = start_date + modules.datetime.timedelta(days=i) %}
{% set dates = dates.append(current_date.strftime(date_format_output)) %}
{% endfor %}

{{ return(dates) }}
{% endmacro %}
47 changes: 42 additions & 5 deletions models/staging/base/base_ga4__events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@
{% set partitions_to_replace = partitions_to_replace.append('date_sub(current_date, interval ' + (i+1)|string + ' day)') %}
{% endfor %}


{% set start_date = var('start_date', none) %}
{% set end_date = var('end_date', none) %}

{{ log("Initial start_date: " ~ start_date, info=True) }}
{{ log("Initial end_date: " ~ end_date, info=True) }}


{% if start_date and end_date %}
{{ log("Running with start_date: " ~ start_date, info=True) }}
{{ log("Running with end_date: " ~ end_date, info=True) }}

{% set formatted_start_date = start_date[:4] ~ '-' ~ start_date[4:6] ~ '-' ~ start_date[6:] %}
{% set formatted_end_date = end_date[:4] ~ '-' ~ end_date[4:6] ~ '-' ~ end_date[6:] %}

{{ log("Formatted start_date: " ~ formatted_start_date, info=True) }}
{{ log("Formatted end_date: " ~ formatted_end_date, info=True) }}

{% set date_array = generate_date_array(start_date, end_date) %}


{% set partitions_to_replace = [] %}
{% for date in date_array %}
{% set formatted_date = "date('" ~ date ~ "')" %}
{% do partitions_to_replace.append(formatted_date) %}
{% endfor %}

{% endif %}

{{ log("Partitions to replace: " ~ partitions_to_replace, info=True) }}


{{
config(
pre_hook="{{ ga4.combine_property_data() }}" if var('combined_dataset', false) else "",
Expand All @@ -13,7 +45,7 @@
"data_type": "date",
},
partitions = partitions_to_replace,
cluster_by=['event_name']
cluster_by=['event_name', 'stream_id']
)
}}

Expand All @@ -22,15 +54,20 @@ with source as (
{{ ga4.base_select_source() }}
from {{ source('ga4', 'events') }}
where cast(left(replace(_table_suffix, 'intraday_', ''), 8) as int64) >= {{var('start_date')}}
{% if is_incremental() %}
{% if var('end_date') is not none %}
and cast(left(replace(_table_suffix, 'intraday_', ''), 8) as int64) <= {{ var('end_date')}}
{% endif %}
{% if is_incremental() and var('end_date') is none %}
and parse_date('%Y%m%d', left(replace(_table_suffix, 'intraday_', ''), 8)) in ({{ partitions_to_replace | join(',') }})
{% endif %}
),
),

renamed as (
select
{{ ga4.base_select_renamed() }}
{{ ga4.base_select_renamed() }},
CAST(REGEXP_EXTRACT((select value.string_value from unnest(event_params) where key = 'ga_session_id'), r'^GS\d\.\d\.(\d+)') AS INT64) as session_id_mp
from source
)

select * from renamed
select * except(session_id), COALESCE(session_id, session_id_mp) as session_id from renamed
qualify row_number() over(partition by event_date_dt, stream_id, user_pseudo_id, session_id, event_name, event_timestamp, to_json_string(ARRAY(SELECT params FROM UNNEST(event_params) AS params ORDER BY key))) = 1
2 changes: 2 additions & 0 deletions models/staging/base/base_ga4__events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ models:
columns:
- name: event_date_dt
description: Date of the event converted to Date type. Time zone is the time zone configured in the GA4 property.
tests:
- ten_weeks_dates
- name: event_timestamp
description: >
Timestamp (in microseconds) indicating when the event's batch was received (as opposed to when the event actually occurred).
Expand Down
7 changes: 1 addition & 6 deletions models/staging/events/stg_ga4__event_page_view.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ version: 2

models:
- name: stg_ga4__event_page_view
description: GA4 events filtered to only show 'page_view' events. Pivots common event parameters into separate columns. Identifies the first and last pageview in the 'is_entrance' and 'is_exit' columns.
columns:
- name: page_location
tests:
- not_null:
severity: warn
description: GA4 events filtered to only show 'page_view' events. Pivots common event parameters into separate columns. Identifies the first and last pageview in the 'is_entrance' and 'is_exit' columns.
2 changes: 2 additions & 0 deletions models/staging/stg_ga4__client_key_first_last_pageviews.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

with page_views_first_last as (
select
stream_id,
client_key,
FIRST_VALUE(event_key) OVER (PARTITION BY client_key ORDER BY event_timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS first_page_view_event_key,
LAST_VALUE(event_key) OVER (PARTITION BY client_key ORDER BY event_timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS last_page_view_event_key
Expand All @@ -12,6 +13,7 @@ with page_views_first_last as (
),
page_views_by_client_key as (
select distinct
stream_id,
client_key,
first_page_view_event_key,
last_page_view_event_key
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_ga4__derived_user_properties.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ with events_from_valid_users as (
unnest_user_properties as
(
select
stream_id,
client_key,
event_timestamp
{% for up in var('derived_user_properties', []) %}
Expand All @@ -20,6 +21,7 @@ unnest_user_properties as
)

SELECT DISTINCT
stream_id,
client_key
{% for up in var('derived_user_properties', []) %}
, LAST_VALUE({{ up.event_parameter }} IGNORE NULLS) OVER (user_window) AS {{ up.user_property_name }}
Expand Down
2 changes: 0 additions & 2 deletions models/staging/stg_ga4__events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ models:
- name: client_key
description: Surrogate key created from stream_id and user_pseudo_id. Provides a way to uniquely identify a user's device within a stream. Important when using the package to combine data across properties and streams.
- name: event_key
tests:
- unique
- name: page_path
description: This field contains the page_location with the query string portion removed. Uses macro remove_query_string
- name: page_engagement_key
Expand Down
36 changes: 34 additions & 2 deletions models/staging/stg_ga4__session_conversions_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
{% for i in range(var('static_incremental_days')) %}
{% set partitions_to_replace = partitions_to_replace.append('date_sub(current_date, interval ' + (i+1)|string + ' day)') %}
{% endfor %}


{% set start_date = var('start_date', none) %}
{% set end_date = var('end_date', none) %}

{{ log("Initial start_date: " ~ start_date, info=True) }}
{{ log("Initial end_date: " ~ end_date, info=True) }}


{% if start_date and end_date %}
{{ log("Running with start_date: " ~ start_date, info=True) }}
{{ log("Running with end_date: " ~ end_date, info=True) }}

{% set formatted_start_date = start_date[:4] ~ '-' ~ start_date[4:6] ~ '-' ~ start_date[6:] %}
{% set formatted_end_date = end_date[:4] ~ '-' ~ end_date[4:6] ~ '-' ~ end_date[6:] %}

{{ log("Formatted start_date: " ~ formatted_start_date, info=True) }}
{{ log("Formatted end_date: " ~ formatted_end_date, info=True) }}

{% set date_array = generate_date_array(start_date, end_date) %}


{% set partitions_to_replace = [] %}
{% for date in date_array %}
{% set formatted_date = "date('" ~ date ~ "')" %}
{% do partitions_to_replace.append(formatted_date) %}
{% endfor %}

{% endif %}

{{
config(
enabled= var('conversion_events', false) != false,
Expand All @@ -13,14 +43,16 @@
"data_type": "date",
"granularity": "day"
},
partitions = partitions_to_replace
partitions = partitions_to_replace,
cluster_by = ['stream_id']
)
}}



with event_counts as (
select
stream_id,
session_key,
session_partition_key,
min(event_date_dt) as session_partition_date -- The date of this session partition
Expand All @@ -32,7 +64,7 @@ with event_counts as (
{% if is_incremental() %}
and event_date_dt in ({{ partitions_to_replace | join(',') }})
{% endif %}
group by 1,2
group by all
)

select * from event_counts
6 changes: 4 additions & 2 deletions models/staging/stg_ga4__sessions_traffic_sources.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
with session_events as (
select
session_key
stream_id
,session_key
,event_timestamp
,events.event_source
,event_medium
Expand All @@ -22,7 +23,8 @@ set_default_channel_grouping as (
),
session_source as (
select
session_key
stream_id
,session_key
,COALESCE(FIRST_VALUE((CASE WHEN event_source <> '(direct)' THEN event_source END) IGNORE NULLS) OVER (session_window), '(direct)') AS session_source
,COALESCE(FIRST_VALUE((CASE WHEN event_source <> '(direct)' THEN COALESCE(event_medium, '(none)') END) IGNORE NULLS) OVER (session_window), '(none)') AS session_medium
,COALESCE(FIRST_VALUE((CASE WHEN event_source <> '(direct)' THEN COALESCE(source_category, '(none)') END) IGNORE NULLS) OVER (session_window), '(none)') AS session_source_category
Expand Down
7 changes: 1 addition & 6 deletions models/staging/stg_ga4__sessions_traffic_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,5 @@ models:
The session_start and first_visit events are ignored for this purpose as they contain no acquisition data.
Aggregated by session_key.
columns:
- name: session_key
tests:
- unique
- name: session_source
description: First non-null source value of the session
tests:
- not_null
description: First non-null source value of the session
42 changes: 37 additions & 5 deletions models/staging/stg_ga4__sessions_traffic_sources_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
{% for i in range(var('static_incremental_days')) %}
{% set partitions_to_replace = partitions_to_replace.append('date_sub(current_date, interval ' + (i+1)|string + ' day)') %}
{% endfor %}


{% set start_date = var('start_date', none) %}
{% set end_date = var('end_date', none) %}

{{ log("Initial start_date: " ~ start_date, info=True) }}
{{ log("Initial end_date: " ~ end_date, info=True) }}


{% if start_date and end_date %}
{{ log("Running with start_date: " ~ start_date, info=True) }}
{{ log("Running with end_date: " ~ end_date, info=True) }}

{% set formatted_start_date = start_date[:4] ~ '-' ~ start_date[4:6] ~ '-' ~ start_date[6:] %}
{% set formatted_end_date = end_date[:4] ~ '-' ~ end_date[4:6] ~ '-' ~ end_date[6:] %}

{{ log("Formatted start_date: " ~ formatted_start_date, info=True) }}
{{ log("Formatted end_date: " ~ formatted_end_date, info=True) }}

{% set date_array = generate_date_array(start_date, end_date) %}


{% set partitions_to_replace = [] %}
{% for date in date_array %}
{% set formatted_date = "date('" ~ date ~ "')" %}
{% do partitions_to_replace.append(formatted_date) %}
{% endfor %}

{% endif %}

{{
config(
materialized = 'incremental',
Expand All @@ -19,7 +49,8 @@

with session_events as (
select
client_key
stream_id
,client_key
,session_partition_key
,event_date_dt as session_partition_date
,event_timestamp
Expand Down Expand Up @@ -47,7 +78,8 @@ set_default_channel_grouping as (
),
first_session_source as (
select
client_key
stream_id
,client_key
,session_partition_key
,session_partition_date
,event_timestamp
Expand All @@ -69,8 +101,8 @@ find_non_direct_session_partition_key as (
from first_session_source
)

select
client_key
select stream_id
,client_key
,session_partition_key
,session_partition_date
,session_source
Expand All @@ -83,4 +115,4 @@ select
,non_direct_session_partition_key
,min(event_timestamp) as session_partition_timestamp
from find_non_direct_session_partition_key
group by 1,2,3,4,5,6,7,8,9,10,11
group by all
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
"data_type": "date",
"granularity": "day"
},
partitions = partitions_to_replace
partitions = partitions_to_replace,
cluster_by=['stream_id']
)
}}

with last_non_direct_session_partition_key as (
select
client_key
stream_id
, client_key
,session_partition_key
,session_partition_date
,session_source
Expand Down Expand Up @@ -49,7 +51,8 @@ with last_non_direct_session_partition_key as (
)
,join_last_non_direct_session_source as (
select
last_non_direct_session_partition_key.client_key
last_non_direct_source.stream_id
, last_non_direct_session_partition_key.client_key
,last_non_direct_session_partition_key.session_partition_key
,last_non_direct_session_partition_key.session_partition_date
,last_non_direct_session_partition_key.session_source
Expand All @@ -69,7 +72,7 @@ with last_non_direct_session_partition_key as (
,coalesce(last_non_direct_source.session_default_channel_grouping, 'Direct') as last_non_direct_default_channel_grouping
from last_non_direct_session_partition_key
left join {{ref('stg_ga4__sessions_traffic_sources_daily')}} last_non_direct_source on
last_non_direct_session_partition_key.session_partition_key_last_non_direct = last_non_direct_source.session_partition_key
last_non_direct_session_partition_key.session_partition_key_last_non_direct = last_non_direct_source.session_partition_key and last_non_direct_session_partition_key.stream_id = last_non_direct_source.stream_id
{% if is_incremental() %}
-- Only keep the records in the partitions we wish to replace (as opposed to the whole 30 day lookback window)
where last_non_direct_session_partition_key.session_partition_date in ({{ partitions_to_replace | join(',') }})
Expand Down
Loading
Loading