Skip to content

Commit 373b102

Browse files
committed
analytics update again
1 parent f99f0d7 commit 373b102

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

conf.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ def get_version():
126126
# documentation.
127127
#
128128
html_theme_options = {
129-
'prev_next_buttons_location': 'both',
130-
'analytics_id': 'G-QLSP3FJWGT'
131-
}
129+
'prev_next_buttons_location': 'both'
130+
}
132131

133132
# Add any paths that contain custom static files (such as style sheets) here,
134133
# relative to this directory. They are copied after the builtin static files,
@@ -259,6 +258,21 @@ def get_version():
259258
import recommonmark
260259
from recommonmark.transform import AutoStructify
261260

261+
# -- Set up Google Analytics
262+
# -- using approach at https://stackoverflow.com/questions/9444342/adding-a-javascript-script-tag-some-place-so-that-it-works-for-every-file-in-sph/41885884#41885884
263+
264+
GA_SETUP_JS = """
265+
<!-- Global site tag (gtag.js) - Google Analytics -->
266+
async src="https://www.googletagmanager.com/gtag/js?id=G-QLSP3FJWGT"
267+
"""
268+
GA_INVOKE_JS = """
269+
window.dataLayer = window.dataLayer || [];
270+
function gtag(){dataLayer.push(arguments);}
271+
gtag('js', new Date());
272+
273+
gtag('config', 'G-QLSP3FJWGT');
274+
"""
275+
262276
def setup(app):
263277

264278
app.add_css_file('css/rtd_theme_mods.css')
@@ -268,3 +282,6 @@ def setup(app):
268282
}, True)
269283

270284
app.add_transform(AutoStructify)
285+
286+
app.add_js_file(None, body=GA_SETUP_JS)
287+
app.add_js_file(None, body=GA_INVOKE_JS)

0 commit comments

Comments
 (0)