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 pathurlof the requestua: user-agent of the clientgt_ms: measured as the time before and after this middleware call next in the asgi stack.cvarwith at leasthttp_status_codeandhttp_methodset.lang: if the headeraccept-langis setcip: client ip, this is only tracked ifaccess_tokenis givensendimage=0for performance issues
Please refer to Matomo Tracking HTTP API for available variables.