Skip to content
Merged
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: 13 additions & 0 deletions models/00_sources/cost_import_sheet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
- name: raw_other_marketing_costs
database: mezo-portal-data
schema: raw_other_marketing_costs
tables:
- name: other_marketing_costs
description: Other marketing costs imported from Google Sheets
external:
options:
format: 'GOOGLE_SHEETS'
uris: ['https://docs.google.com/spreadsheets/d/1ayInoMFB6jwTUhExq9XmQDuzw6GzYmE88O39kLgjyU8/edit?usp=sharing']
sheet_range: 'Sheet1!A1:H1000'
skip_leading_rows: 1
18 changes: 18 additions & 0 deletions models/10_staging/paid/stg_paid__raw_other_marketing_costs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with
source as (
select * from {{ source("raw_other_marketing_costs", "other_marketing_costs") }}
),

renamed as (
select
cast(record_date as date) as date_day,
cast(referrer_source as string) as referrer_source,
cast(referrer_medium as string) as referrer_medium,
cast(spend as float64) as spend,
cast(impressions as int64) as impressions,
cast(clicks as int64) as clicks
from source
)

select *
from renamed
40 changes: 40 additions & 0 deletions models/10_staging/paid/stg_paid__raw_other_marketing_costs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
models:
- name: stg_paid__raw_other_marketing_costs
description: Staging table for raw other marketing costs imported from Google Sheets.
columns:
- name: date_day
description: The date the record was created
data_type: STRING
config:
meta: {}
tags: []
- name: referrer_source
description: The source of the referral
data_type: STRING
config:
meta: {}
tags: []
- name: referrer_medium
description: The medium of the referral
data_type: STRING
config:
meta: {}
tags: []
- name: spend
description: The amount spent on the campaign
data_type: FLOAT64
config:
meta: {}
tags: []
- name: impressions
description: The number of impressions served
data_type: INT64
config:
meta: {}
tags: []
- name: clicks
description: The number of clicks received
data_type: INT64
config:
meta: {}
tags: []
17 changes: 10 additions & 7 deletions models/50_intermediate/paid/int_paid__all_paid.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
with
twitter as (select * from {{ ref("twitter_ads", "twitter_ads__campaign_report") }}),
union_paid as (select * from {{ ref("int_paid__union_paid") }}),

add_unique_id as (
sur_key as (
select
* except (campaign_id),
concat('twitter_', campaign_id, date_day) as id,
concat('twitter_', campaign_id) as campaign_id
from twitter
*,
{{
dbt_utils.generate_surrogate_key(
["campaign_id", "referrer_medium", "referrer_source"]
)
}} as paid_id
from union_paid
)

select *
from add_unique_id
from sur_key
16 changes: 14 additions & 2 deletions models/50_intermediate/paid/int_paid__all_paid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,20 @@ models:
meta: {}
tags: []
data_type: FLOAT64
- name: id
description: The ID of the campaign.
- name: referrer_source
description: The source of the referral
config:
meta: {}
tags: []
data_type: STRING
- name: referrer_medium
description: The medium of the referral
config:
meta: {}
tags: []
data_type: STRING
- name: paid_id
description: Surrogate key for the campaign, generated from referrer source + medium + campaign id.
config:
meta: {}
tags: []
Expand Down
18 changes: 18 additions & 0 deletions models/50_intermediate/paid/int_paid__union_paid.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{
dbt_utils.union_relations(
relations=[
ref("stg_paid__raw_other_marketing_costs"),
ref("int_paid__twitter"),
],
include=[
"date_day",
"clicks",
"impressions",
"spend",
"campaign_id",
"referrer_source",
"referrer_medium",
],
source_column_name="source_relation",
)
}}
58 changes: 58 additions & 0 deletions models/50_intermediate/paid/int_paid__union_paid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 2
models:
- name: int_paid__union_paid
columns:
- name: source_relation
description: >-
The source of the record if the unioning functionality is being used.
If not this field will be empty.
config:
meta: {}
tags: []
data_type: STRING
- name: date_day
description: The date of the performance.
config:
meta: {}
tags: []
data_type: DATE
- name: clicks
description: >-
The number of clicks on that date. Includes clicks on the URL (shortened or regular links),
profile pic, screen name, username, detail, hashtags, and likes.
config:
meta: {}
tags: []
data_type: INT64
- name: impressions
description: >-
The number of impressions on that date. This is the number of users who see a Promoted Ad either
in their home timeline or search results.
config:
meta: {}
tags: []
data_type: INT64
- name: spend
description: The amount of spend on that date.
config:
meta: {}
tags: []
data_type: FLOAT64
- name: referrer_source
description: The source of the referral
config:
meta: {}
tags: []
data_type: STRING
- name: referrer_medium
description: The medium of the referral
config:
meta: {}
tags: []
data_type: STRING
- name: campaign_id
description: The ID of the campaign.
config:
meta: {}
tags: []
data_type: STRING
14 changes: 14 additions & 0 deletions models/50_intermediate/paid/twitter/int_paid__twitter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
with
twitter as (select * from {{ ref("twitter_ads", "twitter_ads__campaign_report") }}),

add_unique_id as (
select
* except (campaign_id),
'twitter' as referrer_source,
'paid_social' as referrer_medium,
concat('twitter_', campaign_id) as campaign_id
from twitter
)

select *
from add_unique_id
Loading
Loading