Skip to content

Commit 82280c0

Browse files
authored
Add HTML snippet for Plausible metrics
Metrics are only collected for the main packaging.python.org documentation deployments. Closes #1561
1 parent 7195af6 commit 82280c0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

source/conf.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# -- Project information ---------------------------------------------------------------
22
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
33

4+
import os
5+
6+
# Some options are only enabled for the main packaging.python.org deployment builds
7+
RTD_BUILD = bool(os.getenv("READTHEDOCS"))
8+
RTD_PR_BUILD = RTD_BUILD and os.getenv("READTHEDOCS_VERSION_TYPE") == "external"
9+
RTD_URL = os.getenv("READTHEDOCS_CANONICAL_URL")
10+
RTD_CANONICAL_BUILD = RTD_BUILD and not RTD_PR_BUILD and "packaging.python.org" in RTD_URL
11+
412
project = "Python Packaging User Guide"
513

614
copyright = "2013–2020, PyPA"
@@ -55,6 +63,15 @@
5563
html_favicon = "assets/py.png"
5664
html_last_updated_fmt = ""
5765

66+
_metrics_js_files = [
67+
("https://plausible.io/js/script.js", {"data-domain": "packaging.python.org"})
68+
]
69+
html_js_files = []
70+
if RTD_CANONICAL_BUILD:
71+
# Enable collection of the visitor metrics reported at
72+
# https://plausible.io/packaging.python.org
73+
html_js_files.extend(_metrics_js_files)
74+
5875
# -- Options for HTML help output ------------------------------------------------------
5976
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-help-output
6077

0 commit comments

Comments
 (0)