Make Google Analytics tracking optional.

Some OpenStack contributors have expressed concern about having Google
Analytics tracking codes embedded in all of the HTML documentation
generated by the use of this theme. In addition to these concerns, which
mostly focus on privacy, having the Google Analytics tracking code used
widely runs the risk of creating misleading analytics data.

This change adopts an approach used by the Alabaster theme, which
enables Google Analytics tracking to be optional. Tracking is now
controlled by the theme settings in conf.py using a new theme option,
'analytics_tracking_code'. If present, this causes the HTML to include
the analytics tracking, with the provided code being used. If not
present, the Google Analytics snippet is excluded from the
documentation.

To avoid breakage, this commit uses the current hard-coded Google
Analytics tracking code as the default value of the option, which
means that most users will not notice any change and may continue to be
accidentally opted in to Google Analytics tracking.

Change-Id: I156151c3f458931f13716b4a32087afe57483794
This commit is contained in:
Cory Benfield 2015-12-04 16:38:23 +00:00
parent 8bce8040c8
commit 89b0475539
3 changed files with 11 additions and 1 deletions

View File

@ -13,6 +13,7 @@
{% if favicon %}
<link rel="shortcut icon" href="{{ pathto('_static/favicon.ico') }}"/>
{% endif %}
{% if theme_analytics_tracking_code %}
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@ -20,10 +21,11 @@
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-17511903-1', 'auto');
ga('create', '{{ theme_analytics_tracking_code }}', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
{% endif %}
</head>
<body>
{% include 'header.html' %}

View File

@ -2,3 +2,6 @@
inherit = basic
stylesheet = css/basic.css
pygments_style = native
[options]
analytics_tracking_code = UA-17511903-1

View File

@ -0,0 +1,5 @@
---
features:
- Google Analytics tracking may now be controlled by
setting the ``analytics_tracking_code`` option, or
removed entirely by leaving that option blank.