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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_plausible_iplweb-0.6.2.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_plausible_iplweb-0.6.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file django_plausible_iplweb-0.6.2.tar.gz.

File metadata

  • Download URL: django_plausible_iplweb-0.6.2.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for django_plausible_iplweb-0.6.2.tar.gz
Algorithm Hash digest
SHA256 db5059a1192abb6fcf181d2ceb77c7864c8978f80d33e31eef913dc67a2499ec
MD5 7abb99dae5c4123df50ba09e054ca0a4
BLAKE2b-256 5a847d3c475ef228d68c340ac0dc67380ad02d88a65c91af3590a3b85b674954

See more details on using hashes here.

File details

Details for the file django_plausible_iplweb-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: django_plausible_iplweb-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for django_plausible_iplweb-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fb4f9d5aa14dc4428776a50475cd201138a06f81ca51af8203d2648c722bc8ed
MD5 011edd1e361d94acdb206d3d3e3c62e5
BLAKE2b-256 4fcfc58353439af0aca34bc145baf20bbca6ebddd98751eb4afa85a39364b51f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page