-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0c02e1
commit 7917ae5
Showing
3 changed files
with
178 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% macro stitch_adwords_click_performance() %} | ||
|
||
{{ adapter.dispatch('stitch_adwords_click_performance', 'adwords')() }} | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro athena__stitch_adwords_click_performance() %} | ||
|
||
with gclid_base as ( | ||
|
||
select | ||
|
||
googleclickid as gclid, | ||
cast(from_iso8601_timestamp(day) as date) as date_day, | ||
keywordid as criteria_id, | ||
adgroupid as ad_group_id, | ||
row_number() over (partition by googleclickid order by cast(from_iso8601_timestamp(day) as date)) as row_num | ||
|
||
from {{ var('click_performance_report') }} | ||
|
||
) | ||
|
||
select * from gclid_base | ||
where row_num = 1 | ||
and gclid is not null | ||
|
||
{% endmacro %} |
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,71 @@ | ||
{% macro stitch_adwords_criteria_performance() %} | ||
|
||
{{ adapter.dispatch('stitch_adwords_criteria_performance', 'adwords')() }} | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro athena__stitch_adwords_criteria_performance() %} | ||
|
||
with criteria_base as ( | ||
|
||
select * from {{ var('criteria_performance_report') }} | ||
|
||
), | ||
|
||
aggregated as ( | ||
|
||
select | ||
|
||
cast( | ||
{{ dbt_utils.surrogate_key ( | ||
[ | ||
'customerid', | ||
'keywordid', | ||
'adgroupid', | ||
'day' | ||
] | ||
) }} as varchar) as id, | ||
|
||
cast(from_iso8601_timestamp(day) as date) as date_day, | ||
keywordid as criteria_id, | ||
adgroup as ad_group_name, | ||
adgroupid as ad_group_id, | ||
adgroupstate as ad_group_state, | ||
campaign as campaign_name, | ||
campaignid as campaign_id, | ||
campaignstate as campaign_state, | ||
customerid as customer_id, | ||
_sdc_report_datetime, | ||
sum(clicks) as clicks, | ||
sum(impressions) as impressions, | ||
sum(cast((cast(cost as double)/cast(1000000 as double)) as decimal(38,6))) as spend | ||
|
||
from criteria_base | ||
{{ dbt_utils.group_by(11) }} | ||
|
||
), | ||
|
||
ranked as ( | ||
|
||
select | ||
|
||
*, | ||
rank() over (partition by id | ||
order by _sdc_report_datetime desc) as latest | ||
|
||
from aggregated | ||
|
||
), | ||
|
||
final as ( | ||
|
||
select * | ||
from ranked | ||
where latest = 1 | ||
|
||
) | ||
|
||
select * from final | ||
|
||
{% endmacro %} |
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,79 @@ | ||
{% macro stitch_adwords_url_performance() %} | ||
|
||
{{ adapter.dispatch('stitch_adwords_url_performance', 'adwords')() }} | ||
|
||
{% endmacro %} | ||
|
||
|
||
{% macro athena__stitch_adwords_url_performance() %} | ||
|
||
with url_performance_base as ( | ||
|
||
select * from {{ var('final_url_performance_report') }} | ||
|
||
), | ||
|
||
aggregated as ( | ||
|
||
select | ||
|
||
cast({{ dbt_utils.surrogate_key ( | ||
[ | ||
'customerid', | ||
'finalurl', | ||
'day', | ||
'campaignid', | ||
'adgroupid' | ||
] | ||
) }} as varchar) as id, | ||
|
||
cast(from_iso8601_timestamp(day) as date) as date_day, | ||
|
||
{{ dbt_utils.split_part('finalurl', "'?'", 1) }} as base_url, | ||
{{ dbt_utils.get_url_host('finalurl') }} as url_host, | ||
'/' || {{ dbt_utils.get_url_path('finalurl') }} as url_path, | ||
{{ dbt_utils.get_url_parameter('finalurl', 'utm_source') }} as utm_source, | ||
{{ dbt_utils.get_url_parameter('finalurl', 'utm_medium') }} as utm_medium, | ||
{{ dbt_utils.get_url_parameter('finalurl', 'utm_campaign') }} as utm_campaign, | ||
{{ dbt_utils.get_url_parameter('finalurl', 'utm_content') }} as utm_content, | ||
{{ dbt_utils.get_url_parameter('finalurl', 'utm_term') }} as utm_term, | ||
campaignid as campaign_id, | ||
campaign as campaign_name, | ||
adgroupid as ad_group_id, | ||
adgroup as ad_group_name, | ||
customerid as customer_id, | ||
_sdc_report_datetime, | ||
|
||
sum(clicks) as clicks, | ||
sum(impressions) as impressions, | ||
sum(cast((cast(cost as double)/cast(1000000 as double)) as decimal(38,6))) as spend | ||
|
||
from url_performance_base | ||
|
||
{{ dbt_utils.group_by(16) }} | ||
|
||
), | ||
|
||
ranked as ( | ||
|
||
select | ||
|
||
*, | ||
rank() over (partition by id | ||
order by _sdc_report_datetime desc) as latest | ||
|
||
from aggregated | ||
|
||
), | ||
|
||
final as ( | ||
|
||
select * | ||
from ranked | ||
where latest = 1 | ||
|
||
) | ||
|
||
select * from final | ||
|
||
{% endmacro %} |