mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-11-06 01:13:57 +03:00
если 4хх ошибка, то аналитика не будет обрабатываться
This commit is contained in:
parent
7aa8a15cbd
commit
544a15f612
1 changed files with 5 additions and 1 deletions
|
@ -1,9 +1,10 @@
|
||||||
import httpx
|
import httpx
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from http import HTTPStatus
|
||||||
from user_agents import parse as ua_parse
|
from user_agents import parse as ua_parse
|
||||||
|
|
||||||
config = yaml.safe_load(open('../config.yaml'))
|
config = yaml.safe_load(open('./config.yaml'))
|
||||||
|
|
||||||
class PlausibleAnalytics:
|
class PlausibleAnalytics:
|
||||||
async def __call__(self, request, call_next):
|
async def __call__(self, request, call_next):
|
||||||
|
@ -12,6 +13,9 @@ class PlausibleAnalytics:
|
||||||
user_agent = request.headers.get('user-agent', 'unknown')
|
user_agent = request.headers.get('user-agent', 'unknown')
|
||||||
user_agent_parsed = ua_parse(user_agent)
|
user_agent_parsed = ua_parse(user_agent)
|
||||||
|
|
||||||
|
if HTTPStatus(response.status_code).is_client_error:
|
||||||
|
return
|
||||||
|
|
||||||
event = {
|
event = {
|
||||||
"domain": config['analytics']['domain'],
|
"domain": config['analytics']['domain'],
|
||||||
"name": request.url.path or '404 - Not Found',
|
"name": request.url.path or '404 - Not Found',
|
||||||
|
|
Loading…
Reference in a new issue