diff --git a/src/middleware/plausible_analytics.py b/src/middleware/plausible_analytics.py index 32a8cd6..f0b238a 100644 --- a/src/middleware/plausible_analytics.py +++ b/src/middleware/plausible_analytics.py @@ -1,9 +1,10 @@ import httpx import yaml +from http import HTTPStatus from user_agents import parse as ua_parse -config = yaml.safe_load(open('../config.yaml')) +config = yaml.safe_load(open('./config.yaml')) class PlausibleAnalytics: async def __call__(self, request, call_next): @@ -12,6 +13,9 @@ class PlausibleAnalytics: user_agent = request.headers.get('user-agent', 'unknown') user_agent_parsed = ua_parse(user_agent) + if HTTPStatus(response.status_code).is_client_error: + return + event = { "domain": config['analytics']['domain'], "name": request.url.path or '404 - Not Found',