-
Notifications
You must be signed in to change notification settings - Fork 17
/
push_messaging_frequency.view.lkml
129 lines (115 loc) · 4.28 KB
/
push_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
# Push Messaging Frequency
view: push_messaging_frequency {
derived_table: {
sql: SELECT * FROM
(select distinct
sends.user_id as sent_user_id,
date_trunc({% parameter date_granularity %}, to_timestamp(sends.time)) as sent_time,
opens.id as opened_id,
coalesce(count(distinct sends.id) over (partition by sent_user_id, sent_time),0)-coalesce(count(distinct bounces.id) over (partition by sent_user_id, sent_time),0) as frequency,
row_number() over (partition by sent_user_id, sent_time order by sent_time) as rank
FROM PUBLIC.USERS_MESSAGES_PUSHNOTIFICATION_SEND as sends
LEFT JOIN PUBLIC.USERS_MESSAGES_PUSHNOTIFICATION_BOUNCE as bounces ON (sends.user_id)=(bounces.user_id)
AND
((sends.message_variation_id)=(bounces.message_variation_id)
OR
(sends.canvas_step_id)=(bounces.canvas_step_id))
LEFT JOIN PUBLIC.USERS_MESSAGES_PUSHNOTIFICATION_OPEN as opens ON (sends.user_id)=(opens.user_id)
AND
((sends.message_variation_id)=(opens.message_variation_id)
OR
(sends.canvas_step_id)=(opens.canvas_step_id))
WHERE
{% condition campaign_name %} sends.campaign_name {% endcondition %}
AND
{% condition canvas_name %} sends.canvas_name {% endcondition %}
AND
{% condition message_variation_id %} sends.message_variation_id {% endcondition %}
AND
{% condition canvas_name %} sends.canvas_step_id {% endcondition %}
AND
{% condition platform %} sends.platform {% endcondition %}) WHERE frequency > 0
;;
}
filter: campaign_name {
description: "name of the campaign"
suggest_explore: users_messages_pushnotification_send
suggest_dimension: campaign_name
}
filter: canvas_name {
description: "name of the canvas"
suggest_explore: users_messages_pushnotification_send
suggest_dimension: canvas_name
}
filter: canvas_step_id {
description: "canvas step id if from a canvas"
suggest_explore: users_messages_pushnotification_send
suggest_dimension: canvas_step_id
}
filter: message_variation_id {
description: "message variation id if from a campaign"
suggest_explore: users_messages_pushnotification_send
suggest_dimension: message_variation_id
}
filter: platform {
description: "platform of the device (iOS, Android, web, etc.)"
suggest_explore: users_messages_pushnotification_send
suggest_dimension: platform
}
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: user_id {
description: "Braze id of the user"
type: string
sql: ${TABLE}."SENT_USER_ID" ;;
}
dimension_group: sent {
description: "timestamp the push notification was sent"
type: time
timeframes: [date, week, month, quarter, year]
sql: ${TABLE}."SENT_TIME" ;;
}
dimension: frequency {
description: "number of push messages delivered per date granularity (day/week/month)"
type: number
sql: ${TABLE}."FREQUENCY" ;;
}
measure: delivery_occasions {
description: "distinct occasions a certain frequency of push messages was sent to a user per date granularity"
type: number
sql: COUNT(CASE WHEN rank=1 then ${TABLE}."FREQUENCY" ELSE NULL END) ;;
}
measure: push_open_rate {
description: "push opens/push delivered"
type: number
value_format_name: percent_2
sql: ${push_opens}/NULLIF(${push_delivered},0) ;;
}
measure: push_opens {
description: "distinct count of push open event ids; may deviate lower than expected due to filtering out 'frequencies' of 0 (where sum(push sent)=sum(push bounce))"
type: count_distinct
sql: ${TABLE}."OPENED_ID" ;;
}
measure: push_delivered {
description: "distinct count of push delivery event ids"
type: sum
sql: CASE WHEN rank=1 then ${TABLE}."FREQUENCY" ELSE NULL END ;;
}
measure: unique_recipients {
description: "distinct count of user ids that received a push message"
type: count_distinct
sql: ${TABLE}."SENT_USER_ID" ;;
}
}