-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpinterest_ads__pin_promotion_report.sql
75 lines (59 loc) · 1.71 KB
/
pinterest_ads__pin_promotion_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
65
66
67
68
69
70
71
72
73
74
75
{{ config(enabled=var('ad_reporting__pinterest_ads_enabled', True)) }}
with report as (
select *
from {{ var('pin_promotion_report') }}
),
pins as (
select *
from {{ var('pin_promotion_history') }}
where is_most_recent_record = True
),
ad_groups as (
select *
from {{ var('ad_group_history') }}
where is_most_recent_record = True
),
campaigns as (
select *
from {{ var('campaign_history') }}
where is_most_recent_record = True
),
advertisers as (
select *
from {{ var('advertiser_history') }}
where is_most_recent_record = True
),
joined as (
select
report.date_day,
campaigns.advertiser_id,
advertisers.advertiser_name,
report.campaign_id,
campaigns.campaign_name,
campaigns.campaign_status,
report.ad_group_id,
ad_groups.ad_group_name,
ad_groups.ad_group_status,
pins.creative_type,
report.pin_promotion_id,
pins.pin_name,
pins.pin_status,
pins.destination_url,
pins.base_url,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions,
sum(report.spend) as spend
{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='pinterest__pin_promotion_report_passthrough_metrics', transform = 'sum') }}
from report
left join pins
on report.pin_promotion_id = pins.pin_promotion_id
left join ad_groups
on report.ad_group_id = ad_groups.ad_group_id
left join campaigns
on report.campaign_id = campaigns.campaign_id
left join advertisers
on campaigns.advertiser_id = advertisers.advertiser_id
{{ dbt_utils.group_by(15) }}
)
select *
from joined