-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fishtown-analytics/feature/vars
updates
- Loading branch information
Showing
10 changed files
with
126 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
with base as ( | ||
|
||
select | ||
id, | ||
url_tags, | ||
coalesce( | ||
object_story_spec__link_data__call_to_action__value__link, | ||
object_story_spec__link_data__link, | ||
link_url | ||
) as url | ||
from | ||
{{ var('ad_creatives_table') }} | ||
|
||
) | ||
|
||
select | ||
id, | ||
url_tags, | ||
*, | ||
split_part(url ,'?',1) as base_url, | ||
split_part(split_part(url_tags,'utm_source=',2), '&', 1) as utm_source, | ||
split_part(split_part(url_tags,'utm_medium=',2), '&', 1) as utm_medium, | ||
split_part(split_part(url_tags,'utm_campaign=',2), '&', 1) as utm_campaign, | ||
split_part(split_part(url_tags,'utm_content=',2), '&', 1) as utm_content, | ||
split_part(split_part(url_tags,'utm_term=',2), '&', 1) as utm_term | ||
from | ||
facebook_us.facebook_adcreative_410871425756349 | ||
from base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
select | ||
* | ||
from | ||
facebook_us.facebook_ads_insights_410871425756349 | ||
{{ var('ads_insights_table') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select | ||
* | ||
from | ||
{{ var('ads_insights_agegender_table') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
select | ||
id as campaign_id, | ||
name as campaign_name | ||
from | ||
{{ var('campaigns_table') }} |
25 changes: 25 additions & 0 deletions
25
models/stitch/transform/facebook_ad_insights_age_gender_xf.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
with ads as ( | ||
|
||
select * from {{ref('facebook_ads')}} | ||
|
||
), creatives as ( | ||
|
||
select * from {{ref('facebook_ad_creatives')}} | ||
|
||
), insights as ( | ||
|
||
select * from {{ref('facebook_ads_insights_age_gender')}} | ||
|
||
) | ||
select | ||
insights.*, | ||
creatives.base_url, | ||
creatives.url, | ||
creatives.utm_medium, | ||
creatives.utm_source, | ||
creatives.utm_campaign, | ||
creatives.utm_content, | ||
creatives.utm_term | ||
from insights | ||
inner join ads on insights.ad_id = ads.id | ||
inner join creatives on ads.creative_id = creatives.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
with ads as ( | ||
|
||
select * from {{ref('facebook_ads')}} | ||
|
||
), creatives as ( | ||
|
||
select * from {{ref('facebook_ad_creatives')}} | ||
|
||
), insights as ( | ||
|
||
select * from {{ref('facebook_ad_insights')}} | ||
|
||
) | ||
select | ||
insights.*, | ||
creatives.base_url, | ||
creatives.url, | ||
creatives.utm_medium, | ||
creatives.utm_source, | ||
creatives.utm_campaign, | ||
creatives.utm_content, | ||
creatives.utm_term | ||
from insights | ||
inner join ads on insights.ad_id = ads.id | ||
inner join creatives on ads.creative_id = creatives.id |
55 changes: 17 additions & 38 deletions
55
models/stitch/transform/facebook_ad_performance_by_url.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,22 @@ | ||
with ads as ( | ||
with insights as ( | ||
|
||
select * from {{ref('facebook_ads')}} | ||
|
||
), creatives as ( | ||
|
||
select * from {{ref('facebook_ad_creatives')}} | ||
|
||
), insights as ( | ||
|
||
select * from {{ref('facebook_ad_insights')}} | ||
|
||
), joined as ( | ||
|
||
select | ||
* | ||
from insights | ||
inner join ads on insights.ad_id = ads.id | ||
inner join creatives on ads.creative_id = creatives.id | ||
|
||
), aggregated as ( | ||
|
||
select | ||
date_start::date as insight_date, | ||
utm_medium, | ||
utm_source, | ||
utm_campaign, | ||
utm_content, | ||
utm_term, | ||
sum(impressions) as impressions, | ||
sum(spend) as spend, | ||
sum(website_clicks) as clicks | ||
from joined | ||
group by 1, 2, 3, 4, 5, 6 | ||
select * from {{ref('facebook_ad_insights_xf')}} | ||
|
||
) | ||
|
||
select | ||
*, | ||
spend / nullif(clicks, 0) as cpc, | ||
spend / (nullif(impressions, 0) * .001::numeric(38,6)) as cpm | ||
from aggregated | ||
order by 1, 2, 3, 4, 5, 6 | ||
date_start::date as insight_date, | ||
ad_id, | ||
campaign_id, | ||
url, | ||
base_url, | ||
utm_medium, | ||
utm_source, | ||
utm_campaign, | ||
utm_content, | ||
utm_term, | ||
sum(impressions) as impressions, | ||
sum(spend) as spend, | ||
sum(website_clicks) as clicks | ||
from insights | ||
group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
24 changes: 24 additions & 0 deletions
24
models/stitch/transform/facebook_ad_performance_by_url_age_gender.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
with insights as ( | ||
|
||
select * from {{ref('facebook_ad_insights_age_gender_xf')}} | ||
|
||
) | ||
|
||
select | ||
date_start::date as insight_date, | ||
ad_id, | ||
campaign_id, | ||
age, | ||
gender, | ||
url, | ||
base_url, | ||
utm_medium, | ||
utm_source, | ||
utm_campaign, | ||
utm_content, | ||
utm_term, | ||
sum(coalesce(impressions__bigint, nullif(impressions__string, '')::int)) as impressions, --fix! | ||
sum(spend) as spend, | ||
sum(website_clicks) as clicks | ||
from insights | ||
group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 |