[ADD] doc: support for analytics keys
authorXavier Morel <xmo@openerp.com>
Wed, 29 Oct 2014 14:53:41 +0000 (15:53 +0100)
committerXavier Morel <xmo@openerp.com>
Wed, 29 Oct 2014 14:53:41 +0000 (15:53 +0100)
doc/_themes/odoodoc/layout.html
doc/conf.py

index 5e469cf..7881c70 100644 (file)
       </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 %}
index 9ae72b9..cd04e65 100644 (file)
@@ -187,6 +187,9 @@ def setup(app):
     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
@@ -212,6 +215,12 @@ def versionize(app, pagename, templatename, context, doctree):
         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,