diff --git a/docs/index.rst b/docs/index.rst index 1e5f11fc..132101bb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,7 @@ The core changes between this theme and the `pydata-sphinx-theme` are: * Add links to the header bar which are specified as theme config variables, with defaults for sunpy.org. * Add a center element to the footer bar. * Restyled the theme for SunPy colors. +* Added optional support for analytics though `goatcounter.com `__ which defaults to on for sunpy.org domains. .. grid:: 1 2 2 2 :gutter: 3 diff --git a/src/sunpy_sphinx_theme/__init__.py b/src/sunpy_sphinx_theme/__init__.py index 439b2e61..4fd2c098 100644 --- a/src/sunpy_sphinx_theme/__init__.py +++ b/src/sunpy_sphinx_theme/__init__.py @@ -149,7 +149,7 @@ def setup(app: Sphinx): root_domain = theme_options.get("sst_site_root", "https://sunpy.org") sunpy_goat_url = "https://sunpy.goatcounter.com/count" default_goat_url = sunpy_goat_url if root_domain == "https://sunpy.org" else None - if theme_options.get("goatcounter_analytics_url", default_goat_url): + if primary_goat_url := theme_options.get("goatcounter_analytics_url", default_goat_url): root_domain = root_domain.removeprefix("https://").removeprefix("http://") default_endpoint = theme_options.get("goatcounter_non_domain_endpoint", False) if default_endpoint is False: @@ -159,7 +159,7 @@ def setup(app: Sphinx): body=f""" var endpoint = '{default_endpoint}'; if (location.hostname.endsWith('{root_domain}')) {{ - endpoint = '{theme_options["goatcounter_analytics_url"]}' + endpoint = '{primary_goat_url}' }} window.goatcounter = {{ diff --git a/src/sunpy_sphinx_theme/theme/sunpy/theme.conf b/src/sunpy_sphinx_theme/theme/sunpy/theme.conf index 37c86e06..7fe0ec38 100644 --- a/src/sunpy_sphinx_theme/theme/sunpy/theme.conf +++ b/src/sunpy_sphinx_theme/theme/sunpy/theme.conf @@ -19,7 +19,7 @@ sst_is_root = False sst_project_name = SunPy # Enable sending stats to goat counter # Set this URL to something like https://MYCODE.goatcounter.com/count -goatcounter_analytics_url = https://sunpy.goatcounter.com/count +goatcounter_analytics_url = # If you only want to count visits to sst_site_root or subdomains there of then set this to False # otherwise set it to another (or the same) goat counter endpoint goatcounter_non_domain_endpoint = False