Skip to content
Merged

fix #29

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
13 changes: 12 additions & 1 deletion models/50_intermediate/segment/int_segment__sessions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ with
on sessions_user_enriched.utm_campaign = twitter_campaigns.campaign_name
and sessions_user_enriched.utm_source = 'twitter'
and sessions_user_enriched.utm_medium = 'paid_social'
),

add_reffer_surrogate_key as (
select
*,
{{
dbt_utils.generate_surrogate_key(
["referrer_medium", "referrer_source"]
)
}} as referrer_id
from add_campaign_id_twitter
)

select *
from add_campaign_id_twitter
from add_reffer_surrogate_key
11 changes: 11 additions & 0 deletions models/50_intermediate/segment/int_segment__sessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ models:
config:
meta: {}
tags: []
data_tests:
- unique
- not_null
description: Unique identifier for the session
- name: anonymous_id
data_type: string
Expand Down Expand Up @@ -421,3 +424,11 @@ models:
config:
meta: {}
tags: []
- name: referrer_id
description: Surrogate key for the channel grouping, generated from referrer source + medium.
config:
meta: {}
tags: []
data_type: STRING
data_tests:
- not_null
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ with
else 'referral'
end as referrer_medium,
case
when
t.utm_source is null and t.utm_medium is null and t.referrer is null
then 'direct'
when t.utm_source is not null
then lower(t.utm_source)
when rm.map_source is not null and t.utm_source is null
Expand Down
17 changes: 17 additions & 0 deletions models/80_marts/dim1_attribution.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
with
base as (select * from {{ ref("int_segment__sessions") }}),

with_keys as (

select referrer_id as id, referrer_source, referrer_medium
from base
qualify
row_number() over (
partition by referrer_source, referrer_medium order by referrer_id
)
= 1

)

