Created
May 3, 2024 02:11
-
-
Save lfy79001/e6e4b39023071276d7a87faaeca37df1 to your computer and use it in GitHub Desktop.
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
{{ config(enabled=var('ad_reporting__google_ads_enabled', True)) }} | |
with stats as ( | |
select * | |
from {{ var('campaign_stats') }} | |
), | |
accounts as ( | |
select * | |
from {{ var('account_history') }} | |
where is_most_recent_record = True | |
), | |
campaigns as ( | |
select * | |
from {{ var('campaign_history') }} | |
where is_most_recent_record = True | |
), | |
fields as ( | |
select | |
stats.source_relation, | |
stats.date_day, | |
accounts.account_name, | |
accounts.account_id, | |
accounts.currency_code, | |
campaigns.campaign_name, | |
stats.campaign_id, | |
campaigns.advertising_channel_type, | |
campaigns.advertising_channel_subtype, | |
campaigns.status, | |
sum(stats.spend) as spend, | |
sum(stats.clicks) as clicks, | |
sum(stats.impressions) as impressions | |
{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='google_ads__campaign_stats_passthrough_metrics', transform = 'sum') }} | |
from stats | |
left join campaigns | |
on stats.campaign_id = campaigns.campaign_id | |
and stats.source_relation = campaigns.source_relation | |
left join accounts | |
on campaigns.account_id = accounts.account_id | |
and campaigns.source_relation = accounts.source_relation | |
{{ dbt_utils.group_by(10) }} | |
) | |
select * | |
from fields |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment