From 544a15f612f5296beaf736e08e14a0c815f48bd8 Mon Sep 17 00:00:00 2001 From: Redume Date: Sun, 20 Oct 2024 11:06:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B5=D1=81=D0=BB=D0=B8=204=D1=85=D1=85=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0,=20=D1=82=D0=BE=20=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=B8=D1=82=D0=B8=D0=BA=D0=B0=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D1=82=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware/plausible_analytics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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',