fix: refactor analytics

This commit is contained in:
Levente Orban
2025-08-27 16:54:28 +02:00
parent 1ea87ab3ae
commit b2e46efc68
5 changed files with 8 additions and 32 deletions

View File

@@ -1,27 +0,0 @@
import { env } from '$env/dynamic/private';
export const handle = async ({ event, resolve }) => {
// Check if analytics is enabled
const analyticsEnabled = env.ANALYTICS === 'true';
// Define the analytics script HTML
const analyticsScript = analyticsEnabled
? '<script defer src="https://analytics.dalev.hu/script.js" data-website-id="7425d098-e340-4464-bd03-c2e47b004cd9"></script>'
: '';
// Replace the placeholder with the actual script or empty string
const response = await resolve(event);
if (response.headers.get('content-type')?.includes('text/html')) {
const html = await response.text();
const modifiedHtml = html.replace('%ANALYTICS_SCRIPT%', analyticsScript);
return new Response(modifiedHtml, {
headers: response.headers,
status: response.status,
statusText: response.statusText
});
}
return response;
};