fix: preserve safe motion and consent failures

This commit is contained in:
Evandro Fonseca Junior committed 2026-09-04 22:02:00 -03:00
1 parent a4e5e5c048
commit bea235d6fd
4 files changed
+61 -14

No files matched your search

+29 -8
View File
@@ -98,7 +98,7 @@ const buttonClassName =
function GoogleAnalyticsConsent() {
const [consent, setConsent] = useState<AnalyticsConsent | null>();
const [preferencesOpen, setPreferencesOpen] = useState(false);
const [revokeError, setRevokeError] = useState<string | null>(null);
const [consentError, setConsentError] = useState<string | null>(null);
const configuredRef = useRef(false);
const preferencesButtonRef = useRef<HTMLButtonElement>(null);
@@ -138,26 +138,38 @@ function GoogleAnalyticsConsent() {
}
function acceptAnalytics() {
if (!persistConsent("granted")) return;
if (!persistConsent("granted")) {
setConsentError(
"Não foi possível salvar sua aceitação. Tente novamente para concluir.",
);
return;
}
setConsentError(null);
enableAnalytics();
setConsent("granted");
closePreferences();
}
function denyAnalytics() {
persistConsent("denied");
if (!persistConsent("denied")) {
setConsentError(
"Não foi possível salvar sua recusa. Tente novamente para concluir.",
);
return;
}
setConsentError(null);
setConsent("denied");
closePreferences();
}
function revokeAnalytics() {
if (!persistConsent("denied")) {
setRevokeError(
setConsentError(
"Não foi possível salvar a revogação. Tente novamente para concluir.",
);
return;
}
setRevokeError(null);
setConsentError(null);
window[GA_DISABLE_KEY] = true;
window.gtag?.("consent", "update", deniedConsent);
expireAnalyticsCookies();
@@ -189,6 +201,15 @@ function GoogleAnalyticsConsent() {
Você decide se permite métricas anônimas para melhorar este site.
Publicidade e personalização continuam desativadas.
</p>
{consentError && (
<p
role="alert"
aria-label="Falha ao salvar o consentimento"
className="mt-sp-3 text-[13px] leading-6 text-[var(--slash)]"
>
{consentError}
</p>
)}
<div className="mt-sp-4 flex flex-wrap gap-sp-2">
<button
type="button"
@@ -257,13 +278,13 @@ function GoogleAnalyticsConsent() {
Analytics está {consent === "granted" ? "ativo" : "desativado"}.
Dados de publicidade permanecem negados.
</p>
{revokeError && (
{consentError && (
<p
role="alert"
aria-label="Falha ao salvar a revogação"
aria-label="Falha ao salvar o consentimento"
className="mt-sp-3 text-[13px] leading-6 text-[var(--slash)]"
>
{revokeError}
{consentError}
</p>
)}
<div className="mt-sp-4 flex flex-wrap gap-sp-2">