Skip to content

Commit

Permalink
feat: inject plausible tracking snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Nov 20, 2024
1 parent 99c1a94 commit df31f29
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions util/versionselector/versionselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,27 @@ def html_page_context(app, pagename, templatename, context, doctree):
context["latest_version"] = versioninfo[app.config.versionselector_latest_version]


def config_hook(app, config):
if not config.plausible_script or not config.plausible_domain:
return

app.add_js_file(config.plausible_script, {
"defer": "defer", "data-domain": config.plausible_domain
})
print("Plausible analytics script added to this build")


def setup(app):
app.add_config_value("versionselector_metadata", {}, "html")
app.add_config_value("versionselector_metadata_path", "", "html")
app.add_config_value("versionselector_current_version", "", "html")
app.add_config_value("versionselector_latest_version", "master", "html")

app.add_config_value("plausible_domain", "", "html")
app.add_config_value("plausible_script", "", "html")

app.connect("html-page-context", html_page_context)
app.connect("config-inited", config_hook)

return {
"version": "0.1",
Expand Down Expand Up @@ -186,6 +200,10 @@ def setup(app):
"-D",
"release={current}",
"-D",
"plausible_script=https://plausible.octoprint.org/js/plausible.js",
"-D",
"plausible_domain=docs.octoprint.org",
"-D",
"templates_path={templates}",
"-D",
"extensions={extensions}",
Expand Down

0 comments on commit df31f29

Please sign in to comment.