-
Notifications
You must be signed in to change notification settings - Fork 17
/
email_messaging_frequency.view.lkml
173 lines (154 loc) · 5.99 KB
/
email_messaging_frequency.view.lkml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Email Messaging Frequency
view: email_messaging_frequency {
derived_table: {
sql: SELECT date_trunc({% parameter date_granularity %}, to_timestamp(deliveries.time)) AS delivered_time,
deliveries.email_address AS delivered_address,
deliveries.ID as delivered_id,
count(distinct deliveries.id ) over (partition by delivered_time, delivered_address) AS frequency,
row_number() over (partition by delivered_address, delivered_time order by delivered_time) as rank,
opens.email_address as opened_address,
opens.message_variation_id as opened_mv_id,
opens.canvas_step_id as opened_cs_id,
clicks.email_address as clicked_address,
clicks.message_variation_id as clicked_mv_id,
clicks.canvas_step_id as clicked_cs_id
FROM PUBLIC.USERS_MESSAGES_EMAIL_DELIVERY AS deliveries
LEFT JOIN PUBLIC.USERS_MESSAGES_EMAIL_OPEN AS opens ON (deliveries.email_address)=(opens.email_address)
AND
((deliveries.message_variation_id)=(opens.message_variation_id)
OR
(deliveries.canvas_step_id)=(opens.canvas_step_id))
LEFT JOIN PUBLIC.USERS_MESSAGES_EMAIL_CLICK AS clicks ON (deliveries.email_address)=(clicks.email_address)
AND
((deliveries.message_variation_id)=(clicks.message_variation_id)
OR
(deliveries.canvas_step_id)=(clicks.canvas_step_id))
WHERE
{% condition campaign_name %} deliveries.campaign_name {% endcondition %}
AND
{% condition canvas_name %} deliveries.canvas_name {% endcondition %}
AND
{% condition message_variation_id %} deliveries.message_variation_id {% endcondition %}
AND
{% condition canvas_name %} deliveries.canvas_step_id {% endcondition %}
;;
}
filter: campaign_name {
description: "name of the campaign"
suggest_explore: users_messages_email_send
suggest_dimension: campaign_name
}
filter: canvas_name {
description: "name of the canvas"
suggest_explore: users_messages_email_send
suggest_dimension: canvas_name
}
filter: canvas_step_id {
description: "canvas step id if from a canvas"
suggest_explore: users_messages_email_send
suggest_dimension: canvas_step_id
}
filter: message_variation_id {
description: "message variation id if from a campaign"
suggest_explore: users_messages_email_send
suggest_dimension: message_variation_id
}
parameter: date_granularity {
description: "specify daily, weekly or monthly marketing pressure"
type: string
default_value: "day"
allowed_value: {
value: "day"
}
allowed_value: {
value: "week"
}
allowed_value: {
value: "month"
}
}
dimension_group: delivered_time {
description: "time the email was delivered (UTC)"
type: time
timeframes: [hour_of_day,
date,
day_of_week,
week, month,
quarter,
year]
sql: ${TABLE}."DELIVERED_TIME" ;;
}
dimension: email_address {
description: "email address of the user"
type: string
sql: ${TABLE}."DELIVERED_ADDRESS" ;;
}
dimension: frequency {
description: "number of emails sent per date granularity (day/week/month)"
type: number
sql: ${TABLE}."FREQUENCY" ;;
}
measure: emails_delivered {
description: "count of unique delivery event IDs"
type: sum
sql: CASE WHEN rank=1 then ${frequency} else null end ;;
}
measure: unique_opens_mvid {
description: "unique opens corresponding to message variations"
type: count_distinct
hidden: yes
sql: ${TABLE}."OPENED_ADDRESS", ${TABLE}."OPENED_MV_ID" ;;
}
measure: unique_opens_csid {
description: "unique opens corresponding to canvas steps"
type: count_distinct
hidden: yes
sql: ${TABLE}."OPENED_ADDRESS", ${TABLE}."OPENED_CS_ID" ;;
}
measure: unique_clicks_mvid {
description: "unique clicks corresponding to message variations"
type: count_distinct
hidden: yes
sql: ${TABLE}."CLICKED_ADDRESS", ${TABLE}."CLICKED_MV_ID" ;;
}
measure: unique_clicks_csid {
description: "unique clicks corresponding to canvas steps"
type: count_distinct
hidden: yes
sql: ${TABLE}."CLICKED_ADDRESS", ${TABLE}."CLICKED_CS_ID" ;;
}
measure: unique_opens {
description: "distinct count of times a recipient opened an email campaign or canvas (does not count the same person opening the same campaign or canvas more than once);
expected behavior is for this measure to deviate from actual by less than 1% because of limitations on linking specific instances of emails delivered to emails opened"
type: number
sql: COALESCE(${unique_opens_mvid},0)+COALESCE(${unique_opens_csid},0);;
}
measure: unique_clicks {
description: "distinct count of times a recipient opened an email campaign or canvas (does not count the same person opening the same campaign or canvas more than once);
expected behavior is for this measure to deviate from actual by less than 1% because of limitations on linking specific instances of emails delivered to emails clicked"
type: number
sql: COALESCE(${unique_clicks_mvid},0)+COALESCE(${unique_clicks_csid},0) ;;
}
measure: delivery_occasions {
description: "occasions a certain frequency of emails was sent to a user per date granularity"
type: number
sql: COUNT(CASE WHEN rank=1 then ${frequency} else null end) ;;
}
measure: unique_click_rate {
description: "email unique clicks/emails delivered"
type: number
value_format_name: percent_2
sql: ${unique_clicks}/NULLIF(${emails_delivered},0) ;;
}
measure: unique_open_rate {
description: "email unique opens/emails delivered"
type: number
value_format_name: percent_2
sql: ${unique_opens}/NULLIF(${emails_delivered},0) ;;
}
measure: unique_recipients {
description: "distinct count of email addresses that received an email campaign"
type: count_distinct
sql: ${TABLE}."DELIVERED_ADDRESS" ;;
}
}