Skip to main content

django-plausible-iplweb

CI PyPI Python Django PyPI - Status PyPI - License

Django module to provide easy Plausible integration, with Wagtail support.

Installation

pip install django-plausible-iplweb

Then simply add plausible to INSTALLED_APPS.

Usage

django-plausible-iplweb provides a plausible template tag that emits Plausible's current per-site tracking script. Each Plausible site now has its own script URL (e.g. https://plausible.io/js/pa-XXXXXXXX.js) — there is no data-domain attribute any more. Copy the script URL from your Plausible dashboard (Site Settings → General → Site Installation) into PLAUSIBLE_SCRIPT_URL, then place the tag in your <head>:

{% load plausible %}

{% plausible %}

With PLAUSIBLE_SCRIPT_URL = "https://plausible.io/js/pa-XXXXXXXX.js", this renders:

<script defer src="https://plausible.io/js/pa-XXXXXXXX.js"></script>
<script>
  window.plausible = window.plausible || function () { (window.plausible.q = window.plausible.q || []).push(arguments) };
  plausible.init({"autoCapturePageviews": false});
  (function () {
    var path = window.location.pathname;
    var masks = [];
    for (var i = 0; i < masks.length; i++) {
      path = path.replace(new RegExp(masks[i].pattern, masks[i].flags || "g"), masks[i].replacement);
    }
    var url = window.location.origin + path + window.location.search;
    plausible("pageview", { url: url });
  })();
</script>

Automatic pageview capture is disabled (autoCapturePageviews: false) so the package can send a single, optionally-masked pageview itself (see URL masking).

If PLAUSIBLE_SCRIPT_URL is empty (the default), the tag renders nothing — a convenient way to switch analytics off in development.

Configuration

All configuration lives in settings.py:

Setting Default Purpose
PLAUSIBLE_SCRIPT_URL "" Full per-site script URL from your Plausible dashboard. Empty → tag renders nothing.
PLAUSIBLE_INIT_OPTIONS {"autoCapturePageviews": False} Dict passed (as JSON) to plausible.init(...). Add any init option here, e.g. {"autoCapturePageviews": False, "hashBasedRouting": True}.
PLAUSIBLE_URL_MASKS [] Ordered list of client-side path-masking rules (see below).
PLAUSIBLE_KEEP_QUERY_STRING True Append location.search to the reported URL (keeps utm_*/ref for acquisition reports). Set False to drop the query string entirely.

You can also pass the script URL at call time, e.g. to use a different site on one page:

{% plausible script_url="https://plausible.io/js/pa-OTHER.js" %}

URL masking

Plausible records the page URL. If your paths contain identifiers (invitation codes, user IDs, UUIDs, …) those would leak into your analytics. PLAUSIBLE_URL_MASKS lets you redact them client-side before the pageview is sent. Each rule is applied to location.pathname in order via JavaScript's String.replace(new RegExp(pattern, flags), replacement):

PLAUSIBLE_URL_MASKS = [
    # Mask invitation/passphrase codes:  /i/<passphrase>  ->  /i/__code__
    {"pattern": r"^/i/[^/]+", "replacement": "/i/__code__"},
    # Mask UUIDs anywhere in the path:  /<uuid>  ->  /__id__
    {"pattern": r"/[0-9a-f-]{36}", "replacement": "/__id__", "flags": "gi"},
    # Mask numeric ids:  /123  ->  /__id__
    {"pattern": r"/\d+", "replacement": "/__id__"},
]

pattern and flags are JavaScript regular-expression syntax (the rules run in the browser). flags defaults to "g". The patterns above are examples — adapt them to your own routes; the default ([]) applies no masking.

Caveat: like Plausible's own redaction guidance, this masking runs once when the page loads. It may not behave as expected in single-page applications or with hash-based routing, where location changes without a full page load.

Overriding the rendered markup

The snippet is rendered from the plausible/plausible.html template. To fully customise it, shadow that path in your own project's templates directory.

Usage with Wagtail

django-plausible-iplweb also provides an optional Wagtail integration that lets editors set the script URL per site through the Wagtail admin. Add plausible.contrib.wagtail to INSTALLED_APPS and run migrate.

Configuration is done through the "Plausible Analytics" setting:

  • script_url: the full per-site Plausible script URL. Blank (the default) → nothing is rendered for that site.

Masking (PLAUSIBLE_URL_MASKS), init options, and query-string handling are still configured globally via the Django settings above.

Load plausible_wagtail rather than plausible; the tag itself is still plausible:

{% load plausible_wagtail %}

{% plausible %}

Migrating from 0.5.x

Version 0.6.0 is a clean break to match Plausible's new tracker. Update your settings:

Old (0.5.x) New (0.6.0)
PLAUSIBLE_DOMAIN + PLAUSIBLE_SCRIPT_NAME PLAUSIBLE_SCRIPT_URL (the full script URL from your dashboard)
data-domain (request host / site_domain) (gone — the site is identified by the script URL)
{% plausible site_domain=… plausible_domain=… script_name=… %} {% plausible %} (optionally script_url=…)
Wagtail site_domain / plausible_domain / script_name fields Wagtail script_url field (migration 0002 applies the change)

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

This is a fork of django-plausible by Jake Howard.

Release files for django-plausible-iplweb 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-plausible-iplweb 0.6.2
File Size Uploaded
django_plausible_iplweb-0.6.2.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-plausible-iplweb 0.6.2
File Interpreter ABI Platform
django_plausible_iplweb-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 28.7 kB

Release files / django_plausible_iplweb-0.6.2.tar.gz

Download URL django_plausible_iplweb-0.6.2.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
db5059a1192abb6fcf181d2ceb77c7864c8978f80d33e31eef913dc67a2499ec
BLAKE2b-256 checksum
How to use checksums
5a847d3c475ef228d68c340ac0dc67380ad02d88a65c91af3590a3b85b674954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / django_plausible_iplweb-0.6.2-py3-none-any.whl

Download URL django_plausible_iplweb-0.6.2-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb4f9d5aa14dc4428776a50475cd201138a06f81ca51af8203d2648c722bc8ed
BLAKE2b-256 checksum
How to use checksums
4fcfc58353439af0aca34bc145baf20bbca6ebddd98751eb4afa85a39364b51f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page