Skip to content

Commit d943aca

Browse files
authored
fix: use up-to-date column names for formatting call in analytics reports (#4421) (#4422)
1 parent 06078a9 commit d943aca

File tree

4 files changed

+254
-72
lines changed

4 files changed

+254
-72
lines changed

analytics/anvil-catalog-sheets/generate_sheets_report.ipynb

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 5,
66
"metadata": {},
7-
"outputs": [],
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"env: ANVIL_ANALYTICS_REPORTING_CLIENT_SECRET_PATH=../../../do_not_commit_ga4_credentials.json\n"
13+
]
14+
}
15+
],
816
"source": [
917
"# Update this line to the path of your ga4 credentials. Make sure these are never stored in a version controlled folder.\n",
1018
"%env ANVIL_ANALYTICS_REPORTING_CLIENT_SECRET_PATH=../../../do_not_commit_ga4_credentials.json"
1119
]
1220
},
1321
{
1422
"cell_type": "code",
15-
"execution_count": null,
23+
"execution_count": 6,
1624
"metadata": {},
1725
"outputs": [],
1826
"source": [
1927
"from analytics import sheets_api as sheets\n",
2028
"from analytics import sheets_elements as elements\n",
29+
"from analytics import entities as e\n",
2130
"from analytics import api as ga\n",
2231
"import pandas as pd\n",
2332
"from constants import *\n",
@@ -26,9 +35,17 @@
2635
},
2736
{
2837
"cell_type": "code",
29-
"execution_count": null,
38+
"execution_count": 7,
3039
"metadata": {},
31-
"outputs": [],
40+
"outputs": [
41+
{
42+
"name": "stdout",
43+
"output_type": "stream",
44+
"text": [
45+
"Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=274560362763-p5netdrssq6r02lcfan6s157m6d65rqe.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8082%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly&state=cvpeqoNGBve6K3fVhpWzKJZ2IBswWk&access_type=offline\n"
46+
]
47+
}
48+
],
3249
"source": [
3350
"ga_authentication, drive_authentication, sheets_authentication = ga.authenticate(\n",
3451
" SECRET_NAME,\n",
@@ -59,7 +76,7 @@
5976
},
6077
{
6178
"cell_type": "code",
62-
"execution_count": null,
79+
"execution_count": 8,
6380
"metadata": {},
6481
"outputs": [],
6582
"source": [
@@ -70,9 +87,52 @@
7087
},
7188
{
7289
"cell_type": "code",
73-
"execution_count": null,
90+
"execution_count": 9,
7491
"metadata": {},
75-
"outputs": [],
92+
"outputs": [
93+
{
94+
"data": {
95+
"text/plain": [
96+
"{'spreadsheetId': '1e-m11cXlbdbYwGpdu_InyYQkTiWR2KkYigmvtN2qKGM',\n",
97+
" 'replies': [{'addChart': {'chart': {'chartId': 929691188,\n",
98+
" 'spec': {'title': 'Pageviews and Users Over Time',\n",
99+
" 'basicChart': {'chartType': 'LINE',\n",
100+
" 'axis': [{'position': 'BOTTOM_AXIS', 'viewWindowOptions': {}},\n",
101+
" {'position': 'LEFT_AXIS', 'viewWindowOptions': {}}],\n",
102+
" 'domains': [{'domain': {'sourceRange': {'sources': [{'sheetId': 726663797,\n",
103+
" 'startRowIndex': 0,\n",
104+
" 'endRowIndex': 48,\n",
105+
" 'startColumnIndex': 0,\n",
106+
" 'endColumnIndex': 1}]}}}],\n",
107+
" 'series': [{'series': {'sourceRange': {'sources': [{'sheetId': 726663797,\n",
108+
" 'startRowIndex': 0,\n",
109+
" 'endRowIndex': 48,\n",
110+
" 'startColumnIndex': 1,\n",
111+
" 'endColumnIndex': 2}]}},\n",
112+
" 'targetAxis': 'LEFT_AXIS'},\n",
113+
" {'series': {'sourceRange': {'sources': [{'sheetId': 726663797,\n",
114+
" 'startRowIndex': 0,\n",
115+
" 'endRowIndex': 48,\n",
116+
" 'startColumnIndex': 2,\n",
117+
" 'endColumnIndex': 3}]}},\n",
118+
" 'targetAxis': 'LEFT_AXIS'}],\n",
119+
" 'headerCount': 1},\n",
120+
" 'hiddenDimensionStrategy': 'SKIP_HIDDEN_ROWS_AND_COLUMNS',\n",
121+
" 'titleTextFormat': {'fontFamily': 'Roboto'},\n",
122+
" 'fontName': 'Roboto'},\n",
123+
" 'position': {'overlayPosition': {'anchorCell': {'sheetId': 726663797,\n",
124+
" 'columnIndex': 5},\n",
125+
" 'offsetXPixels': 75,\n",
126+
" 'offsetYPixels': 75,\n",
127+
" 'widthPixels': 600,\n",
128+
" 'heightPixels': 371}}}}}]}"
129+
]
130+
},
131+
"execution_count": 9,
132+
"metadata": {},
133+
"output_type": "execute_result"
134+
}
135+
],
76136
"source": [
77137
"dict_spreadsheet = {\n",
78138
" \"Monthly Traffic Summary\": df_monthly_pageviews,\n",
@@ -91,17 +151,17 @@
91151
" sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE,\n",
92152
" column_formatting_options={\n",
93153
" \"Monthly Traffic Summary\": {\n",
94-
" \"Month\": sheets.COLUMN_FORMAT_OPTIONS.YEAR_MONTH_DATE,\n",
95-
" \"Users Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
96-
" \"Total Pageviews Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
154+
" e.DIMENSION_YEAR_MONTH[\"alias\"]: sheets.COLUMN_FORMAT_OPTIONS.YEAR_MONTH_DATE,\n",
155+
" e.METRIC_ACTIVE_USERS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
156+
" e.METRIC_PAGE_VIEWS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
97157
" },\n",
98158
" \"Outbound Links\": {\n",
99-
" \"Total Clicks Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
100-
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
159+
" e.SYNTHETIC_METRIC_CLICKS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
160+
" e.METRIC_TOTAL_USERS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
101161
" },\n",
102162
" \"Pageviews\": {\n",
103-
" \"Total Views Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
104-
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
163+
" e.METRIC_PAGE_VIEWS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
164+
" e.METRIC_TOTAL_USERS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
105165
" },\n",
106166
"\n",
107167
" },\n",
@@ -159,7 +219,7 @@
159219
"name": "python",
160220
"nbconvert_exporter": "python",
161221
"pygments_lexer": "ipython3",
162-
"version": "3.12.8"
222+
"version": "3.12.4"
163223
}
164224
},
165225
"nbformat": 4,

analytics/anvil-explorer-sheets/generate_sheets_report.ipynb

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 3,
66
"metadata": {},
77
"outputs": [],
88
"source": [
99
"import analytics.api as ga\n",
1010
"import analytics.sheets_api as sheets\n",
1111
"import analytics.sheets_elements as elements\n",
12+
"import analytics.entities as e\n",
1213
"import pandas as pd\n",
1314
"import gspread\n",
1415
"from constants import *"
1516
]
1617
},
1718
{
1819
"cell_type": "code",
19-
"execution_count": 2,
20+
"execution_count": 4,
2021
"metadata": {},
2122
"outputs": [
2223
{
@@ -33,14 +34,14 @@
3334
},
3435
{
3536
"cell_type": "code",
36-
"execution_count": 3,
37+
"execution_count": 5,
3738
"metadata": {},
3839
"outputs": [
3940
{
4041
"name": "stdout",
4142
"output_type": "stream",
4243
"text": [
43-
"Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=425030666072-vun85q7nt3038skng8gs0f03juh97e17.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8082%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly&state=o8oUzUca8ESjd1GImvQPjxAcKhIkdb&access_type=offline\n"
44+
"Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=274560362763-p5netdrssq6r02lcfan6s157m6d65rqe.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8082%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets&state=3TOrvrS8EuGJvNWqEnjqNIlknGfZW7&access_type=offline\n"
4445
]
4546
}
4647
],
@@ -75,7 +76,7 @@
7576
},
7677
{
7778
"cell_type": "code",
78-
"execution_count": 4,
79+
"execution_count": 6,
7980
"metadata": {},
8081
"outputs": [],
8182
"source": [
@@ -86,48 +87,48 @@
8687
},
8788
{
8889
"cell_type": "code",
89-
"execution_count": 5,
90+
"execution_count": 7,
9091
"metadata": {},
9192
"outputs": [
9293
{
9394
"data": {
9495
"text/plain": [
95-
"{'spreadsheetId': '1Wm8jbfdBKu7Gd0ld40r8AwT4ffPg6xP4nV-jdY1FsE4',\n",
96-
" 'replies': [{'addChart': {'chart': {'chartId': 918233154,\n",
96+
"{'spreadsheetId': '1ueSQdU9pTa1qPptkNc4vk4xoHuJgP6gNcQ7exRxN9y0',\n",
97+
" 'replies': [{'addChart': {'chart': {'chartId': 113619751,\n",
9798
" 'spec': {'title': 'Pageviews and Users Over Time',\n",
9899
" 'basicChart': {'chartType': 'LINE',\n",
99100
" 'axis': [{'position': 'BOTTOM_AXIS', 'viewWindowOptions': {}},\n",
100101
" {'position': 'LEFT_AXIS', 'viewWindowOptions': {}}],\n",
101-
" 'domains': [{'domain': {'sourceRange': {'sources': [{'sheetId': 1792760679,\n",
102+
" 'domains': [{'domain': {'sourceRange': {'sources': [{'sheetId': 388329788,\n",
102103
" 'startRowIndex': 0,\n",
103-
" 'endRowIndex': 12,\n",
104+
" 'endRowIndex': 13,\n",
104105
" 'startColumnIndex': 0,\n",
105106
" 'endColumnIndex': 1}]}}}],\n",
106-
" 'series': [{'series': {'sourceRange': {'sources': [{'sheetId': 1792760679,\n",
107+
" 'series': [{'series': {'sourceRange': {'sources': [{'sheetId': 388329788,\n",
107108
" 'startRowIndex': 0,\n",
108-
" 'endRowIndex': 12,\n",
109+
" 'endRowIndex': 13,\n",
109110
" 'startColumnIndex': 1,\n",
110111
" 'endColumnIndex': 2}]}},\n",
111112
" 'targetAxis': 'LEFT_AXIS'},\n",
112-
" {'series': {'sourceRange': {'sources': [{'sheetId': 1792760679,\n",
113+
" {'series': {'sourceRange': {'sources': [{'sheetId': 388329788,\n",
113114
" 'startRowIndex': 0,\n",
114-
" 'endRowIndex': 12,\n",
115+
" 'endRowIndex': 13,\n",
115116
" 'startColumnIndex': 2,\n",
116117
" 'endColumnIndex': 3}]}},\n",
117118
" 'targetAxis': 'LEFT_AXIS'}],\n",
118119
" 'headerCount': 1},\n",
119120
" 'hiddenDimensionStrategy': 'SKIP_HIDDEN_ROWS_AND_COLUMNS',\n",
120121
" 'titleTextFormat': {'fontFamily': 'Roboto'},\n",
121122
" 'fontName': 'Roboto'},\n",
122-
" 'position': {'overlayPosition': {'anchorCell': {'sheetId': 1792760679,\n",
123+
" 'position': {'overlayPosition': {'anchorCell': {'sheetId': 388329788,\n",
123124
" 'columnIndex': 5},\n",
124125
" 'offsetXPixels': 75,\n",
125126
" 'offsetYPixels': 25,\n",
126127
" 'widthPixels': 600,\n",
127128
" 'heightPixels': 371}}}}}]}"
128129
]
129130
},
130-
"execution_count": 5,
131+
"execution_count": 7,
131132
"metadata": {},
132133
"output_type": "execute_result"
133134
}
@@ -150,17 +151,17 @@
150151
" sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE,\n",
151152
" column_formatting_options={\n",
152153
" \"Explorer Summary\": {\n",
153-
" \"Month\": sheets.COLUMN_FORMAT_OPTIONS.YEAR_MONTH_DATE,\n",
154-
" \"Users Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
155-
" \"Total Pageviews Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
154+
" e.DIMENSION_YEAR_MONTH[\"alias\"]: sheets.COLUMN_FORMAT_OPTIONS.YEAR_MONTH_DATE,\n",
155+
" e.METRIC_ACTIVE_USERS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
156+
" e.METRIC_PAGE_VIEWS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
156157
" },\n",
157158
" \"Outbound Links\": {\n",
158-
" \"Total Clicks Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
159-
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
159+
" e.SYNTHETIC_METRIC_CLICKS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
160+
" e.METRIC_TOTAL_USERS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
160161
" },\n",
161162
" \"Pageviews\": {\n",
162-
" \"Total Views Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
163-
" \"Total Users Percent Change\": sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
163+
" e.METRIC_PAGE_VIEWS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
164+
" e.METRIC_TOTAL_USERS[\"change_alias\"]: sheets.COLUMN_FORMAT_OPTIONS.PERCENT_COLORED,\n",
164165
" },\n",
165166
"\n",
166167
" },\n",
@@ -218,7 +219,7 @@
218219
"name": "python",
219220
"nbconvert_exporter": "python",
220221
"pygments_lexer": "ipython3",
221-
"version": "3.12.8"
222+
"version": "3.12.4"
222223
}
223224
},
224225
"nbformat": 4,

0 commit comments

Comments
 (0)