This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
forked from llooker/segment_marketing_attribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_A_alias_mapping.view.lkml
74 lines (63 loc) · 1.59 KB
/
_A_alias_mapping.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
view: page_aliases_mapping {
derived_table: {
sql_trigger_value: select count(*) from @{SEGMENT_SCHEMA_NAME}.tracks ;;
sql: with
-- Establish all child-to-parent edges from tables (tracks, pages, aliases)
all_mappings as (
select
anonymous_id
,user_id
,timestamp as timestamp
from @{SEGMENT_SCHEMA_NAME}.tracks
union distinct
select
user_id
,null
,timestamp
from @{SEGMENT_SCHEMA_NAME}.tracks
union distinct
select
anonymous_id
,user_id
,timestamp
from @{SEGMENT_SCHEMA_NAME}.pages
union distinct
select
user_id
,null
,timestamp
from @{SEGMENT_SCHEMA_NAME}.pages
)
select * from (
select
-- *
distinct anonymous_id as alias,
coalesce(first_value(user_id)
over(
partition by anonymous_id
order by COALESCE(user_id, 'ZZZZZZZZZZZZZZZZZ'), timestamp desc
rows between unbounded preceding and unbounded following), anonymous_id) as looker_visitor_id
from all_mappings
where anonymous_id IS NOT NULL
order by anonymous_id
)
where alias is not NULL
;;
}
# Anonymous ID
dimension: alias {
primary_key: yes
sql: ${TABLE}.alias ;;
}
# User ID
dimension: looker_visitor_id {
sql: ${TABLE}.looker_visitor_id ;;
}
measure: count {
type: count
}
measure: count_visitor {
type: count_distinct
sql: ${looker_visitor_id} ;;
}
}