Getting started¶
Installation¶
To install asgi-matomo:
pip install asgi-matomo
Usage¶
To use the MatomoMiddleware with, for instance Starlette, simply:
from asgi_matomo import MatomoMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
    return JSONResponse({"data": 4000})
app = Starlette(
    routes=[Route("/", homepage)],
    middleware=[
        Middleware(
            MatomoMiddleware,
            matomo_url="YOUR MATOMO TRACKING URL",
            idsite=12345,  # your service tracking id
        )
    ],
)
This will track all requests made to your service.
What is tracked?¶
Currently asgi-matomo tracks the following variables:
- action_namethat defaults to the path
- urlof the request
- ua: user-agent of the client
- gt_ms: measured as the time before and after this middleware call next in the asgi stack.
- cvarwith at least- http_status_codeand- http_methodset.
- lang: if the header- accept-langis set
- cip: client ip, this is only tracked if- access_tokenis given
- sendimage=0for performance issues
Please refer to Matomo Tracking HTTP API for available variables.