-
Notifications
You must be signed in to change notification settings - Fork 4
/
52_sessions.view.lkml
270 lines (218 loc) · 5.78 KB
/
52_sessions.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
view: sessions {
derived_table: {
persist_for: "24 hours"
sql: SELECT
session_id
, MIN(created_at) AS session_start
, MAX(created_at) AS session_end
, COUNT(*) AS number_of_events_in_session
, SUM(CASE WHEN event_type IN ('Category','Brand') THEN 1 END) AS browse_events
, SUM(CASE WHEN event_type = 'Product' THEN 1 END) AS product_events
, SUM(CASE WHEN event_type = 'Cart' THEN 1 END) AS cart_events
, SUM(CASE WHEN event_type = 'Purchase' THEN 1 end) AS purchase_events
, MAX(user_id) AS session_user_id
, MIN(id) AS landing_event_id
, MAX(id) AS bounce_event_id
FROM events
GROUP BY session_id
;;
}
##### Basic Web Info ########
measure: count {
type: count
drill_fields: [detail*]
}
dimension: session_id {
type: string
primary_key: yes
sql: ${TABLE}.session_id ;;
}
dimension: session_user_id {
sql: ${TABLE}.session_user_id ;;
}
dimension: landing_event_id {
sql: ${TABLE}.landing_event_id ;;
}
dimension: bounce_event_id {
sql: ${TABLE}.bounce_event_id ;;
}
dimension_group: session_start {
type: time
# timeframes: [time, date, week, month, hour_of_day, day_of_week]
sql: ${TABLE}.session_start ;;
}
dimension_group: session_end {
type: time
timeframes: [raw, time, date, week, month]
sql: ${TABLE}.session_end ;;
}
dimension: duration {
label: "Duration (sec)"
type: number
sql: DATEDIFF('second', ${session_start_raw}, ${session_end_raw}) ;;
}
measure: average_duration {
label: "Average Duration (sec)"
type: average
value_format_name: decimal_2
sql: ${duration} ;;
}
dimension: duration_seconds_tier {
label: "Duration Tier (sec)"
type: tier
tiers: [10, 30, 60, 120, 300]
style: integer
sql: ${duration} ;;
}
##### Bounce Information ########
dimension: is_bounce_session {
type: yesno
sql: ${number_of_events_in_session} = 1 ;;
}
measure: count_bounce_sessions {
type: count
filters: {
field: is_bounce_session
value: "Yes"
}
drill_fields: [detail*]
}
measure: percent_bounce_sessions {
type: number
value_format_name: percent_2
sql: 1.0 * ${count_bounce_sessions} / nullif(${count},0) ;;
}
####### Session by event types included ########
dimension: number_of_browse_events_in_session {
type: number
hidden: yes
sql: ${TABLE}.browse_events ;;
}
dimension: number_of_product_events_in_session {
type: number
hidden: yes
sql: ${TABLE}.product_events ;;
}
dimension: number_of_cart_events_in_session {
type: number
hidden: yes
sql: ${TABLE}.cart_events ;;
}
dimension: number_of_purchase_events_in_session {
type: number
hidden: yes
sql: ${TABLE}.purchase_events ;;
}
dimension: includes_browse {
type: yesno
sql: ${number_of_browse_events_in_session} > 0 ;;
}
dimension: includes_product {
type: yesno
sql: ${number_of_product_events_in_session} > 0 ;;
}
dimension: includes_cart {
type: yesno
sql: ${number_of_cart_events_in_session} > 0 ;;
}
dimension: includes_purchase {
type: yesno
sql: ${number_of_purchase_events_in_session} > 0 ;;
}
measure: count_with_cart {
type: count
filters: {
field: includes_cart
value: "Yes"
}
drill_fields: [detail*]
}
measure: count_with_purchase {
type: count
filters: {
field: includes_purchase
value: "Yes"
}
drill_fields: [detail*]
}
dimension: number_of_events_in_session {
type: number
sql: ${TABLE}.number_of_events_in_session ;;
}
####### Linear Funnel ########
dimension: furthest_funnel_step {
sql: CASE
WHEN ${number_of_purchase_events_in_session} > 0 THEN '(5) Purchase'
WHEN ${number_of_cart_events_in_session} > 0 THEN '(4) Add to Cart'
WHEN ${number_of_product_events_in_session} > 0 THEN '(3) View Product'
WHEN ${number_of_browse_events_in_session} > 0 THEN '(2) Browse'
ELSE '(1) Land'
END
;;
}
measure: all_sessions {
view_label: "Funnel View"
label: "(1) All Sessions"
type: count
drill_fields: [detail*]
}
measure: count_browse_or_later {
view_label: "Funnel View"
label: "(2) Browse or later"
type: count
filters: {
field: furthest_funnel_step
value: "(2) Browse,(3) View Product,(4) Add to Cart,(5) Purchase
"
}
drill_fields: [detail*]
}
measure: count_product_or_later {
view_label: "Funnel View"
label: "(3) View Product or later"
type: count
filters: {
field: furthest_funnel_step
value: "(3) View Product,(4) Add to Cart,(5) Purchase
"
}
drill_fields: [detail*]
}
measure: count_cart_or_later {
view_label: "Funnel View"
label: "(4) Add to Cart or later"
type: count
filters: {
field: furthest_funnel_step
value: "(4) Add to Cart,(5) Purchase
"
}
drill_fields: [detail*]
}
measure: count_purchase {
view_label: "Funnel View"
label: "(5) Purchase"
type: count
filters: {
field: furthest_funnel_step
value: "(5) Purchase
"
}
drill_fields: [detail*]
}
measure: cart_to_checkout_conversion {
view_label: "Funnel View"
type: number
value_format_name: percent_2
sql: 1.0 * ${count_purchase} / nullif(${count_cart_or_later},0) ;;
}
measure: overall_conversion {
view_label: "Funnel View"
type: number
value_format_name: percent_2
sql: 1.0 * ${count_purchase} / nullif(${count},0) ;;
}
set: detail {
fields: [session_id, session_start_time, session_end_time, number_of_events_in_session, duration, number_of_purchase_events_in_session, number_of_cart_events_in_session]
}
}