Skip to content

Commit

Permalink
fix(language-menu): improve "Remember language" measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Sep 25, 2024
1 parent 1f640ff commit 5bcbea6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions client/src/ui/organisms/article-actions/language-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 5bcbea6

Please sign in to comment.