This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
forked from llooker/heap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_facts.view.lkml
83 lines (71 loc) · 2.14 KB
/
session_facts.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
view: session_facts {
derived_table: {
sortkeys: ["session_start_time"]
distribution: "session_unique_id"
# update trigger value to desired frequency and timezone
sql_trigger_value: select date(convert_timezone('pst', getdate() - interval '3 hours')) ;;
sql: SELECT
all_events.session_id || '-' || all_events.user_id AS session_unique_id,
user_id,
row_number() over( partition by user_id order by min(all_events.time)) as session_sequence_number,
min(all_events.time) AS session_start_time,
max(all_events.time) AS session_end_time,
COUNT(*) AS "all_events.count"
FROM main_production.all_events AS all_events
GROUP BY 1,2
;;
}
dimension: session_unique_id {
type: string
primary_key: yes
hidden: yes
sql: ${TABLE}.session_unique_id ;;
}
dimension: user_id {
type: number
hidden: yes
sql: ${TABLE}.user_id ;;
}
dimension: session_sequence_number {
type: number
sql: ${TABLE}.session_sequence_number ;;
}
dimension: is_first_session {
type: yesno
sql: ${session_sequence_number} = 1 ;;
}
dimension_group: session_start_time {
type: time
timeframes: [time, date, week, month, hour_of_day, day_of_week_index]
sql: ${TABLE}.session_start_time ;;
}
dimension_group: session_end_time {
type: time
timeframes: [time, date, week, month, hour_of_day, day_of_week_index]
sql: ${TABLE}.session_end_time ;;
}
dimension: session_duration_minutes {
type: number
sql: extract(epoch from (${TABLE}.session_end_time - ${TABLE}.session_start_time))/60 ;;
value_format_name: decimal_2
}
dimension: event_count {
type: number
sql: ${TABLE}."all_events.count" ;;
}
dimension: is_bounced {
type: yesno
# update to definition of bounced session relevant to Heap implementation
sql: ${event_count} = 1 ;;
}
measure: average_events_per_session {
type: average
sql: ${event_count} ;;
value_format_name: decimal_1
}
measure: average_session_duration_minutes {
type: average
sql: ${session_duration_minutes} ;;
value_format_name: decimal_2
}
}