select *
from with_keys
26 changes: 26 additions & 0 deletions models/80_marts/dim1_attribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2
models:
- name: dim1_attribution
description: Dimension table for channel grouping based on referrer source and medium.
columns:
- name: id
description: Surrogate key for the channel grouping, generated from referrer source + medium.
tests:
- not_null
- unique
config:
meta: {}
tags: []
data_type: STRING
- name: referrer_source
description: Original referrer source (e.g., google, facebook, newsletter).
config:
meta: {}
tags: []
data_type: STRING
- name: referrer_medium
description: Original referrer medium (e.g., cpc, email, referral, social).
config:
meta: {}
tags: []
data_type: STRING
4 changes: 2 additions & 2 deletions models/80_marts/fct_assets_locked.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ with
filtered_assets_locked as (
select
sequence_number as id,
canonical_segment_id as fk_dim1__users,
canonical_segment_id as fk__dim1_users,
transaction_hash as fk_transaction_hash,
token_id as fk_token_id,
token_id as fk__dim1_token,
amount,
token_usd_value,
1 as asset_locked_count,
Expand Down
4 changes: 2 additions & 2 deletions models/80_marts/fct_assets_locked.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ models:
meta: {}
tags: []
description: Unique identifier for this price record
- name: fk_dim1__users
- name: fk__dim1_users
data_type: STRING
tests:
- not_null
Expand All @@ -29,7 +29,7 @@ models:
meta: {}
tags: []
description: Hash of the transaction that emitted this event.
- name: fk_token_id
- name: fk__dim1_token
data_type: STRING
tests:
- not_null
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_donated.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ with
filtered_donated as (
select
transaction_hash as id,
canonical_segment_id as fk_dim1__users,
canonical_segment_id as fk__dim1_users,
amount,
1 as donation_count,
date(record_timestamp) as record_date,
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_donated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ models:
meta: {}
tags: []
description: Unique identifier for this donation record.
- name: fk_dim1__users
- name: fk__dim1_users
data_type: STRING
tests:
- not_null
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_liquidation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ with
select
id,
transaction_hash as fk_transaction_hash,
canonical_segment_id as fk_dim1__users,
canonical_segment_id as fk__dim1_users,
coll_gas_compensation,
gas_compensation,
liquidated_principal,
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_liquidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ models:
meta: {}
tags: []
description: Hash of the transaction that executed the liquidation.
- name: fk_dim1__users
- name: fk__dim1_users
data_type: STRING
tests:
- not_null
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_loans.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ with
filtered_loan as (
select
transaction_hash as id,
canonical_segment_id as fk_dim1__users,
canonical_segment_id as fk__dim1_users,
collateral_usd_value,
principal,
interest,
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_loans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ models:
meta: {}
tags: []
description: Transaction hash as unique identifier for the loan record.
- name: fk_dim1__users
- name: fk__dim1_users
data_type: STRING
tests:
- not_null
Expand Down
4 changes: 2 additions & 2 deletions models/80_marts/fct_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ with
filtered_order as (
select
order_id as id,
canonical_segment_id as fk_dim1__users,
canonical_segment_id as fk__dim1_users,
transaction_hash as fk_transaction_hash,
product_id as fk_dim1__products,
product_id as fk__dim1_products,
price,
1 as order_count,
date(record_timestamp) as record_date
Expand Down
4 changes: 2 additions & 2 deletions models/80_marts/fct_orders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ models:
meta: {}
tags: []
description: Unique identifier for the order record.
- name: fk_dim1__users
- name: fk__dim1_users
data_type: STRING
tests:
- not_null
Expand All @@ -29,7 +29,7 @@ models:
meta: {}
tags: []
description: Hash of the transaction in which the order was placed.
- name: fk_dim1__products
- name: fk__dim1_products
data_type: STRING
tests:
- not_null
Expand Down
3 changes: 2 additions & 1 deletion models/80_marts/fct_paid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ with
all_paid as (select * from {{ ref("int_paid__all_paid") }}),

fact as (
select id, campaign_id as fk_campaign, spend, impressions, clicks from all_paid
select id, campaign_id as fk__dim1_campaign, spend, impressions, clicks
from all_paid
)

select *
Expand Down
2 changes: 1 addition & 1 deletion models/80_marts/fct_paid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ models:
meta: {}
tags: []
data_type: STRING
- name: fk_campaign
- name: fk__dim1_campaign
description: The foreign key identifier for the campaign
tests:
- not_null
Expand Down
5 changes: 3 additions & 2 deletions models/80_marts/fct_sessions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ with
facts as (
select
session_id as id,
canonical_segment_id_with_fallback as fk_dim1__users,
canonical_segment_id_with_fallback as fk__dim1_users,
session_start_date as fk__dim1_date,
campaign_id as fk_campaign,
campaign_id as fk__dim1_campaign,
landing_page_url_without_query_string as fk_landingpage__dim1_page,
exit_page_url_without_query_string as fk_exitpage__dim1_page,
referrer_id as fk__dim1_attribution,
{% for session_metric in var("session_metrics") %}
{{ session_metric.metric_name }}{{ "," if not loop.last }}
{% endfor %},
Expand Down
15 changes: 13 additions & 2 deletions models/80_marts/fct_sessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ models:
meta: {}
tags: []
data_type: STRING
- name: fk_dim1__users
- name: fk__dim1_users
data_type: STRING
tests:
- not_null
Expand All @@ -29,7 +29,7 @@ models:
tags: []
data_type: DATE
description: Foreign key to the DATE dimension
- name: fk_campaign
- name: fk__dim1_campaign
description: Foreign key to the campaign dimension
data_tests:
- relationships:
Expand All @@ -51,6 +51,17 @@ models:
meta: {}
tags: []
data_type: STRING
- name: fk__dim1_attribution
description: Foreign key to the attribution dimension
tests:
- not_null
- relationships:
field: id
to: ref('dim1_attribution')
config:
meta: {}
tags: []
data_type: STRING
- name: button_clicks
description: Count of button click events in the session
config:
Expand Down
Loading