Internationalization: Add language preference analytics (#59230)

* Report change languange

* clean defaults.ini

* Add language to rudderstand user identify call

* undo changes not intended
This commit is contained in:
Josh Hunt 2022-11-28 12:11:55 +00:00 committed by GitHub
parent b814c66c1d
commit b0e886840d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 12 deletions

View File

@ -102,6 +102,7 @@ jest.mock('app/core/services/PreferencesService', () => ({
const props = { const props = {
resourceUri: '/fake-api/user/1', resourceUri: '/fake-api/user/1',
preferenceType: 'user' as const,
}; };
describe('SharedPreferences', () => { describe('SharedPreferences', () => {

View File

@ -3,7 +3,7 @@ import React, { PureComponent } from 'react';
import { FeatureState, SelectableValue } from '@grafana/data'; import { FeatureState, SelectableValue } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors'; import { selectors } from '@grafana/e2e-selectors';
import { config } from '@grafana/runtime'; import { config, reportInteraction } from '@grafana/runtime';
import { import {
Button, Button,
Field, Field,
@ -26,17 +26,12 @@ import { UserPreferencesDTO } from 'app/types';
export interface Props { export interface Props {
resourceUri: string; resourceUri: string;
disabled?: boolean; disabled?: boolean;
preferenceType: 'org' | 'team' | 'user';
onConfirm?: () => Promise<boolean>; onConfirm?: () => Promise<boolean>;
} }
export type State = UserPreferencesDTO; export type State = UserPreferencesDTO;
const themes: SelectableValue[] = [
{ value: '', label: t('shared-preferences.theme.default-label', 'Default') },
{ value: 'dark', label: t('shared-preferences.theme.dark-label', 'Dark') },
{ value: 'light', label: t('shared-preferences.theme.light-label', 'Light') },
];
function getLanguageOptions(): Array<SelectableValue<string>> { function getLanguageOptions(): Array<SelectableValue<string>> {
const languageOptions = LANGUAGES.map((v) => ({ const languageOptions = LANGUAGES.map((v) => ({
value: v.code, value: v.code,
@ -58,6 +53,7 @@ const i18nFlag = Boolean(config.featureToggles.internationalization);
export class SharedPreferences extends PureComponent<Props, State> { export class SharedPreferences extends PureComponent<Props, State> {
service: PreferencesService; service: PreferencesService;
themeOptions: SelectableValue[];
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
@ -70,6 +66,12 @@ export class SharedPreferences extends PureComponent<Props, State> {
language: '', language: '',
queryHistory: { homeTab: '' }, queryHistory: { homeTab: '' },
}; };
this.themeOptions = [
{ value: '', label: t('shared-preferences.theme.default-label', 'Default') },
{ value: 'dark', label: t('shared-preferences.theme.dark-label', 'Dark') },
{ value: 'light', label: t('shared-preferences.theme.light-label', 'Light') },
];
} }
async componentDidMount() { async componentDidMount() {
@ -116,6 +118,11 @@ export class SharedPreferences extends PureComponent<Props, State> {
onLanguageChanged = (language: string) => { onLanguageChanged = (language: string) => {
this.setState({ language }); this.setState({ language });
reportInteraction('grafana_preferences_language_changed', {
toLanguage: language,
preferenceType: this.props.preferenceType,
});
}; };
render() { render() {
@ -131,8 +138,8 @@ export class SharedPreferences extends PureComponent<Props, State> {
<FieldSet label={<Trans i18nKey="shared-preferences.title">Preferences</Trans>} disabled={disabled}> <FieldSet label={<Trans i18nKey="shared-preferences.title">Preferences</Trans>} disabled={disabled}>
<Field label={t('shared-preferences.fields.theme-label', 'UI Theme')}> <Field label={t('shared-preferences.fields.theme-label', 'UI Theme')}>
<RadioButtonGroup <RadioButtonGroup
options={themes} options={this.themeOptions}
value={themes.find((item) => item.value === theme)?.value} value={this.themeOptions.find((item) => item.value === theme)?.value}
onChange={this.onThemeChanged} onChange={this.onThemeChanged}
/> />
</Field> </Field>

View File

@ -75,6 +75,7 @@ export class RudderstackBackend implements EchoBackend<PageviewEchoEvent, Rudder
window.rudderanalytics?.identify?.(identifier, { window.rudderanalytics?.identify?.(identifier, {
email: options.user.email, email: options.user.email,
orgId: options.user.orgId, orgId: options.user.orgId,
language: options.user.language,
}); });
} }
} }

View File

@ -61,7 +61,12 @@ export class OrgDetailsPage extends PureComponent<Props> {
<VerticalGroup spacing="lg"> <VerticalGroup spacing="lg">
{canReadOrg && <OrgProfile onSubmit={this.onUpdateOrganization} orgName={organization.name} />} {canReadOrg && <OrgProfile onSubmit={this.onUpdateOrganization} orgName={organization.name} />}
{canReadPreferences && ( {canReadPreferences && (
<SharedPreferences resourceUri="org" disabled={!canWritePreferences} onConfirm={this.handleConfirm} /> <SharedPreferences
resourceUri="org"
disabled={!canWritePreferences}
preferenceType="org"
onConfirm={this.handleConfirm}
/>
)} )}
</VerticalGroup> </VerticalGroup>
)} )}

View File

@ -62,7 +62,7 @@ export function UserProfileEditPage({
<Page.Contents isLoading={!user}> <Page.Contents isLoading={!user}>
<VerticalGroup spacing="md"> <VerticalGroup spacing="md">
<UserProfileEditForm updateProfile={updateUserProfile} isSavingUser={isUpdating} user={user} /> <UserProfileEditForm updateProfile={updateUserProfile} isSavingUser={isUpdating} user={user} />
<SharedPreferences resourceUri="user" /> <SharedPreferences resourceUri="user" preferenceType="user" />
<UserTeams isLoading={teamsAreLoading} teams={teams} /> <UserTeams isLoading={teamsAreLoading} teams={teams} />
<UserOrganizations isLoading={orgsAreLoading} setUserOrg={changeUserOrg} orgs={orgs} user={user} /> <UserOrganizations isLoading={orgsAreLoading} setUserOrg={changeUserOrg} orgs={orgs} user={user} />
<UserSessions isLoading={sessionsAreLoading} revokeUserSession={revokeUserSession} sessions={sessions} /> <UserSessions isLoading={sessionsAreLoading} revokeUserSession={revokeUserSession} sessions={sessions} />

View File

@ -84,7 +84,7 @@ export const TeamSettings: FC<Props> = ({ team, updateTeam }) => {
</FieldSet> </FieldSet>
)} )}
</Form> </Form>
<SharedPreferences resourceUri={`teams/${team.id}`} disabled={!canWriteTeamSettings} /> <SharedPreferences resourceUri={`teams/${team.id}`} disabled={!canWriteTeamSettings} preferenceType="team" />
</VerticalGroup> </VerticalGroup>
); );
}; };