</p>
</div>
</div>
+ {%- if google_analytics_key -%}
+ <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','//www.google-analytics.com/analytics.js','ga');
+
+ ga('create', '{{ google_analytics_key }}', 'auto');
+ ga('send','pageview');
+ </script>
+ {%- endif -%}
{%- endblock %}
app.connect('html-page-context', versionize)
app.add_config_value('versions', '', 'env')
+ app.connect('html-page-context', analytics)
+ app.add_config_value('google_analytics_key', False, 'env')
+
def canonicalize(app, pagename, templatename, context, doctree):
""" Adds a 'canonical' URL for the current document in the rendering
context. Requires the ``canonical_root`` setting being set. The canonical
if vs != app.config.version
]
+def analytics(app, pagename, templatename, context, doctree):
+ if not app.config.google_analytics_key:
+ return
+
+ context['google_analytics_key'] = app.config.google_analytics_key
+
def _build_url(root, branch, pagename):
return "{canonical_url}{canonical_branch}/{canonical_page}".format(
canonical_url=root,