Skip to main content

A super-simple user analytics tool that tracks user behaviour based on web requests to your Django app.

docs/example.jpeg

It’s intended for use with libraries such as htmx, which generally make a web request for each user interaction. It also includes a JavaScript function for tracking purely client-side actions (e.g. things you might use Alpine.js for).

The UI is designed for small projects where understanding individual user behaviour is useful.

Features

  • (optional) Automatic tracking of all web requests - no additional code needed in your project

  • JavaScript function for tracking client-side actions

  • Separate reporting of authenticated and anonymous sessions

  • Shows top platforms, top user-agents (using user-agents), top viewport sizes, and new users, for each month

  • Detects and hides bot traffic

  • Tracking cookies can be disabled (you just won’t see viewport size data)

  • All data is stored in a single table with no relations to your project’s tables

Requirements

Django 4.2+ and Python 3.8+

Installation

  1. pip install django-silent-mammoth-whistle

  2. Add to INSTALLED_APPS setting - ideally just above the main app:

    INSTALLED_APPS = [
            ...,
            "silent_mammoth_whistle",
            ...,
    ]
  3. Add middleware. At the end is fine:

    MIDDLEWARE = [
            ...,
            'silent_mammoth_whistle.middleware.SilentMammothWhistleMiddleware',
    ]
  4. Include the Silent Mammoth Whistle URLconf in your project urls.py. The URL (e.g. /mammoth) can be anything you like:

    urlpatterns = [
            ...,
            path('/mammoth', include('silent_mammoth_whistle.urls')),
            ...,
    ]
  5. Add <script src="{% static 'silent_mammoth_whistle/js/whistle.js' %}"></script> to your templates

  6. Run migrations ./manage.py migrate silent_mammoth_whistle

Configuration

All configuration is optional. The default configuration will track request methods, paths (urls), and response status codes.

settings.py

WHISTLE_USER_ID_FIELD

Defaults to 'id'

The name of a User model attribute that is used as the unqiue user identifier. It is displayed in the UI and is used for determining which web requests belong to which users. Sessions are based on this id.

WHISTLE_CLIENT_EVENT_PATH

Defaults to '/whistle'

The url used by the whistle function in whistle.js to make web requests using JavaScript.

This is used in 2 places: 1) in the middleware, and 2) in the whistle.js file. If you change this setting, you will need to set the same value in a global (window) var called whistleClientEventPath using JavaScript.

WHISTLE_COOKIES

Defaults to True

When True, a cookie is added to clients and is used with some JavaScript to record viewport dimensions. I don’t think this constitutes a “tracking cookie”, but if you think it does and you don’t want that, just set this to False.

WHISTLE_AUTOLOG_REQUEST_METHOD

Defaults to True

Automatically adds the request method (e.g. POST) to the whistle.

WHISTLE_AUTOLOG_REQUEST_PATH

Defaults to True

Automatically adds the request path to the whistle.

WHISTLE_AUTOLOG_RESPONSE_CODE

Defaults to True

Automatically adds the response status code to the whistle.

When this is True, a count of 4xx and 5xx response codes is also displayed next to each session on the main page, and 4xx and 5xx responses are given an orange/red color when viewing the whistle details for a session.

WHISTLE_CACHE

Defaults to False

Enables caching for the homepage queries (charts,etc). Everything older than the current day is cached. See https://docs.djangoproject.com/en/6.1/topics/cache/ for details on configuring cache.

WHISTLE_CACHE_TIMEOUT

Defaults to 30 days.

Usage

By default, Silent Mammoth Whistle will record all web requests (specifically the HTTP method, response code, and path/URL).

You can also record additional data for a request.

request.whistle.request('put a string here')

You can record as much data as you like, and you can make as many of these request.whistle.request() calls as you like. Silent Mammoth Whistle is super-simple and all data is cast to strings using str() before saving. Silent Mammoth Whistle will merge the strings from all the calls into a single string, separated by a tab when rendered.

Practical example time!

This line will record the fields present in a POST request. This could be useful if your form has many optional fields and you want to know which ones were included by the user.

request.whistle.request('fields=' + ', '.join(request.POST.dict().keys()))

When viewing session details in Silent Mammoth Whistle, you’ll see 3 columns: time, request, and response. Request is the obvious column to use, but you might like to separate tracking of what the user requested from how the server responded. E.g. capture which fields were in error in a form submission.

request.whistle.response('Fields in error = ' + ', '.join(form.errors.keys()))

These calls all start with request. because Silent Mammoth Whistle adds a whistle object to the standard Django request object.

JavaScript API

The JavaScript API is similar to the above.

whistle('Edit dialog box open')

whistle takes an unlimited number of arguments. Each argument is added to the whistle.

Bot detection

Bot traffic is recorded and then hidden when viewing whistles.

Metadata

Release files for django-silent-mammoth-whistle 3.0.1

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-silent-mammoth-whistle 3.0.1
File Size Uploaded
django_silent_mammoth_whistle-3.0.1.tar.gz 291.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-silent-mammoth-whistle 3.0.1
File Interpreter ABI Platform
django_silent_mammoth_whistle-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 483.1 kB

Release files / django_silent_mammoth_whistle-3.0.1.tar.gz

Download URL django_silent_mammoth_whistle-3.0.1.tar.gz
Size 291.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0be11bf92718e71bd36649f614e95865c5439cf4db3e99cdb86037b805bcd9f2
BLAKE2b-256 checksum
How to use checksums
f368767f21c7b4c0ffa4430a1630316da57a83d44867899a95d6400616ba7e16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / django_silent_mammoth_whistle-3.0.1-py3-none-any.whl

Download URL django_silent_mammoth_whistle-3.0.1-py3-none-any.whl
Size 191.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b0dd96de4fcdcd130587ae46f94ce42ac815510b17abd3ccdec4f70c18a22e7
BLAKE2b-256 checksum
How to use checksums
b269674226e7c67ce9219dd1deb64fe067a57a26b8554b928083a8452f51eb7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.5

2 release files

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1

1 release file

1.0

1 release file

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