From b6f0912a220fe427d481e9fdb2042629bdc8f7bd Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 23 Apr 2024 16:41:42 -0500 Subject: [PATCH 01/21] Added Google Analytics to documentation --- .github/workflows/doc.yaml | 4 +++ Dockerfile | 7 +++++ docs/source/insert_ga_to_header.py | 50 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 docs/source/insert_ga_to_header.py diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 320b298..c6cb106 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -52,13 +52,17 @@ jobs: done echo "VERSION=${version}" >> $GITHUB_ENV echo "TAGS=${tags}" >> $GITHUB_ENV + GA_KEY="${{ secrets.GA_KEY }}" elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV + GA_KEY="${{ secrets.GA_KEY }}" else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV + GA_KEY="${{ secrets.GA_KEY }}" fi + echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV # build image - name: Build image diff --git a/Dockerfile b/Dockerfile index f323fdf..9193bb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,10 @@ FROM mambaorg/micromamba AS builder USER root +# Set the GA_KEY environment variable +ARG GA_KEY +ENV GA_KEY=$GA_KEY + # install packages WORKDIR /src COPY environment.yml ./ @@ -16,6 +20,9 @@ RUN micromamba install -y -n base -c conda-forge -c in-core \ COPY . ./ RUN sphinx-build -v -b html docs/source docs/build +# Run the insert_ga_to_header.py script to insert Google Analytics code +RUN python /src/docs/source/insert_ga_to_header.py + # ---------------------------------------------------------------------- # Building actual container # ---------------------------------------------------------------------- diff --git a/docs/source/insert_ga_to_header.py b/docs/source/insert_ga_to_header.py new file mode 100644 index 0000000..3dc0e41 --- /dev/null +++ b/docs/source/insert_ga_to_header.py @@ -0,0 +1,50 @@ +import os +from bs4 import BeautifulSoup + +# Directory containing the built HTML files +build_dir = "docs/build" + +# Google Analytics tracking ID +ga_key = os.environ.get("GA_KEY") + +# Ensure GA_KEY is provided +if not ga_key: + raise ValueError("Google Analytics tracking ID (GA_KEY) not provided.") + +# Google Analytics code snippet to insert into the HTML files +ga_code = f""" + + + +""" + +# Loop through each HTML file in the build directory +for filename in os.listdir(build_dir): + if filename.endswith(".html"): + filepath = os.path.join(build_dir, filename) + print(f"Processing file: {filepath}") + + # Read the content of the HTML file + with open(filepath, "r", encoding="utf-8") as file: + html_content = file.read() + + # Parse HTML content using BeautifulSoup + soup = BeautifulSoup(html_content, "html.parser") + + # Find the tag and insert the Google Analytics code before it + head_tag = soup.find("head") + if head_tag: + print(f"Found tag in {filename}:") + print("Inserting Google Analytics code...") + head_tag.insert(0, BeautifulSoup(ga_code, "html.parser")) + + # Write the modified HTML content back to the file + with open(filepath, "w", encoding="utf-8") as file: + file.write(str(soup)) + +print("Google Analytics code insertion completed.") From ff5f0150b0cb9b954de9964f8785053d0042aa2c Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 23 Apr 2024 16:49:52 -0500 Subject: [PATCH 02/21] install bs4 in docker --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 9193bb9..55ebccb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ WORKDIR /src COPY environment.yml ./ ENV PATH "$MAMBA_ROOT_PREFIX/bin:$PATH" RUN micromamba install -y -n base -c conda-forge -c in-core \ + beautifulsoup4 \ sphinx=6.2.1 sphinx_rtd_theme -f environment.yml # copy code and generate documentation From f5c9d4e295c5fca3c2ff9d47100d81ddb961e208 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 23 Apr 2024 16:54:02 -0500 Subject: [PATCH 03/21] added build arg for docker in github action --- .github/workflows/doc.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index c6cb106..8a489e9 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -70,6 +70,8 @@ jobs: with: name: incore/doc/pyincore-viz no_push: true + build_args: | + --build-arg GA_KEY="${{ secrets.GA_KEY }}" # this will publish to NCSA - name: Publish to NCSA Hub From d540b15cfb2717b2879f0985d93d7faa00f26fc8 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 23 Apr 2024 17:03:54 -0500 Subject: [PATCH 04/21] modified GA KEY in github action --- .github/workflows/doc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 8a489e9..5feacdb 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -71,7 +71,7 @@ jobs: name: incore/doc/pyincore-viz no_push: true build_args: | - --build-arg GA_KEY="${{ secrets.GA_KEY }}" + --build-arg GA_KEY=${{ env.GA_KEY }} # this will publish to NCSA - name: Publish to NCSA Hub From fc86d1562ae3890dbd1449ce02cd76dfc91ceea5 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 23 Apr 2024 17:06:58 -0500 Subject: [PATCH 05/21] added GA KEY log --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 55ebccb..45db0d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,9 @@ USER root ARG GA_KEY ENV GA_KEY=$GA_KEY +# Print out the value of GA_KEY +RUN echo "GA_KEY value is: $GA_KEY" + # install packages WORKDIR /src COPY environment.yml ./ From a1535aed3e8e35df2bb5ce0e9c6db777c368f81f Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 08:54:33 -0500 Subject: [PATCH 06/21] chnage build arg method in github action --- .github/workflows/doc.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 5feacdb..f1bb432 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -70,8 +70,8 @@ jobs: with: name: incore/doc/pyincore-viz no_push: true - build_args: | - --build-arg GA_KEY=${{ env.GA_KEY }} + build-args: | + GA_KEY: ${{ env.GA_KEY }} # this will publish to NCSA - name: Publish to NCSA Hub From ccd2a69bffac4c58d0855c98927073d0db4d568e Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 09:50:28 -0500 Subject: [PATCH 07/21] modified bld args --- .github/workflows/doc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index f1bb432..e9647cf 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -71,7 +71,7 @@ jobs: name: incore/doc/pyincore-viz no_push: true build-args: | - GA_KEY: ${{ env.GA_KEY }} + GA_KEY=${{ env.GA_KEY }} # this will publish to NCSA - name: Publish to NCSA Hub From 530c5b3e0bf7190b04e74ab39f8154b92132df79 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 10:45:52 -0500 Subject: [PATCH 08/21] check if GA_KEY is correct --- .github/workflows/doc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index e9647cf..928c8e0 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -63,6 +63,7 @@ jobs: GA_KEY="${{ secrets.GA_KEY }}" fi echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV + echo "GA_KEY is: ${{ env.GA_KEY }}" # build image - name: Build image From ed51300a41abe4360921f1daef9163eeadfd7a49 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 10:57:45 -0500 Subject: [PATCH 09/21] print out GA_KEY --- .github/workflows/doc.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 928c8e0..61f72b7 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -64,6 +64,8 @@ jobs: fi echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV echo "GA_KEY is: ${{ env.GA_KEY }}" + echo "GA_KEY in secret is: ${{ secrets.GA_KEY }}" + echo "GA_KEY_DEV in secret is: ${{ secrets.GA_KEY_DEV }}" # build image - name: Build image From 4b11955a7a0ecb151f4626948c2092c0cb57cd5a Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 11:02:22 -0500 Subject: [PATCH 10/21] Fixed GA_KEY in github action --- .github/workflows/doc.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 61f72b7..08264e0 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -52,7 +52,7 @@ jobs: done echo "VERSION=${version}" >> $GITHUB_ENV echo "TAGS=${tags}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY }}" + GA_KEY="${{ secrets.GA_KEY_DEV }}" elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV @@ -60,12 +60,9 @@ jobs: else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY }}" + GA_KEY="${{ secrets.GA_KEY_DEV }}" fi echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV - echo "GA_KEY is: ${{ env.GA_KEY }}" - echo "GA_KEY in secret is: ${{ secrets.GA_KEY }}" - echo "GA_KEY_DEV in secret is: ${{ secrets.GA_KEY_DEV }}" # build image - name: Build image From 964ed92a3f2fb8170feb7e19590923e8e1e6d7c5 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 11:05:28 -0500 Subject: [PATCH 11/21] Fixed GA_KEY in github action --- .github/workflows/doc.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 08264e0..529a1aa 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -52,11 +52,11 @@ jobs: done echo "VERSION=${version}" >> $GITHUB_ENV echo "TAGS=${tags}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY_DEV }}" + GA_KEY="${{ secrets.GA_KEY }}" elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY }}" + GA_KEY="${{ secrets.GA_KEY_DEV }}" else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV From 7460bf7414d2168a9edb01c127420f7176b38437 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 11:06:32 -0500 Subject: [PATCH 12/21] updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aadf59..4d642a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] +### Added +- Google Analytics to the documentation site [#164](https://github.com/IN-CORE/pyincore-viz/issues/164) + ## [1.10.0] - 2023-02-07 ### Added - Plot method for local hazard [#153](https://github.com/IN-CORE/pyincore-viz/issues/153) From 9e4e818cfcf9738fc5c1ac4df2dacb9ee731d21a Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 11:10:57 -0500 Subject: [PATCH 13/21] added echo statement --- .github/workflows/doc.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 529a1aa..7a5ba91 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -63,6 +63,11 @@ jobs: GA_KEY="${{ secrets.GA_KEY_DEV }}" fi echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV + echo "GA_KEY is: $GA_KEY" + echo "GA_KEY_DEV in secret is: ${{ secrets.GA_KEY_DEV }}" + echo "GA_KEY in secret is: ${{ secrets.GA_KEY }}" + echo "GA_KEY in process is: $GA_KEY" + echo "GA_KEY in env is: ${{ env.GA_KEY }}" # build image - name: Build image From de3d3fab85aca976eb99d3deae84590a56db1800 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 11:15:19 -0500 Subject: [PATCH 14/21] added echo statement --- .github/workflows/doc.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 7a5ba91..efa139a 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -69,6 +69,11 @@ jobs: echo "GA_KEY in process is: $GA_KEY" echo "GA_KEY in env is: ${{ env.GA_KEY }}" + # print out env.GA_KEY + - name: Print out env.GA_KEY + run: | + echo "GA_KEY is: ${{ env.GA_KEY }}" + # build image - name: Build image uses: elgohr/Publish-Docker-Github-Action@3.04 From 1163b9412b29530289c471c2e9306f5a7668a410 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Wed, 24 Apr 2024 11:18:02 -0500 Subject: [PATCH 15/21] changed bld arg --- .github/workflows/doc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index efa139a..e3c1492 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -81,7 +81,7 @@ jobs: name: incore/doc/pyincore-viz no_push: true build-args: | - GA_KEY=${{ env.GA_KEY }} + GA_KEY:${{ env.GA_KEY }} # this will publish to NCSA - name: Publish to NCSA Hub From a706530be2a586c500ab4ce27f5ef46f5d56237d Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 7 May 2024 10:38:49 -0500 Subject: [PATCH 16/21] Modified build args --- .github/workflows/doc.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index e3c1492..f141066 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -77,11 +77,12 @@ jobs: # build image - name: Build image uses: elgohr/Publish-Docker-Github-Action@3.04 + env: + GA_KEY: ${{ env.GA_KEY }} with: name: incore/doc/pyincore-viz no_push: true - build-args: | - GA_KEY:${{ env.GA_KEY }} + buildargs: GA_KEY # this will publish to NCSA - name: Publish to NCSA Hub From 5e38046c21027be8f596d2b9ae3f921b15aaf189 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 7 May 2024 10:53:06 -0500 Subject: [PATCH 17/21] Added GA key to ci.yaml --- .github/workflows/ci.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ea0d3b3..f809f0d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,13 +49,16 @@ jobs: done echo "VERSION=${version}" >> $GITHUB_ENV echo "TAGS=${tags}" >> $GITHUB_ENV + GA_KEY="${{ secrets.GA_KEY }}" elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV + GA_KEY="${{ secrets.GA_KEY }}" else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV fi + echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV # build image - name: Build image @@ -65,13 +68,14 @@ jobs: VERSION: ${{ env.VERSION }} BUILDNUMBER: ${{ github.run_number }} GITSHA1: ${{ github.sha }} + GA_KEY: ${{ env.GA_KEY }} with: registry: hub.ncsa.illinois.edu name: incore/doc/pyincore-viz #username: ${{ secrets.HUB_USERNAME }} #password: ${{ secrets.HUB_PASSWORD }} tags: "${{ env.TAGS }}" - buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 + buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1,GA_KEY no_push: true # this will publish to NCSA From 3d5e6ffa405cc286abc4bdd597d1c2782a89428d Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 7 May 2024 10:59:39 -0500 Subject: [PATCH 18/21] add GA_KEY to env --- .github/workflows/ci.yaml | 2 +- .github/workflows/doc.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f809f0d..b8c1f7f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,7 +58,7 @@ jobs: echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV fi - echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV + echo "GA_KEY=$GA_KEY" >> $GITHUB_ENV # build image - name: Build image diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index f141066..473cbf8 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -62,7 +62,7 @@ jobs: echo "TAGS=${BRANCH}" >> $GITHUB_ENV GA_KEY="${{ secrets.GA_KEY_DEV }}" fi - echo "GA_KEY=${GA_KEY}" >> $GITHUB_ENV + echo "GA_KEY=$GA_KEY" >> $GITHUB_ENV echo "GA_KEY is: $GA_KEY" echo "GA_KEY_DEV in secret is: ${{ secrets.GA_KEY_DEV }}" echo "GA_KEY in secret is: ${{ secrets.GA_KEY }}" From 2a090911b5af15aeb0a194655ebc6c85fbcad0bc Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Tue, 7 May 2024 11:16:55 -0500 Subject: [PATCH 19/21] removed print outs --- .github/workflows/ci.yaml | 6 ++++-- .github/workflows/doc.yaml | 13 ++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b8c1f7f..909133d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -53,10 +53,11 @@ jobs: elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY }}" + GA_KEY="${{ secrets.GA_KEY_DEV }}" else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV + GA_KEY="${{ secrets.GA_KEY_DEV }}" fi echo "GA_KEY=$GA_KEY" >> $GITHUB_ENV @@ -88,10 +89,11 @@ jobs: VERSION: ${{ env.VERSION }} BUILDNUMBER: ${{ github.run_number }} GITSHA1: ${{ github.sha }} + GA_KEY: ${{ env.GA_KEY }} with: registry: hub.ncsa.illinois.edu name: incore/doc/pyincore-viz username: ${{ secrets.HUB_USERNAME }} password: ${{ secrets.HUB_PASSWORD }} tags: "${{ env.TAGS }}" - buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 \ No newline at end of file + buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1,GA_KEY \ No newline at end of file diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 473cbf8..a45b334 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -63,16 +63,6 @@ jobs: GA_KEY="${{ secrets.GA_KEY_DEV }}" fi echo "GA_KEY=$GA_KEY" >> $GITHUB_ENV - echo "GA_KEY is: $GA_KEY" - echo "GA_KEY_DEV in secret is: ${{ secrets.GA_KEY_DEV }}" - echo "GA_KEY in secret is: ${{ secrets.GA_KEY }}" - echo "GA_KEY in process is: $GA_KEY" - echo "GA_KEY in env is: ${{ env.GA_KEY }}" - - # print out env.GA_KEY - - name: Print out env.GA_KEY - run: | - echo "GA_KEY is: ${{ env.GA_KEY }}" # build image - name: Build image @@ -94,10 +84,11 @@ jobs: VERSION: ${{ env.VERSION }} BUILDNUMBER: ${{ github.run_number }} GITSHA1: ${{ github.sha }} + GA_KEY: ${{ env.GA_KEY }} with: registry: hub.ncsa.illinois.edu name: incore/doc/pyincore-viz username: ${{ secrets.HUB_USERNAME }} password: ${{ secrets.HUB_PASSWORD }} tags: "${{ env.TAGS }}" - buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 \ No newline at end of file + buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1,GA_KEY \ No newline at end of file From 02c4be7790b1edfa5331b12c74e966a9a9079600 Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Thu, 30 May 2024 14:03:49 -0500 Subject: [PATCH 20/21] revert github action --- .github/workflows/ci.yaml | 10 ++-------- .github/workflows/doc.yaml | 10 +--------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 909133d..ea0d3b3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,17 +49,13 @@ jobs: done echo "VERSION=${version}" >> $GITHUB_ENV echo "TAGS=${tags}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY }}" elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY_DEV }}" else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY_DEV }}" fi - echo "GA_KEY=$GA_KEY" >> $GITHUB_ENV # build image - name: Build image @@ -69,14 +65,13 @@ jobs: VERSION: ${{ env.VERSION }} BUILDNUMBER: ${{ github.run_number }} GITSHA1: ${{ github.sha }} - GA_KEY: ${{ env.GA_KEY }} with: registry: hub.ncsa.illinois.edu name: incore/doc/pyincore-viz #username: ${{ secrets.HUB_USERNAME }} #password: ${{ secrets.HUB_PASSWORD }} tags: "${{ env.TAGS }}" - buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1,GA_KEY + buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 no_push: true # this will publish to NCSA @@ -89,11 +84,10 @@ jobs: VERSION: ${{ env.VERSION }} BUILDNUMBER: ${{ github.run_number }} GITSHA1: ${{ github.sha }} - GA_KEY: ${{ env.GA_KEY }} with: registry: hub.ncsa.illinois.edu name: incore/doc/pyincore-viz username: ${{ secrets.HUB_USERNAME }} password: ${{ secrets.HUB_PASSWORD }} tags: "${{ env.TAGS }}" - buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1,GA_KEY \ No newline at end of file + buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 \ No newline at end of file diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index a45b334..320b298 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -52,27 +52,20 @@ jobs: done echo "VERSION=${version}" >> $GITHUB_ENV echo "TAGS=${tags}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY }}" elif [ "$BRANCH" == "develop" ]; then echo "VERSION=develop" >> $GITHUB_ENV echo "TAGS=develop" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY_DEV }}" else echo "VERSION=testing" >> $GITHUB_ENV echo "TAGS=${BRANCH}" >> $GITHUB_ENV - GA_KEY="${{ secrets.GA_KEY_DEV }}" fi - echo "GA_KEY=$GA_KEY" >> $GITHUB_ENV # build image - name: Build image uses: elgohr/Publish-Docker-Github-Action@3.04 - env: - GA_KEY: ${{ env.GA_KEY }} with: name: incore/doc/pyincore-viz no_push: true - buildargs: GA_KEY # this will publish to NCSA - name: Publish to NCSA Hub @@ -84,11 +77,10 @@ jobs: VERSION: ${{ env.VERSION }} BUILDNUMBER: ${{ github.run_number }} GITSHA1: ${{ github.sha }} - GA_KEY: ${{ env.GA_KEY }} with: registry: hub.ncsa.illinois.edu name: incore/doc/pyincore-viz username: ${{ secrets.HUB_USERNAME }} password: ${{ secrets.HUB_PASSWORD }} tags: "${{ env.TAGS }}" - buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1,GA_KEY \ No newline at end of file + buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 \ No newline at end of file From 9086ea35941c28c785c56ae721248e0e7f836c1b Mon Sep 17 00:00:00 2001 From: YONG WOOK KIM Date: Thu, 30 May 2024 14:08:54 -0500 Subject: [PATCH 21/21] modified Dockerfile --- Dockerfile | 8 +------- config/config.json | 3 +++ config/googleAnalytics.js | 31 ++++++++++++++++++++++++++++++ docs/source/insert_ga_to_header.py | 26 +++++++++++-------------- 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 config/config.json create mode 100644 config/googleAnalytics.js diff --git a/Dockerfile b/Dockerfile index 45db0d6..8ee5e02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,6 @@ FROM mambaorg/micromamba AS builder USER root -# Set the GA_KEY environment variable -ARG GA_KEY -ENV GA_KEY=$GA_KEY - -# Print out the value of GA_KEY -RUN echo "GA_KEY value is: $GA_KEY" - # install packages WORKDIR /src COPY environment.yml ./ @@ -33,3 +26,4 @@ RUN python /src/docs/source/insert_ga_to_header.py FROM nginx COPY --from=builder /src/docs/build/ /usr/share/nginx/html/doc/pyincore_viz/ +COPY config /usr/share/nginx/html/doc/pyincore_viz/config diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..279dd30 --- /dev/null +++ b/config/config.json @@ -0,0 +1,3 @@ +{ + "GA_KEY": "Test-Google-Analytics-Key-Replace-Me" +} \ No newline at end of file diff --git a/config/googleAnalytics.js b/config/googleAnalytics.js new file mode 100644 index 0000000..6e43a7e --- /dev/null +++ b/config/googleAnalytics.js @@ -0,0 +1,31 @@ +// analytics.js +(function() { + // Fetch the runtime configuration + fetch('config/config.json') + .then(response => { + if (!response.ok) { + throw new Error('Configuration file not found'); + } + return response.json(); + }) + .then(config => { + if (!config.GA_KEY) { + throw new Error('GA_KEY is missing in the configuration'); + } + + // Create the script tag for Google Tag Manager + const scriptTag = document.createElement('script'); + scriptTag.async = true; + scriptTag.src = `https://www.googletagmanager.com/gtag/js?id=${config.GA_KEY}`; + document.head.appendChild(scriptTag); + + // Initialize Google Analytics + window.dataLayer = window.dataLayer || []; + + function gtag() { dataLayer.push(arguments); } + + gtag('js', new Date()); + gtag('config', config.GA_KEY); + }) + .catch(error => console.warn('GA setup skipped:', error.message)); +})(); \ No newline at end of file diff --git a/docs/source/insert_ga_to_header.py b/docs/source/insert_ga_to_header.py index 3dc0e41..94e7f4f 100644 --- a/docs/source/insert_ga_to_header.py +++ b/docs/source/insert_ga_to_header.py @@ -4,23 +4,19 @@ # Directory containing the built HTML files build_dir = "docs/build" -# Google Analytics tracking ID -ga_key = os.environ.get("GA_KEY") - -# Ensure GA_KEY is provided -if not ga_key: - raise ValueError("Google Analytics tracking ID (GA_KEY) not provided.") - # Google Analytics code snippet to insert into the HTML files ga_code = f""" - - - + """ # Loop through each HTML file in the build directory