|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": null, |
| 5 | + "execution_count": 5, |
6 | 6 | "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 | + ], |
8 | 16 | "source": [ |
9 | 17 | "# Update this line to the path of your ga4 credentials. Make sure these are never stored in a version controlled folder.\n", |
10 | 18 | "%env ANVIL_ANALYTICS_REPORTING_CLIENT_SECRET_PATH=../../../do_not_commit_ga4_credentials.json" |
11 | 19 | ] |
12 | 20 | }, |
13 | 21 | { |
14 | 22 | "cell_type": "code", |
15 | | - "execution_count": null, |
| 23 | + "execution_count": 6, |
16 | 24 | "metadata": {}, |
17 | 25 | "outputs": [], |
18 | 26 | "source": [ |
19 | 27 | "from analytics import sheets_api as sheets\n", |
20 | 28 | "from analytics import sheets_elements as elements\n", |
| 29 | + "from analytics import entities as e\n", |
21 | 30 | "from analytics import api as ga\n", |
22 | 31 | "import pandas as pd\n", |
23 | 32 | "from constants import *\n", |
|
26 | 35 | }, |
27 | 36 | { |
28 | 37 | "cell_type": "code", |
29 | | - "execution_count": null, |
| 38 | + "execution_count": 7, |
30 | 39 | "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 | + ], |
32 | 49 | "source": [ |
33 | 50 | "ga_authentication, drive_authentication, sheets_authentication = ga.authenticate(\n", |
34 | 51 | " SECRET_NAME,\n", |
|
59 | 76 | }, |
60 | 77 | { |
61 | 78 | "cell_type": "code", |
62 | | - "execution_count": null, |
| 79 | + "execution_count": 8, |
63 | 80 | "metadata": {}, |
64 | 81 | "outputs": [], |
65 | 82 | "source": [ |
|
70 | 87 | }, |
71 | 88 | { |
72 | 89 | "cell_type": "code", |
73 | | - "execution_count": null, |
| 90 | + "execution_count": 9, |
74 | 91 | "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 | + ], |
76 | 136 | "source": [ |
77 | 137 | "dict_spreadsheet = {\n", |
78 | 138 | " \"Monthly Traffic Summary\": df_monthly_pageviews,\n", |
|
91 | 151 | " sheets.FILE_OVERRIDE_BEHAVIORS.OVERRIDE_IF_IN_SAME_PLACE,\n", |
92 | 152 | " column_formatting_options={\n", |
93 | 153 | " \"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", |
97 | 157 | " },\n", |
98 | 158 | " \"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", |
101 | 161 | " },\n", |
102 | 162 | " \"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", |
105 | 165 | " },\n", |
106 | 166 | "\n", |
107 | 167 | " },\n", |
|
159 | 219 | "name": "python", |
160 | 220 | "nbconvert_exporter": "python", |
161 | 221 | "pygments_lexer": "ipython3", |
162 | | - "version": "3.12.8" |
| 222 | + "version": "3.12.4" |
163 | 223 | } |
164 | 224 | }, |
165 | 225 | "nbformat": 4, |
|
0 commit comments