forked from llooker/demo_segment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_C_session_pg_tracks.view.lkml
86 lines (73 loc) · 2.24 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
view: sessions_pg_trk {
derived_table: {
sortkeys: ["session_start_at"]
distribution: "looker_visitor_id"
sql_trigger_value: select count(*) from ${mapped_events.SQL_TABLE_NAME} ;;
sql: select row_number() over(partition by looker_visitor_id order by received_at) || ' - '|| looker_visitor_id as session_id
, looker_visitor_id
, received_at as session_start_at
, row_number() over(partition by looker_visitor_id order by received_at) as session_sequence_number
, lead(received_at) over(partition by looker_visitor_id order by received_at) as next_session_start_at
from ${mapped_events.SQL_TABLE_NAME}
where (idle_time_minutes > 30 or idle_time_minutes is null)
;;
}
dimension: session_id {
hidden: yes
sql: ${TABLE}.session_id ;;
}
dimension: looker_visitor_id {
type: number
sql: ${TABLE}.looker_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: ${looker_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, looker_visitor_id, start_date, session_sequence_number, next_session_start_at_date]
}
}