Skip to content

Commit

Permalink
unit test for stg_ga4__sessions_traffic_sources_last_non_direct_daily…
Browse files Browse the repository at this point in the history
…. Not working yet
  • Loading branch information
adamribaudo-velir committed Jun 22, 2024
1 parent 6e709db commit 9d53c9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion models/staging/stg_ga4__session_conversions_daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ unit_tests:
macros:
is_incremental: false
vars: {conversion_events: ['my_conversion']}
- name: test_session_conversion_count_non_standard_event_name
- name: test_stg_ga4__session_conversions_daily_non_standard_event_name
description: Test whether the session-level count of conversions is correct
model: stg_ga4__session_conversions_daily
given:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{% set partitions_to_replace = ['current_date'] %}

{% if is_incremental() %}
{% 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 %}
{% endif %}

{{
config(
materialized = 'incremental',
Expand Down Expand Up @@ -35,7 +39,7 @@ with last_non_direct_session_partition_key as (
last_value(non_direct_session_partition_key ignore nulls) over(
partition by client_key
order by
session_partition_timestamp range between {{var('session_attribution_lookback_window_days', 30 ) * 24 * 60 * 60 * 1000000 }} preceding
session_partition_timestamp range between {{ var('session_attribution_lookback_window_days', 30 ) * 24 * 60 * 60 * 1000000 }} preceding
and current row -- lookback window
)
ELSE non_direct_session_partition_key
Expand All @@ -44,7 +48,7 @@ with last_non_direct_session_partition_key as (
{{ref('stg_ga4__sessions_traffic_sources_daily')}}
{% if is_incremental() %}
-- Add 30 to static_incremental_days to include the session attribution lookback window
where session_partition_date >= date_sub(current_date, interval ({{var('static_incremental_days',3) + var('session_attribution_lookback_window_days', 30 )}} ) day)
where session_partition_date >= date_sub(current_date, interval ({{ var('static_incremental_days',3) + var('session_attribution_lookback_window_days', 30 ) }} ) day)
{% endif %}
)
,join_last_non_direct_session_source as (
Expand All @@ -68,7 +72,7 @@ with last_non_direct_session_partition_key as (
,coalesce(last_non_direct_source.session_term, '(none)') as last_non_direct_term
,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
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
{% if is_incremental() %}
-- Only keep the records in the partitions we wish to replace (as opposed to the whole 30 day lookback window)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,28 @@ models:
- name: last_non_direct_default_channel_grouping
description: The the most recent non-direct channel grouping within a 30-day lookback window.
tests:
- not_null
- not_null
unit_tests:
- name: test_stg_ga4__sessions_traffic_sources_last_non_direct_daily
model: stg_ga4__sessions_traffic_sources_last_non_direct_daily
given:
- input : ref('stg_ga4__sessions_traffic_sources_daily')
format: csv
rows: |
client_key,session_partition_key,session_partition_date,session_partition_timestamp,session_source,session_medium,session_source_category,session_campaign,session_content,session_term,session_default_channel_grouping,non_direct_session_partition_key
A,A,20230505,1683321359,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a,A
A,B,20230506,1683407759,(direct),,,,,,,
A,C,20230507,1683494159,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a,C
A,D,20230508,1683580559,(direct),,,,,,,
expect:
format: csv
rows:
client_key,session_partition_key,session_partition_date,session_source,session_medium,session_source_category,session_campaign,session_content,session_term,session_default_channel_grouping,session_partition_key_last_non_direct,last_non_direct_source,last_non_direct_medium,last_non_direct_source_category,last_non_direct_campaign,last_non_direct_content,last_non_direct_term,last_non_direct_default_channel_grouping
A,A,20230505,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a,A,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a
A,B,20230506,(direct),,,,,,,A,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a
A,C,20230507,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a,C,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a
A,D,20230508,(direct),,,,,,,C,source_a,medium_a,source_category_a,campaign_a,content_a,term_a,default_channel_grouping_a
overrides:
macros:
is_incremental: false
vars: {session_attribution_lookback_window_days: 30}

0 comments on commit 9d53c9a

Please sign in to comment.