This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathga_sessions.view.lkml
283 lines (231 loc) · 8.79 KB
/
ga_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
271
272
273
274
275
276
277
278
279
280
281
282
283
view: ga_sessions_config {
extends: [ga_sessions_core]
extension: required
# Scenario 1 (S1): You are viewing a single GA 360 property
# S1 TODO: Update the sql_table_name with the customer’s schema name.
# Single property
sql_table_name: `@{SCHEMA_NAME}.@{GA360_TABLE_NAME}` ;;
dimension_group: partition {
# Date that is parsed from the table name. Required as a filter to avoid accidental massive queries
label: ""
view_label: "Session"
description: "Date based on the day the session was added to the database. Matches date in Google Analytics UI, but may not match 'Session Start Date'."
type: time
timeframes: [
date,
day_of_week,
day_of_week_index,
day_of_month,
day_of_year,
fiscal_quarter,
fiscal_quarter_of_year,
week,
month,
month_name,
month_num,
quarter,
quarter_of_year,
week_of_year,
year
]
sql: TIMESTAMP(
PARSE_DATE(
'%Y%m%d'
, REGEXP_EXTRACT(
_TABLE_SUFFIX
, r'^\d\d\d\d\d\d\d\d'
)
)
);;
convert_tz: no
}
# # Scenario 2 (S2): You are viewing Multiple GA 360 properties in the same BQ project and are leveraging analytics across multiple properties
# # TODO: update the always_filter in the model
# # TODO: Uncomment the sql_table_name and update the FROM statement and property nickname
# sql_table_name:
# (
# SELECT *, 'Property1' as property, TIMESTAMP(PARSE_DATE('%Y%m%d', REGEXP_EXTRACT(_TABLE_SUFFIX,r'^\d\d\d\d\d\d\d\d'))) AS partition_date
# FROM `@{SCHEMA_NAME}.@{GA360_TABLE_NAME}`
# WHERE {% condition partition_filter %} TIMESTAMP(PARSE_DATE('%Y%m%d', REGEXP_EXTRACT(_TABLE_SUFFIX,r'^\d\d\d\d\d\d\d\d'))) {% endcondition %}
# UNION ALL
# SELECT *, 'Property2' as property, TIMESTAMP(PARSE_DATE('%Y%m%d', REGEXP_EXTRACT(_TABLE_SUFFIX,r'^\d\d\d\d\d\d\d\d'))) AS partition_date
# FROM `@{SCHEMA_NAME}.@{GA360_TABLE_NAME}`
# WHERE {% condition partition_filter %} TIMESTAMP(PARSE_DATE('%Y%m%d', REGEXP_EXTRACT(_TABLE_SUFFIX,r'^\d\d\d\d\d\d\d\d'))) {% endcondition %}
# );;
# # S2 TODO: Uncomment field
# filter: partition_filter {
# type: date
# default_value: "@{EXPLORE_DATE_FILTER}"
# }
# # S2 TODO: Uncomment field and comment out the partition date above
# dimension_group: partition {
# # Date that is parsed from the table name. Required as a filter to avoid accidental massive queries
# label: ""
# view_label: "Session"
# description: "Date based on the day the session was added to the database. Matches date in Google Analytics UI, but may not match 'Session Start Date'."
# type: time
# timeframes: [
# date,
# day_of_week,
# day_of_week_index,
# day_of_month,
# day_of_year,
# fiscal_quarter,
# fiscal_quarter_of_year,
# week,
# month,
# month_name,
# month_num,
# quarter,
# quarter_of_year,
# week_of_year,
# year
# ]
# sql: ${TABLE}.partition_date ;;
# # can_filter: no
# convert_tz: no
# }
# # S2 TODO: Uncomment out the field and update the property and website names
# dimension: property {
# hidden: yes
# suggestions: ["Website1","Website2"]
# sql: CASE
# WHEN ${TABLE}.property = "Property1" THEN "Website1"
# WHEN ${TABLE}.property = "Property2" THEN "Website2"
# ELSE NULL
# END
# ;;
# }
# #Scenario 3 (S3): Multiple properties but allow specific users to view their own properties
# # S3 TODO: Create a user attribute ga_360_schema and assign values for each user.
# Uncomment out the sql_table_name below
# # Single property
# sql_table_name: `{{ _user_attributes['ga_360_schema'] }}.@{GA360_TABLE_NAME} ;;
# # TODO: CUSTOMIZE GOALS HERE ####
# # Goals measure how well your site or app fulfills your target objectives. A goal represents a completed activity,
# # called a conversion, that contributes to the success of your business. Examples of goals include making a purchase
# # (for an ecommerce site), completing a game level (for a mobile gaming app), or submitting a contact information
# # form (for a marketing or lead generation site).
# # Find more information here: https://support.google.com/analytics/answer/1012040?hl=en&ref_topic=6150889
# # "Selected_goal_conversions", "selected_goal_conversion_rate", and "selected_goal_conversion_value" are the
# # measures used in the application interface. Make sure that these measures contain all of the possible goals.
# # The goal will be selected using a filter in the Application UI.
# goal definitions
dimension: demo_goal_hit {
type: yesno
sql: (SELECT h.page.pagePath FROM UNNEST(${ga_sessions.hits}) h
WHERE h.page.pagePath = "/asearch.html" LIMIT 1) IS NOT NULL ;;
}
# dimension: company_goal_hit {
# type: yesno
# sql: (SELECT h.page.pagePath FROM UNNEST(${ga_sessions.hits}) h
# WHERE h.page.pagePath = "/company" LIMIT 1) IS NOT NULL ;;
# }
# dimension: team_goal_hit {
# type: yesno
# sql: (SELECT h.page.pagePath FROM UNNEST(${ga_sessions.hits}) h
# WHERE h.page.pagePath = "/team" LIMIT 1) IS NOT NULL ;;
# }
# dimension: home_page_goal {
# type: yesno
# sql: (SELECT h.page.pagePath FROM UNNEST(${ga_sessions.hits}) h
# WHERE h.page.pagePath = "/goal" LIMIT 1) IS NOT NULL ;;
# }
# dimension: about_page_goal {
# type: yesno
# sql: (SELECT h.page.pagePath FROM UNNEST(${ga_sessions.hits}) h
# WHERE h.page.pagePath = "/about" LIMIT 1) IS NOT NULL ;;
# }
# dimension: conversion_value {
# sql: 100 ;;
# }
# value of goal
# dimension: value_of_conversion {
# type: number
# hidden: yes
# sql: 100 ;;
# value_format_name: usd
# }
# # filter for goal completion to mark as converted
# measure: demo_goal_conversions {
# group_label: "Goals"
# type: count
# filters: {
# field: demo_goal_hit
# value: "Yes"
# }
# }
# measure: company_goal_conversions {
# group_label: "Goals"
# type: count
# filters: {
# field: company_goal_hit
# value: "Yes"
# }
# }
# define conversion rate
# measure: demo_goal_conversion_rate {
# description: "URL hits / Sessions"
# group_label: "Goals"
# type: number
# sql: 1.0 * (${demo_goal_conversions}/NULLIF(${ga_sessions.visits_total},0));;
# value_format_name: percent_2
# }
# measure: company_goal_conversion_rate {
# description: "URL hits / Sessions"
# group_label: "Goals"
# type: number
# sql: 1.0 * (${company_goal_conversions}/NULLIF(${ga_sessions.visits_total},0));;
# value_format_name: percent_2
# }
# measure: demo_goal_conversion_value {
# description: "URL Conversions * Value"
# group_label: "Goals"
# type: number
# sql: 1.0 * (${demo_goal_conversions}) * (${value_of_conversion});;
# value_format_name: usd
# }
# measure: company_goal_conversion_value {
# description: "URL Conversions * Value"
# group_label: "Goals"
# type: number
# sql: 1.0 * (${company_goal_conversions}) * (${value_of_conversion});;
# value_format_name: usd
# }
# TODO: you need to add all the goals here as well
# parameter: goal_selection {
# type: string
# suggestions: ["No Selection","Demo","Company"]
# allowed_value: {value: "No Selection"}
# allowed_value: {value: "Demo"}
# allowed_value: {value: "Company"}
# default_value: "'No Selection'"
# }
# measure: selected_goal_conversions {
# type: number
# sql: {% if goal_selection._parameter_value == "'Demo'" %}${demo_goal_conversions}
# {% elsif goal_selection._parameter_value == "'Company'" %}${company_goal_conversions}
# {% elsif goal_selection._parameter_value == "'No Selection'" %}NULL
# {% endif %} ;;
# label_from_parameter: goal_selection
# value_format_name: decimal_0
# }
# measure: selected_goal_conversion_rate {
# type: number
# sql: {% if goal_selection._parameter_value == "'Demo'" %}${demo_goal_conversion_rate}
# {% elsif goal_selection._parameter_value == "'Company'" %}${company_goal_conversion_rate}
# {% elsif goal_selection._parameter_value == "'No Selection'" %}NULL
# {% endif %} ;;
# label_from_parameter: goal_selection
# value_format_name: percent_2
# }
# measure: selected_goal_conversion_value {
# type: number
# sql: {% if goal_selection._parameter_value == "'Demo'" %}${demo_goal_conversion_value}
# {% elsif goal_selection._parameter_value == "'Company'" %}${company_goal_conversion_value}
# {% elsif goal_selection._parameter_value == "'No Selection'" %}NULL
# {% endif %} ;;
# label_from_parameter: goal_selection
# value_format_name: usd
# }
}