RealOrangeOne / django-plausible

Django module to provide easy Plausible integration, with Wagtail support
https://pypi.org/project/django-plausible/
BSD 3-Clause "New" or "Revised" License
16 stars 2 forks source link
analytics django plausible

django-plausible

CI PyPI PyPI - Python Version PyPI - Status PyPI - License

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

Installation

pip install django-plausible

Then simply add plausible to INSTALLED_APPS.

Usage

django-plausible provides a plausible template tag, which can be used to output the required script tag for Plausible.

{% load plausible %}

{% plausible %}

Will result in:

<script defer data-domain="example.com" src="https://plausible.io/js/plausible.js"></script>

Configuration

Configuration can be changed either in settings.py, or when calling the plausible template tag:

These settings will affect all calls to the plausible template tag. To override it at call time, you can also pass them into the template tag:

{% plausible plausible_domain="my-plausible.com" script_name="plausible.hash.js" %}

By default, the domain (data-domain) used will be based on the request's hostname (using request.get_host()). To override this, pass site_domain to the template tag.

If the "compat" script is used, django-plausible will automatically add the required id to the script tag. It is excluded by default to help hide Plausible's presence.

Usage with Wagtail

Additionally, django-plausible provides an (optional) deep integration with Wagtail, allowing configuration through the Wagtail admin. To enable this, additionally add plausible.contrib.wagtail to INSTALLED_APPS.

Configuration is done through the "Plausible Analytics" setting:

To access the template tag, load plausible_wagtail, rather than plausible. The template tag itself is still plausible. Note that unlike the Django variant, the Wagtail template tag doesn't allow options to be passed.

{% load plausible_wagtail %}

{% plausible %}