Skip to content

Commit e1eb291

Browse files
committed
chore: If the browser sends DNT, then analytics will not be collected
1 parent d38d651 commit e1eb291

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

chart/middleware/plausible_analytics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class PlausibleAnalytics:
2424
async def __call__(self, request, call_next):
2525
response = await call_next(request)
2626

27+
if request.headers.get('DNT', 0) == 1:
28+
return response
29+
2730
if (HTTPStatus(response.status_code).is_client_error
2831
or not config['analytics']['enabled']):
2932
return response

server/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fastify.addHook('onResponse', async (request, reply) => {
4747

4848
routePartFiltered.unshift('/');
4949

50+
if (request.headers['DNT'] === 1) return;
5051
if (!config?.['analytics']['work'] ? config?.['analytics']['work'] : false)
5152
return;
5253
else if (!fastify.printRoutes().includes(routePartFiltered.at(-1))) return;

0 commit comments

Comments
 (0)