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
This commit is contained in:
Eric Holscher 2018-12-04 15:08:29 -05:00 committed by Aaron Carlisle
parent 5b7d202a11
commit 7e4592f95c
2 changed files with 18 additions and 1 deletions

View File

@ -19,7 +19,7 @@ file of this repository, and can be defined in your project's ``conf.py`` via
html_theme_options = { html_theme_options = {
'canonical_url': '', 'canonical_url': '',
'analytics_id': '', 'analytics_id': 'UA-XXXXXXX-1', # Provided by Google in your dashboard
'logo_only': False, 'logo_only': False,
'display_version': True, 'display_version': True,
'prev_next_buttons_location': 'bottom', 'prev_next_buttons_location': 'bottom',

View File

@ -221,6 +221,23 @@
}); });
</script> </script>
{# Do not conflict with RTD insertion of analytics script #}
{% if not READTHEDOCS %}
{% if theme_analytics_id %}
<!-- Theme Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '{{ theme_analytics_id }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
{% endif %}
{%- block footer %} {% endblock %} {%- block footer %} {% endblock %}
</body> </body>