Skip to content

Commit a631c83

Browse files
authored
feat: allow disabling of analytics through a Sphinx option (#43)
1 parent 5acb227 commit a631c83

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎sphinx-ui/demo/source/conf.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@
2121

2222
html_theme = 'quantinuum_sphinx'
2323
html_static_path = ['_static']
24+
25+
# Google Analytics is disabled by default so non-production environments
26+
# (e.g. staging) do not send analytics. Enable it only in the production
27+
# build's conf.py:
28+
# html_theme_options = {
29+
# 'enable_analytics': True,
30+
# }

‎sphinx-ui/quantinuum_sphinx/page.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<!--Force light mode -->
3131
<script>document.body.setAttribute('data-theme','light')</script>
3232
<nav style="position:fixed;top:0;z-index:1021;width:100%;">
33-
<div class="nexus-nav"></div>
33+
<div class="nexus-nav" data-analytics-enabled="{{ 'true' if theme_enable_analytics else 'false' }}"></div>
3434
</nav>
3535
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
3636
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">

‎sphinx-ui/quantinuum_sphinx/theme.toml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ stylesheets = [
77
"styles/quantinuum-ui-tailwind.css",
88
"styles/quantinuum-sphinx.css",
99
]
10+
11+
[options]
12+
# Enable Google Analytics. Disabled by default so non-production
13+
# environments (e.g. staging) do not send analytics. Set to true in the
14+
# production conf.py via html_theme_options = {"enable_analytics": True}.
15+
enable_analytics = false

‎sphinx-ui/react/src/injectNav.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ const observeTailwindDialogPortalElements = () => {
9494
const mountElement = document.querySelector('.nexus-nav')
9595
if (!mountElement) return
9696

97+
const analyticsEnabled = mountElement.getAttribute('data-analytics-enabled') === 'true'
98+
9799
observeTailwindDialogPortalElements()
98100

99101
const renderIn = document.createElement('div')
@@ -106,7 +108,7 @@ const observeTailwindDialogPortalElements = () => {
106108
<div className="antialiased" style={{ fontFamily: `Inter, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"` }}>
107109
<CookieConsentProvider version={1}>
108110
<CookieConditional category={CookieCategoryName.Analytics} fallback={null}>
109-
{GA_ID && <GoogleAnalytics gaId={GA_ID} />}
111+
{analyticsEnabled && GA_ID && <GoogleAnalytics gaId={GA_ID} />}
110112
</CookieConditional>
111113
<DocsNavBar activePath="/" />
112114
<CookieConsentManager />

0 commit comments

Comments
 (0)