From 7e4592f95c0a1c01a420e6bb3e2bd3f043fd4d11 Mon Sep 17 00:00:00 2001 From: Eric Holscher <25510+ericholscher@users.noreply.github.com> Date: Tue, 4 Dec 2018 15:08:29 -0500 Subject: [PATCH] Add support for Google Analytics to theme. (#411) * Add support for Google Analytics to theme. This setting has actually existed in the default config since the original version, but doesn't currently work. This fixes that and supports GA if it's set. * Add docs around analytics_id * Do not conflict with RTD insertion of analytics script * Remove dupliate analytics_id * Add analytics_id to the configuration in its new place --- docs/configuring.rst | 2 +- sphinx_rtd_theme/layout.html | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/configuring.rst b/docs/configuring.rst index 67c91bce..94beb09d 100644 --- a/docs/configuring.rst +++ b/docs/configuring.rst @@ -19,7 +19,7 @@ file of this repository, and can be defined in your project's ``conf.py`` via html_theme_options = { 'canonical_url': '', - 'analytics_id': '', + 'analytics_id': 'UA-XXXXXXX-1', # Provided by Google in your dashboard 'logo_only': False, 'display_version': True, 'prev_next_buttons_location': 'bottom', diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index 7d9a25df..dccfac1d 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -221,6 +221,23 @@ }); + {# Do not conflict with RTD insertion of analytics script #} + {% if not READTHEDOCS %} + {% if theme_analytics_id %} + + + + {% endif %} + {% endif %} + {%- block footer %} {% endblock %}