-
Notifications
You must be signed in to change notification settings - Fork 12
/
linkedin_ads__account_report.sql
64 lines (50 loc) · 1.94 KB
/
linkedin_ads__account_report.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{{ config(enabled=var('ad_reporting__linkedin_ads_enabled', True)) }}
with account as (
select *
from {{ var('account_history') }}
where is_latest_version
),
campaign as (
select *
from {{ var('campaign_history') }}
where is_latest_version
),
report as (
select *,
{% if var('linkedin_ads__conversion_fields', none) %}
{{ var('linkedin_ads__conversion_fields') | join(' + ') }} as total_conversions
{% else %}
0 as total_conversions
{% endif %}
from {{ var('ad_analytics_by_campaign') }}
),
final as (
select
report.source_relation,
report.date_day,
account.account_id,
account.account_name,
account.version_tag,
account.currency,
account.status,
account.type,
account.last_modified_at,
account.created_at,
sum(report.total_conversions) as total_conversions,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions,
sum(report.cost) as cost,
sum(coalesce(report.conversion_value_in_local_currency, 0)) as conversion_value_in_local_currency
{{ linkedin_ads_persist_pass_through_columns(pass_through_variable='linkedin_ads__conversion_fields', transform='sum', coalesce_with=0, except_variable='linkedin_ads__campaign_passthrough_metrics', exclude_fields=['conversion_value_in_local_currency']) }}
{{ linkedin_ads_persist_pass_through_columns(pass_through_variable='linkedin_ads__campaign_passthrough_metrics', transform='sum', exclude_fields=['conversion_value_in_local_currency']) }}
from report
left join campaign
on report.campaign_id = campaign.campaign_id
and report.source_relation = campaign.source_relation
left join account
on campaign.account_id = account.account_id
and campaign.source_relation = account.source_relation
{{ dbt_utils.group_by(10) }}
)
select *
from final