-
Notifications
You must be signed in to change notification settings - Fork 17
/
email_messaging_cadence.view.lkml
166 lines (144 loc) · 6.23 KB
/
email_messaging_cadence.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
# Email Messaging Cadence
view: email_messaging_cadence {
derived_table: {
sql: with deliveries as
(select TO_TIMESTAMP(time) AS delivered_timestamp,
email_address AS delivered_address,
message_variation_id as d_message_variation_id,
canvas_step_id as d_canvas_step_id,
campaign_name as d_campaign_name,
canvas_name as d_canvas_name,
id as delivered_id,
rank() over (partition by delivered_address order by delivered_timestamp asc) as delivery_event,
min(delivered_timestamp) over (partition by delivered_address order by delivered_timestamp asc) as first_delivered,
datediff(day, lag(delivered_timestamp) over (partition by delivered_address order by delivered_timestamp asc), delivered_timestamp) as diff_days,
datediff(week, lag(delivered_timestamp) over (partition by delivered_address order by delivered_timestamp asc), delivered_timestamp) as diff_weeks
from PUBLIC.USERS_MESSAGES_EMAIL_DELIVERY group by 1,2,3,4,5,6,7),
opens as
(select distinct email_address as open_address,
message_variation_id as o_message_variation_id,
canvas_step_id as o_canvas_step_id
FROM PUBLIC.USERS_MESSAGES_EMAIL_OPEN),
clicks as
(select distinct email_address as click_address,
message_variation_id as c_message_variation_id,
canvas_step_id as c_canvas_step_id
FROM PUBLIC.USERS_MESSAGES_EMAIL_CLICK)
SELECT * FROM deliveries
LEFT JOIN opens
ON (deliveries.delivered_address)=(opens.open_address)
AND ((deliveries.d_message_variation_id)=(opens.o_message_variation_id) OR (deliveries.d_canvas_step_id)=(opens.o_canvas_step_id))
LEFT JOIN clicks
ON (deliveries.delivered_address)=(clicks.click_address)
AND ((deliveries.d_message_variation_id)=(clicks.c_message_variation_id) OR (deliveries.d_canvas_step_id)=(clicks.c_canvas_step_id))
;;
}
dimension: campaign_name {
description: "campaign name if from a campaign"
type: string
sql: ${TABLE}."D_CAMPAIGN_NAME" ;;
}
dimension: canvas_name {
description: "canvas name if from a canvas"
type: string
sql: ${TABLE}."D_CANVAS_NAME" ;;
}
dimension: canvas_step_id {
description: "canvas step ID if from a canvas"
type: string
sql: ${TABLE}."D_CANVAS_STEP_ID" ;;
}
dimension: days_since_last_received {
description: "amount of time (days) between each email message variation/canvas step delivered to an email address (null if campaign/canvas only has one send per email address)"
type: number
sql: ${TABLE}."DIFF_DAYS" ;;
}
dimension: days_since_last_received_tier {
description: "time ranges (days) between each email message variation/canvas step delivered to an email address (null if campaign/canvas only has one send per email address)"
type: tier
hidden: yes
sql: COALESCE(${TABLE}."DIFF_DAYS",0) ;;
tiers: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,28]
style: integer
}
dimension: email_address {
description: "email address of the user"
type: string
sql: ${TABLE}."delivered_ADDRESS" ;;
}
dimension_group: first_delivered {
description: "UTC epoch timestamp the first push was delivered to this user"
type: time
timeframes: [date, time]
sql: ${TABLE}."FIRST_DELIVERED" ;;
}
dimension: message_variation_id {
description: "message variation ID if from a campaign"
type: string
sql: ${TABLE}."D_MESSAGE_VARIATION_ID" ;;
}
dimension_group: delivery {
description: "UTC epoch timestamp the email was delivered"
type: time
timeframes: [date, time, hour_of_day]
sql: ${TABLE}."DELIVERED_TIMESTAMP" ;;
}
dimension: delivery_event {
description: "time-based ranking (1st, 2nd, 3rd, etc.) of message variations/canvas steps delivered to an email address"
type: number
sql: ${TABLE}."DELIVERY_EVENT" ;;
}
dimension: weeks_since_last_received {
description: "amount of time (weeeks) between each email message variation/canvas step delivered to an email address (null if campaign/canvas only has one send per email address)"
type: number
sql: ${TABLE}."DIFF_WEEKS" ;;
}
dimension: weeks_since_last_received_tier {
description: "time ranges (weeks) between each email message variation/canvas step delivered to an email address (null if campaign/canvas only has one send per email address)"
type: tier
hidden: yes
sql: COALESCE(${TABLE}."DIFF_WEEKS",0) ;;
tiers: [1,2,3,4,5,6,7,8,9,10,11,12,13,23,33,52]
style: integer
}
measure: average_number_of_days_since_last_received {
description: "average amount of time (days) between each email message variation/canvas step delivered to an email address (null if campaign/canvas only has one send per email address)"
type: average
value_format_name: decimal_0
sql: ${TABLE}."DIFF_DAYS";;
}
measure: count_distinct_email_address {
description: "distinct count of email addresses"
type: count_distinct
sql: ${TABLE}."DELIVERED_ADDRESS" ;;
}
measure: emails_delivered {
description: "distinct count of delivery ids"
type: count_distinct
sql: ${TABLE}."DELIVERED_ID" ;;
}
measure: unique_clicks {
description: "distinct count of campaigns/canvases clicked per email address; may differ by less than 1% due to inability to link exact instances of emails delivered to emails clicked"
type: number
sql: count(distinct ${TABLE}."CLICK_ADDRESS", ${TABLE}."C_MESSAGE_VARIATION_ID")
+count(distinct ${TABLE}."CLICK_ADDRESS", ${TABLE}."C_CANVAS_STEP_ID") ;;
}
measure: unique_opens {
description: "distinct count of campaigns/canvases opened per email address; may differ by less than 1% due to inability to link exact instances of emails delivered to emails opened"
type: number
sql: count(distinct ${TABLE}."OPEN_ADDRESS", ${TABLE}."O_MESSAGE_VARIATION_ID")
+count(distinct ${TABLE}."OPEN_ADDRESS", ${TABLE}."O_CANVAS_STEP_ID") ;;
}
measure: unique_open_rate {
description: "email unique opens/deliveries"
type: number
value_format_name: percent_2
sql: ${unique_opens}/${emails_delivered} ;;
}
measure: unique_click_rate {
description: "email unique opens/deliveries"
type: number
value_format_name: percent_2
sql: ${unique_clicks}/${emails_delivered} ;;
}
}