[ADD] doc: support for analytics keys
This commit is contained in:
parent
27fa742a70
commit
28a69fa250
|
@ -113,4 +113,15 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</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 %}
|
{%- endblock %}
|
||||||
|
|
|
@ -187,6 +187,9 @@ def setup(app):
|
||||||
app.connect('html-page-context', versionize)
|
app.connect('html-page-context', versionize)
|
||||||
app.add_config_value('versions', '', 'env')
|
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):
|
def canonicalize(app, pagename, templatename, context, doctree):
|
||||||
""" Adds a 'canonical' URL for the current document in the rendering
|
""" Adds a 'canonical' URL for the current document in the rendering
|
||||||
context. Requires the ``canonical_root`` setting being set. The canonical
|
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
|
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):
|
def _build_url(root, branch, pagename):
|
||||||
return "{canonical_url}{canonical_branch}/{canonical_page}".format(
|
return "{canonical_url}{canonical_branch}/{canonical_page}".format(
|
||||||
canonical_url=root,
|
canonical_url=root,
|
||||||
|
|
Loading…
Reference in New Issue