From 5bcbea600397b4bd4b81da42c1afff875a2524a1 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Wed, 25 Sep 2024 12:45:50 +0200 Subject: [PATCH] fix(language-menu): improve "Remember language" measurement --- .../organisms/article-actions/language-menu/index.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/client/src/ui/organisms/article-actions/language-menu/index.tsx b/client/src/ui/organisms/article-actions/language-menu/index.tsx index 14e1955f9ed1..9cbf25a009b6 100644 --- a/client/src/ui/organisms/article-actions/language-menu/index.tsx +++ b/client/src/ui/organisms/article-actions/language-menu/index.tsx @@ -41,14 +41,15 @@ export function LanguageMenu({ // The default is the current locale itself. If that's what's chosen, // don't bother redirecting. if (newLocale !== locale) { - const cookieValueBefore = getCookieValue(PREFERRED_LOCALE_COOKIE_NAME); + const oldLocale = getCookieValue(PREFERRED_LOCALE_COOKIE_NAME); - if (cookieValueBefore === locale) { + if (oldLocale === locale) { for (const translation of translations) { if (translation.locale === newLocale) { - setCookieValue(PREFERRED_LOCALE_COOKIE_NAME, translation.locale, { + setCookieValue(PREFERRED_LOCALE_COOKIE_NAME, newLocale, { maxAge: PREFERRED_LOCALE_COOKIE_MAX_AGE, }); + gleanClick(`${LANGUAGE_REMEMBER}: ${oldLocale} -> ${newLocale}`); } } } @@ -138,17 +139,19 @@ function LocaleRedirectSetting() { }, []); function toggle(event) { + const oldValue = getCookieValue(PREFERRED_LOCALE_COOKIE_NAME); const newValue = event.target.checked; if (newValue) { setCookieValue(PREFERRED_LOCALE_COOKIE_NAME, locale, { maxAge: 60 * 60 * 24 * 365 * 3, }); setPreferredLocale(locale); + gleanClick(`${LANGUAGE_REMEMBER}: ${oldValue} -> ${locale}`); } else { deleteCookie(PREFERRED_LOCALE_COOKIE_NAME); setPreferredLocale(undefined); + gleanClick(`${LANGUAGE_REMEMBER}: ${oldValue} -> 0`); } - gleanClick(`${LANGUAGE_REMEMBER}: ${locale} -> ${Number(newValue)}`); } return (