forked from llooker/demo_segment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_C_session_pg_tracks.view.lkml
90 lines (77 loc) · 2.51 KB
/
_C_session_pg_tracks.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
view: sessions_pg_trk {
derived_table: {
sortkeys: ["session_start_at"]
distribution: "tenantbase_visitor_id"
sql_trigger_value: SELECT COUNT(*) FROM ${mapped_events.SQL_TABLE_NAME} ;;
sql: SELECT
ROW_NUMBER() OVER(PARTITION BY tenantbase_visitor_id ORDER BY "timestamp") || ' - '|| tenantbase_visitor_id as session_id
, tenantbase_visitor_id
, "timestamp" AS session_start_at
, ROW_NUMBER() OVER(PARTITION BY tenantbase_visitor_id ORDER BY "timestamp") AS session_sequence_number
-- Default offset of lead is 1 (gives the next possible value)
, LEAD("timestamp") OVER(PARTITION BY tenantbase_visitor_id ORDER BY "timestamp") AS next_session_start_at
FROM ${mapped_events.SQL_TABLE_NAME}
-- Where clause indicates either end of session or first session
WHERE (idle_time_minutes > 30 OR idle_time_minutes is NULL)
;;
}
dimension: session_id {
hidden: yes
sql: ${TABLE}.session_id ;;
}
dimension: tenantbase_visitor_id {
type: string
sql: ${TABLE}.tenantbase_visitor_id ;;
}
dimension_group: start {
type: time
timeframes: [time, date, week, month, raw]
sql: ${TABLE}.session_start_at ;;
}
dimension: session_sequence_number {
type: number
sql: ${TABLE}.session_sequence_number ;;
}
dimension_group: next_session_start_at {
type: time
timeframes: [time, date, week, month, raw]
sql: ${TABLE}.next_session_start_at ;;
}
dimension: is_first_session {
# type: yesno
sql: CASE WHEN ${session_sequence_number} = 1 THEN 'First Session'
ELSE 'Repeat Session'
END
;;
}
dimension: session_duration_minutes {
type: number
sql: DATEDIFF(minutes, ${start_time}::timestamp, ${session_pg_trk_facts.end_time}::timestamp) ;;
}
measure: count {
type: count
drill_fields: [detail*]
}
measure: percent_of_total_count {
type: percent_of_total
sql: ${count} ;;
}
measure: count_visitors {
type: count_distinct
sql: ${tenantbase_visitor_id} ;;
drill_fields: [tenantbase_visitor_id]
}
measure: avg_sessions_per_user {
type: number
value_format_name: decimal_2
sql: ${count}::numeric / nullif(${count_visitors}, 0) ;;
}
measure: avg_session_duration_minutes {
type: average
sql: ${session_duration_minutes} ;;
value_format_name: decimal_1
}
set: detail {
fields: [session_id, tenantbase_visitor_id, start_date, session_sequence_number, next_session_start_at_date]
}
}