Django app to track webtraffic serverside with Matomo API
Project description
Django Matomo API Tracking
This django app enables server side traffic tracking. The code is greatly inspired by the Django Google Analytics app.
Prerequisites
For this middleware to work you must have the following items configured:
- A Matomo server to send tracking data to.
- A Celery task queue configured for Django and functional for the middleware to use. The task queue allows tracking data to be sent asynchronously. You will also need to install a broker of some kind for Celery to use. (i.e. RabbitMQ, Redis, etc.)
Installation
- Install
django-matomo-api-trackingfrom pypi usingpip install django-matomo-api-tracking
Setup / Configuration
- Add
matomo_api_trackingto yourINSTALLED_APPSsetting. - Add a new variable
MATOMO_API_TRACKINGto your settings to configure the behaviour of the app:
MATOMO_API_TRACKING = {
'url': 'https://your-matomo-server.com/matomo.php',
'site_id': <your_site_id>,
'backend':
# choose one of the following backends. if non is specified, the default to CeleryTrackingBackend
"matomo_api_tracking.backends.celery.CeleryTrackingBackend",
# "matomo_api_tracking.backends.redis_batch.RedisBatchTrackingBackend",
# "matomo_api_tracking.backends.direct.DirectTrackingBackend", # for debugging
# 'ignore_paths': ["/debug/", "/health/"],
# 'token_auth': "<your auth token>", # e.g. "33dc3f2536d3025974cccb4b4d2d98f4"
# 'timeout': 8,
# 'redis_url': 'redis://localhost:6379/0', # only needed for batching in the RedisBatchTrackingBackend
# 'redis_key': 'matomo_events', # only needed for batching in the RedisBatchTrackingBackend
}
The app supports multiple backends for sending the tracking data to the Matomo server. The default backend is the CeleryTrackingBackend, which requires you to have Celery set up in your project. The CeleryTrackingBackend sends every tracking event in a separate celery task to the Matomo server. This is the recommended setup for production websites with medium traffic.
Alternatively, for really low-traffic websites or developing purposes, you can use the DirectTrackingBackend. There, no additional setup is required. The middleware sends the tracking data directly in the main thread to the Matomo server.
For high-traffic websites, you can also use the Redis with RedisBatchTrackingBackend. This backend has been implemented in version 0.3.0 to reduce the load on the Matomo server. Multiple django processes can send tracking data to the Matomo server in parallel by using a Redis queue. In the celery configuation, you should enable a periodic task that runs every few seconds to send the tracking data in batches to the Matomo server. This way, you can reduce the number of requests to the Matomo server and improve the performance of your website.
If you don't want to use Celery, you can choose the Redis batch backend, which batches the tracking data and sends it to the Matomo server at regular intervals. For debugging purposes, you can also use the direct backend, which sends the tracking data directly to the Matomo server without any batching.
- enable the middleware by adding the matomo_api_tracking middleware to the list of enabled middlewares in the settings:
MIDDLEWARE = [
...
'matomo_api_tracking.middleware.MatomoApiTrackingMiddleware',
]
- configure a periodic celery beat task if you want to use the RedisBatchTrackingBackend.
CELERY_BEAT_SCHEDULE = {
'flush-matomo-every-n-seconds': {
'task': 'matomo_api_tracking.tasks.flush_matomo_batch',
'schedule': 10.0, # seconds
},
}
and make sure that the celery beat scheduler is running ( e.g. celery --app <your_project_name> beat -l info).
In the settings part, the ignore_path can be used to entirely skip certain
paths from being tracked. If you specify an token_auth, the app will also send
the client's IP address (cip parameter). But this is not required. Additionally,
you can specify a timeout for the requests for middleware sent tracking data.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_matomo_api_tracking-0.3.0.tar.gz.
File metadata
- Download URL: django_matomo_api_tracking-0.3.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8379f2b889b5698463cbfd9c6a0462f8336122d9fd8a48c2df5aac32d78e78eb
|
|
| MD5 |
b515c771f16baa0f1e42f965ceb39136
|
|
| BLAKE2b-256 |
4373418fcc14c49b868ad1ba01bc41388a17784255b09dca31ecfa3fe4e896f9
|
Provenance
The following attestation bundles were made for django_matomo_api_tracking-0.3.0.tar.gz:
Publisher:
ci.yaml on DessimozLab/django-matomo-api-tracking
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_matomo_api_tracking-0.3.0.tar.gz -
Subject digest:
8379f2b889b5698463cbfd9c6a0462f8336122d9fd8a48c2df5aac32d78e78eb - Sigstore transparency entry: 990232761
- Sigstore integration time:
-
Permalink:
DessimozLab/django-matomo-api-tracking@6a3e43c7c42ad167e364d1a406d0b917ef6a5330 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/DessimozLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yaml@6a3e43c7c42ad167e364d1a406d0b917ef6a5330 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_matomo_api_tracking-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_matomo_api_tracking-0.3.0-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
068560ca8b027114c0e6b86133339276c8d70f2759daddbf32864e9cc00644a5
|
|
| MD5 |
9eabd11e6d10e34fccefcb20959f6fa3
|
|
| BLAKE2b-256 |
60acf59f7dba9479a85acd6709f52ace56fa4da030da64a4e851322a4511f9c8
|
Provenance
The following attestation bundles were made for django_matomo_api_tracking-0.3.0-py3-none-any.whl:
Publisher:
ci.yaml on DessimozLab/django-matomo-api-tracking
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_matomo_api_tracking-0.3.0-py3-none-any.whl -
Subject digest:
068560ca8b027114c0e6b86133339276c8d70f2759daddbf32864e9cc00644a5 - Sigstore transparency entry: 990232767
- Sigstore integration time:
-
Permalink:
DessimozLab/django-matomo-api-tracking@6a3e43c7c42ad167e364d1a406d0b917ef6a5330 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/DessimozLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yaml@6a3e43c7c42ad167e364d1a406d0b917ef6a5330 -
Trigger Event:
push
-
Statement type: