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_name
that defaults to the pathurl
of the requestua
: user-agent of the clientgt_ms
: measured as the time before and after this middleware call next in the asgi stack.cvar
with at leasthttp_status_code
andhttp_method
set.lang
: if the headeraccept-lang
is setcip
: client ip, this is only tracked ifaccess_token
is givensendimage=0
for performance issues
Please refer to Matomo Tracking HTTP API for available variables.