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.2.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for asgi_matomo-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5b0b33590369efcb1876a62585dcf6858ce387cb15eaef5b33bd6686ff6afd3 |
|
MD5 | c8cc59fe84a17b4f1da95f878c227a6c |
|
BLAKE2b-256 | 4dd477e847d6a9804aaa26ac15c1fd261fcadc18ad1b86255ea379c668272bbe |