mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 11:17:20 +02:00
docs: add google analytics tracking
This commit is contained in:
@ -59,6 +59,7 @@ extensions = ['breathe',
|
|||||||
'extensions.html_redirects',
|
'extensions.html_redirects',
|
||||||
'extensions.toctree_filter',
|
'extensions.toctree_filter',
|
||||||
'extensions.list_filter',
|
'extensions.list_filter',
|
||||||
|
'extensions.google_analytics',
|
||||||
|
|
||||||
# Note: order is important here, events must
|
# Note: order is important here, events must
|
||||||
# be registered by one extension before they can be
|
# be registered by one extension before they can be
|
||||||
@ -361,6 +362,8 @@ html_static_path = ['../_static']
|
|||||||
# Output file base name for HTML help builder.
|
# Output file base name for HTML help builder.
|
||||||
htmlhelp_basename = 'ReadtheDocsTemplatedoc'
|
htmlhelp_basename = 'ReadtheDocsTemplatedoc'
|
||||||
|
|
||||||
|
google_analytics_id = os.environ['CI_GOOGLE_ANALYTICS_ID']
|
||||||
|
|
||||||
# -- Options for LaTeX output ---------------------------------------------
|
# -- Options for LaTeX output ---------------------------------------------
|
||||||
|
|
||||||
latex_template_dir = os.path.join(config_dir, 'latex_templates')
|
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
|
Reference in New Issue
Block a user