Middleware for tracking ASGI reqeusts with Matomo
Project description
asgi-matomo
Tracking requests with Matomo from ASGI apps.
MatomoMiddleware
adds tracking of all requests to Matomo to ASGI applications (Starlette, FastAPI, Quart, etc.).
Installation
pip install asgi-matomo
Examples
Starlette
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
from starlette.middleware import Middleware
from asgi_matomo import MatomoMiddleware
async def homepage(request):
return JSONResponse({"data": "a" * 4000})
app = Starlette(
routes=[Route("/", homepage)],
middleware=[
Middleware(
MatomoMiddleware,
matomo_url="YOUR MATOMO TRACKING URL",
idsite=12345, # your service tracking id
)],
)
FastAPI
from fastapi import FastAPI
from asgi_matomo import MatomoMiddleware
app = FastAPI()
app.add_middleware(
BrotliMiddleware,
matomo_url="YOUR MATOMO TRACKING URL",
idsite=12345, # your service tracking id
)
@app.get("/")
def home() -> dict:
return {"data": "a" * 4000}
API Reference
Overview
app.add_middleware(
MatomoMiddleware,
matomo_url="YOUR MATOMO TRACKING URL",
idsite=12345, # your service tracking id
access_token="SECRETTOKEN",
assume_https=True,
minimum_size=400,
)
Parameters:
- (Required)
matomo_url
: The URL to make your tracking calls to. - (Required)
idsite
: The tracking id for your service. - (Optional)
access_token
: Access token for Matomo. If this is setcip
is also tracked. Required for tracking some data. - (Optional)
assume_https
: IfTrue
, set tracked url scheme tohttps
, useful when running behind a proxy. Defaults toTrue
.
Notes:
- Currently only some parts Matomo Tracking HTTP API is supported.
Ideas for further work:
- filtering tracked of urls
- custom extraction of tracked data
Release Notes
Latest Changes
0.1.0 - 2023-04-28
- Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asgi_matomo-0.1.0.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for asgi_matomo-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2284c482658dc6850d9d72fc88483b3365aee96cb471549fe25a76fb03fc192 |
|
MD5 | 6b26b0a2b32e31a4163c64611e1448b8 |
|
BLAKE2b-256 | cfd6688ed9f6241dad9d732940b2a9e4af1f951e7db9466c46ad7d1303f920fc |