# Add Privatus Analytics to Sphinx and Read the Docs

> Add cookieless analytics to a Sphinx docs project, hosted on Read the Docs or elsewhere, with html_js_files in conf.py and no theme changes.

Add the script to `html_js_files` in `docs/conf.py`:

```python
html_js_files = [
    (
        "https://privatusstats.com/js/pa.js",
        {
            "defer": "defer",
            "data-site": "pa_YOURSITEID",
            "data-modules": "engage,auto,vitals,clicks,ask",
        },
    ),
]
```

Each entry is a file name or URL, or a tuple of that and a dictionary of
attributes for the `<script>` tag. Sphinx adds the tag to every page it
builds, whatever the theme.

## Read the Docs

Read the Docs builds your project with `conf.py`, so the same setting
applies. To count only the live build and not local `make html` runs, check
the variable Read the Docs sets while building:

```python
import os

html_js_files = []
if os.environ.get("READTHEDOCS") == "True":
    html_js_files.append((
        "https://privatusstats.com/js/pa.js",
        {
            "defer": "defer",
            "data-site": "pa_YOURSITEID",
            "data-modules": "engage,auto,vitals,clicks,ask",
        },
    ))
```

Hits are only stored for hostnames among the site's domains. If you use a
custom domain or want to measure pull request previews, add those hostnames
as [additional domains](/docs/getting-started/add-a-site#more-settings-under-site-settings-general).

Sphinx pages are full page loads, so each page view is counted once.
