From df31f294e626425491c129537e2c9c2af21718fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 20 Nov 2024 14:33:00 +0100 Subject: [PATCH] feat: inject plausible tracking snippet --- util/versionselector/versionselector.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/util/versionselector/versionselector.py b/util/versionselector/versionselector.py index 63a654681..57d669c30 100644 --- a/util/versionselector/versionselector.py +++ b/util/versionselector/versionselector.py @@ -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", @@ -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}",