From 58874b4655f2212758b0b9f367dcd720cedbe7fa Mon Sep 17 00:00:00 2001 From: Carlos Henrique Bernardes Date: Sun, 23 Nov 2025 02:07:19 -0300 Subject: [PATCH] feat: gate analytics with consent and bundle styles --- README.md | 6 +- README.pt-BR.md | 6 +- index.html | 122 +++++++++------------------- src/main.ts | 28 +------ src/styles/main.css | 86 ++++++++++++++++++++ src/utils/analyticsConsent.ts | 147 ++++++++++++++++++++++++++++++++++ tailwind.config.js | 1 + tests/e2e/text-reader.spec.ts | 26 +++--- 8 files changed, 294 insertions(+), 128 deletions(-) create mode 100644 src/utils/analyticsConsent.ts diff --git a/README.md b/README.md index 0c95168..4f1d25f 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,10 @@ This project uses modern build tools and development dependencies. For end users ## 📈 Analytics & Privacy -- Google Analytics (GA4) and Google Tag Manager now load from the deferred [`analytics.js`](public/analytics.js) file instead of inline snippets. -- The script waits for `requestIdleCallback` or the first user interaction (click, key press, pointer/touch) before injecting GA/GTM assets, freeing the critical rendering path while keeping telemetry intact. +- Google Analytics (GA4) and Google Tag Manager are now opt-in and only load after the visitor accepts telemetry via the in-app "Ativar métricas" control. The preference is stored in `localStorage`. +- The [`analytics.js`](public/analytics.js) bundle is injected lazily after consent and started programmatically with `window.appAnalytics.init()`, keeping it out of the critical rendering path by default. - The GTM `