mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
docs: add google analytics tracking
This commit is contained in:
parent
c13dfb8024
commit
440fab3d6e
@ -59,6 +59,7 @@ extensions = ['breathe',
|
||||
'extensions.html_redirects',
|
||||
'extensions.toctree_filter',
|
||||
'extensions.list_filter',
|
||||
'extensions.google_analytics',
|
||||
|
||||
# Note: order is important here, events must
|
||||
# be registered by one extension before they can be
|
||||
@ -358,6 +359,8 @@ html_static_path = ['../_static']
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'ReadtheDocsTemplatedoc'
|
||||
|
||||
google_analytics_id = os.environ['CI_GOOGLE_ANALYTICS_ID']
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_template_dir = os.path.join(config_dir, 'latex_templates')
|
||||
|
30
docs/extensions/google_analytics.py
Normal file
30
docs/extensions/google_analytics.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Embeds a google analytics tracking tag in every HTML page
|
||||
def setup(app):
|
||||
app.add_config_value('google_analytics_id', None, 'html')
|
||||
app.connect('html-page-context', google_analytics_embed)
|
||||
|
||||
return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.1'}
|
||||
|
||||
|
||||
def google_analytics_embed(app, pagename, templatename, context, doctree):
|
||||
|
||||
ga_id = app.config.google_analytics_id
|
||||
if not ga_id:
|
||||
return
|
||||
|
||||
metatags = context.get('metatags', '')
|
||||
|
||||
google_analytics_snippet = """
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){{dataLayer.push(arguments);}}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '{}');
|
||||
</script>""".format(ga_id, ga_id)
|
||||
|
||||
# Prepend the google analytics to the HTML metatags (which will be passed to the sphinx templating engine)
|
||||
metatags = google_analytics_snippet + metatags
|
||||
context['metatags'] = metatags
|
@ -31,6 +31,7 @@ components/xtensa/trax/traceparse.py
|
||||
docs/build_docs.py
|
||||
docs/conf_common.py
|
||||
docs/en/conf.py
|
||||
docs/extensions/google_analytics.py
|
||||
docs/extensions/html_redirects.py
|
||||
docs/extensions/list_filter.py
|
||||
docs/extensions/toctree_filter.py
|
||||
|
Loading…
Reference in New Issue
Block a user