Skip to content

Commit 35851ea

Browse files
authored
Add plausible stats for jupyter.org (#296)
1 parent 2943c69 commit 35851ea

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ html:
2828
</p>
2929
3030
sphinx:
31+
local_extensions:
32+
_plausible: .
3133
config:
3234
html_show_copyright: false

_plausible.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Sphinx extension to add Plausible analytics to Jupyter Book."""
2+
3+
4+
def setup(app):
5+
"""Add Plausible analytics scripts to the site."""
6+
# Add the external Plausible script for jupyter.org
7+
app.add_js_file(
8+
"https://plausible.io/js/pa-B75UO5--FNXYQSG7GBWkf.js",
9+
loading_method="async"
10+
)
11+
12+
# Add the inline initialization script
13+
plausible_init = """
14+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
15+
plausible.init({hashBasedRouting:true})
16+
"""
17+
app.add_js_file(None, body=plausible_init)
18+
19+
return {
20+
'version': '0.1',
21+
'parallel_read_safe': True,
22+
'parallel_write_safe': True,
23+
}

0 commit comments

Comments
 (0)