diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aadf59..1601e31 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/). +## [1.10.1] - 2023-06-12 +### 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) diff --git a/Dockerfile b/Dockerfile index f323fdf..8ee5e02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,15 +10,20 @@ 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 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 # ---------------------------------------------------------------------- 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/conf.py b/docs/source/conf.py index d28e67a..25a3452 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -33,7 +33,7 @@ # The short X.Y version version = '1.10' # The full version, including alpha/beta/rc tags -release = '1.10.0' +release = '1.10.1' # -- General configuration --------------------------------------------------- diff --git a/docs/source/insert_ga_to_header.py b/docs/source/insert_ga_to_header.py new file mode 100644 index 0000000..94e7f4f --- /dev/null +++ b/docs/source/insert_ga_to_header.py @@ -0,0 +1,46 @@ +import os +from bs4 import BeautifulSoup + +# Directory containing the built HTML files +build_dir = "docs/build" + +# 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.") diff --git a/recipes/meta.yaml b/recipes/meta.yaml index dcc8574..0a7953c 100644 --- a/recipes/meta.yaml +++ b/recipes/meta.yaml @@ -1,5 +1,5 @@ {% set name = "pyincore-viz" %} -{% set version = "1.10.0" %} +{% set version = "1.10.1" %} package: name: {{ name|lower }} diff --git a/setup.py b/setup.py index 4a613b7..2722b3e 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ from setuptools import setup, find_packages # version number of pyincore -version = '1.10.0' +version = '1.10.1' with open("README.rst", encoding="utf-8") as f: readme = f.read()