From 4926f7834bb9ad6375f2070063e180cda3f4113e Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:14:25 -0600 Subject: [PATCH 01/34] Create automate-metrics.yaml --- .github/workflows/automate-metrics.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/automate-metrics.yaml diff --git a/.github/workflows/automate-metrics.yaml b/.github/workflows/automate-metrics.yaml new file mode 100644 index 00000000..7f39bbff --- /dev/null +++ b/.github/workflows/automate-metrics.yaml @@ -0,0 +1,15 @@ +on: [push] + +jobs: + main: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - name: Install Flutter SDK + uses: mobiledevops/secret-to-file-action@v1 + with: + base64-encoded-secret: ${{ secrets.FILE_CONTENT }} + filename: "hello-world.sh" + is-executable: true + working-directory: "./a/b/c" + - run: ./a/b/c/hello-world.sh From 7b0acfab2da7719dc5dad0bf740182ca5582c584 Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:31:30 -0600 Subject: [PATCH 02/34] outline for automate-metrics.yaml --- .github/workflows/automate-metrics.yaml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/automate-metrics.yaml b/.github/workflows/automate-metrics.yaml index 7f39bbff..5ae853c5 100644 --- a/.github/workflows/automate-metrics.yaml +++ b/.github/workflows/automate-metrics.yaml @@ -1,4 +1,7 @@ -on: [push] +on: + schedule: + # Weekly Every Monday at 1PM UTC + - cron: '0 13 * * 1' jobs: main: @@ -8,8 +11,21 @@ jobs: - name: Install Flutter SDK uses: mobiledevops/secret-to-file-action@v1 with: - base64-encoded-secret: ${{ secrets.FILE_CONTENT }} - filename: "hello-world.sh" + base64-encoded-secret: ${{ secrets.GOOGLE_ANALYTICS_API_CREDENTIALS }} + filename: "credentials.json" is-executable: true working-directory: "./a/b/c" - - run: ./a/b/c/hello-world.sh + - run: export GOOGLE_APPLICATION_CREDENTIALS="credentials.json" + + - name: Create Virtual Environment + - run: + python3 -m venv analytics-api + source analytics-api/bin/activate + pip install google-analytics-data + + - name: Get Credentials + - run: credentials.py + pass in 3 secrets for foundations, cookbook, and portal + + - name: Update Site + # run an if check to only open a PR if metrics have changed by a certain margin? From b8511a20d895f7ed1cd87a29e80b2aa07370741b Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:33:57 -0600 Subject: [PATCH 03/34] Create get-metrics.py --- .github/workflows/get-metrics.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/get-metrics.py diff --git a/.github/workflows/get-metrics.py b/.github/workflows/get-metrics.py new file mode 100644 index 00000000..2c995648 --- /dev/null +++ b/.github/workflows/get-metrics.py @@ -0,0 +1,22 @@ +from google.analytics.data_v1beta import BetaAnalyticsDataClient +from google.analytics.data_v1beta.types import ( + DateRange, + Metric, + RunReportRequest, +) + +def run_total_users_report(property_id): + client = BetaAnalyticsDataClient() + + request = RunReportRequest( + property=f"properties/{property_id}", + dimensions=[], + metrics=[Metric(name="activeUsers")], + date_ranges=[DateRange(start_date="2020-03-31", end_date="today")], + ) + response = client.run_report(request) + + total_users = 0 + for row in response.rows: + total_users += int(row.metric_values[0].value) + return total_users From a9ed412df11376fd20a203b16c36c19f9b0953d7 Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:43:56 -0600 Subject: [PATCH 04/34] Update automate-metrics.yaml --- .github/workflows/automate-metrics.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/automate-metrics.yaml b/.github/workflows/automate-metrics.yaml index 5ae853c5..0609d520 100644 --- a/.github/workflows/automate-metrics.yaml +++ b/.github/workflows/automate-metrics.yaml @@ -1,4 +1,4 @@ -on: +ion: schedule: # Weekly Every Monday at 1PM UTC - cron: '0 13 * * 1' @@ -23,9 +23,13 @@ jobs: source analytics-api/bin/activate pip install google-analytics-data - - name: Get Credentials - - run: credentials.py - pass in 3 secrets for foundations, cookbook, and portal + - name: Get Metrics + - run: + python + import get-metrics + portal = get-metrics.run_total_users_report(${{ secrets.GA4_PORTAL_ID }}) + foundations = get-metrics.run_total_users_report(${{ secrets.GA4_FOUNDATIONS_ID }}) + cookbooks = get-metrics.run_total_users_report(${{ secrets.GA4_COOKBOOKS_ID }}) - name: Update Site # run an if check to only open a PR if metrics have changed by a certain margin? From 37cd664d45124b6b1c372a9b664daa283d4c2aed Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:48:13 -0600 Subject: [PATCH 05/34] Update automate-metrics.yaml --- .github/workflows/automate-metrics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/automate-metrics.yaml b/.github/workflows/automate-metrics.yaml index 0609d520..bee334af 100644 --- a/.github/workflows/automate-metrics.yaml +++ b/.github/workflows/automate-metrics.yaml @@ -14,7 +14,7 @@ jobs: base64-encoded-secret: ${{ secrets.GOOGLE_ANALYTICS_API_CREDENTIALS }} filename: "credentials.json" is-executable: true - working-directory: "./a/b/c" + working-directory: "." - run: export GOOGLE_APPLICATION_CREDENTIALS="credentials.json" - name: Create Virtual Environment From aa0463b77ee1606101a8ccbbaa74ad16aadc9bc0 Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:01:43 -0600 Subject: [PATCH 06/34] Update footer-menu.html with metrics --- portal/_templates/footer-menu.html | 1 + 1 file changed, 1 insertion(+) diff --git a/portal/_templates/footer-menu.html b/portal/_templates/footer-menu.html index 3a17455b..73477ed8 100644 --- a/portal/_templates/footer-menu.html +++ b/portal/_templates/footer-menu.html @@ -8,6 +8,7 @@