Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
milo157 committed May 17, 2022
1 parent 65bbb54 commit ae54d05
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 304 deletions.
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ vars:
facebook_ads_schema: "facebook_marketing_airbyte_masch"
airbyte_facebook_ads:
ads: "{{ source('airbyte_facebook_ads','ads') }}"
ad_creative: "{{ source('airbyte_facebook_ads','ad_creative') }}"
ads_creative: "{{ source('airbyte_facebook_ads','ads_creative') }}"
ad_creatives: "{{ source('airbyte_facebook_ads','ad_creatives') }}"
ad_insights: "{{ source('airbyte_facebook_ads','ad_insights') }}"
ads_insights: "{{ source('airbyte_facebook_ads','ads_insights') }}"
campaigns: "{{ source('airbyte_facebook_ads','campaigns') }}"
7 changes: 4 additions & 3 deletions models/facebook_ads__ad_adapter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ utm term

with ads as (
select
created_at_timestamp as date_day,
created_at_date as date_day,
account_id,
account_name,
campaign_id,
Expand All @@ -21,9 +21,10 @@ with ads as (
adset_name,
ad_id,
ad_name,
account_id,
impressions,
clicks,
spend
from {{ ref('stg_facebook_ads_ads') }}
),
)

select * from ads
20 changes: 10 additions & 10 deletions models/facebook_ads__ad_set_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ with ads as (
ad_id,
ad_name,
adset_id,
adset_name,
account_id,
account_name
account_name,
campaign_id,
campaign_name,
created_at_timestamp,
created_at_date,
spend,
clicks,
impressions
Expand All @@ -29,19 +30,18 @@ with ads as (

adset as (
select
ads.created_at_timestamp,
ads.created_at_date as date_day,
ads.adset_id,
ads.adset_name,
ads.campaign_id,
ads.campaign_name,
ads.account_id,
ads.account_name,
sum(ads.spend),
sum(ads.clicks),
sum(ads.impressions)
from campaigns
left join ads using (campaign_id) and (created_at_timestamp)
{{ dbt_utils.group_by(n=6) }}
sum(ads.spend) as spend,
sum(ads.clicks) as clicks,
sum(ads.impressions) as impressions
from ads
{{ dbt_utils.group_by(n=7) }}
)

select * from final_campaigns
select * from adset
20 changes: 10 additions & 10 deletions models/facebook_ads__campaign_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ spend

with campaigns as (
select
id as campaign_id,
name as campaign_name,
campaign_id,
campaign_name,
objective,
account_id,
created_time as created_at_timestamp
created_at_date
from {{ ref('stg_facebook_ads_campaigns') }}
),

Expand All @@ -25,10 +25,10 @@ ads as (
ad_name,
adset_id,
account_id,
account_name
account_name,
campaign_id,
campaign_name,
created_at_timestamp,
created_at_date,
spend,
clicks,
impressions
Expand All @@ -37,17 +37,17 @@ ads as (

final_campaigns as (
select
campaigns.created_at_timestamp,
campaigns.created_at_date as date_day,
campaigns.campaign_id,
campaigns.campaign_name,
campaigns.account_id,
ads.account_name,
campaigns.objective,
sum(ads.spend),
sum(ads.clicks),
sum(ads.impressions)
sum(ads.spend) as spend,
sum(ads.clicks) as clicks,
sum(ads.impressions) as impressions
from campaigns
left join ads using (campaign_id) and (created_at_timestamp)
left join ads using (campaign_id, created_at_date)
{{ dbt_utils.group_by(n=6) }}
)

Expand Down
Loading

0 comments on commit ae54d05

Please sign in to comment.