Skip to content

Commit

Permalink
feat(app): add analytics for localization feature
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 committed Dec 17, 2024
1 parent c752197 commit 79c1032
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
} from '@opentrons/components'

import { LANGUAGES } from '/app/i18n'
import {
ANALYTICS_LANGUAGE_UPDATED_DESKTOP_APP_MODAL,
useTrackEvent,
} from '/app/redux/analytics'
import {
getAppLanguage,
getStoredSystemLanguage,
Expand All @@ -32,7 +36,7 @@ type ArrayElement<

export function SystemLanguagePreferenceModal(): JSX.Element | null {
const { i18n, t } = useTranslation(['app_settings', 'shared', 'branded'])

const trackEvent = useTrackEvent()
const [currentOption, setCurrentOption] = useState<DropdownOption>(
LANGUAGES[0]
)
Expand Down Expand Up @@ -66,6 +70,15 @@ export function SystemLanguagePreferenceModal(): JSX.Element | null {
const handlePrimaryClick = (): void => {
dispatch(updateConfigValue('language.appLanguage', currentOption.value))
dispatch(updateConfigValue('language.systemLanguage', systemLanguage))
trackEvent({
name: ANALYTICS_LANGUAGE_UPDATED_DESKTOP_APP_MODAL,
properties: {
language: currentOption.value,
modalType: showUpdateModal
? 'systemLanguageUpdateModal'
: 'appBootModal',
},
})
}

const handleDropdownClick = (value: string): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from '@opentrons/components'

import { LANGUAGES } from '/app/i18n'
import { ANALYTICS_LANGUAGE_UPDATED_ODD_SETTINGS } from '/app/redux/analytics'
import { useTrackEventWithRobotSerial } from '/app/redux-resources/analytics'
import { ChildNavigation } from '/app/organisms/ODD/ChildNavigation'
import { getAppLanguage, updateConfigValue } from '/app/redux/config'

Expand Down Expand Up @@ -47,11 +49,18 @@ export function LanguageSetting({
}: LanguageSettingProps): JSX.Element {
const { t } = useTranslation('app_settings')
const dispatch = useDispatch<Dispatch>()
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()

const appLanguage = useSelector(getAppLanguage)

const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
dispatch(updateConfigValue('language.appLanguage', event.target.value))
trackEventWithRobotSerial({
name: ANALYTICS_LANGUAGE_UPDATED_ODD_SETTINGS,
properties: {
language: event.target.value,
},
})
}

return (
Expand Down
7 changes: 7 additions & 0 deletions app/src/pages/Desktop/AppSettings/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import {
useTrackEvent,
ANALYTICS_APP_UPDATE_NOTIFICATIONS_TOGGLED,
ANALYTICS_LANGUAGE_UPDATED_DESKTOP_APP_SETTINGS,
} from '/app/redux/analytics'
import { getAppLanguage, updateConfigValue } from '/app/redux/config'
import { UpdateAppModal } from '/app/organisms/Desktop/UpdateAppModal'
Expand Down Expand Up @@ -71,6 +72,12 @@ export function GeneralSettings(): JSX.Element {

const handleDropdownClick = (value: string): void => {
dispatch(updateConfigValue('language.appLanguage', value))
trackEvent({
name: ANALYTICS_LANGUAGE_UPDATED_DESKTOP_APP_SETTINGS,
properties: {
language: value,
},
})
}

const [showUpdateBanner, setShowUpdateBanner] = useState<boolean>(
Expand Down
9 changes: 9 additions & 0 deletions app/src/pages/ODD/ChooseLanguage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
TYPOGRAPHY,
} from '@opentrons/components'

import { ANALYTICS_LANGUAGE_UPDATED_ODD_UNBOXING_FLOW } from '/app/redux/analytics'
import { useTrackEventWithRobotSerial } from '/app/redux-resources/analytics'
import { MediumButton } from '/app/atoms/buttons'
import { LANGUAGES, US_ENGLISH } from '/app/i18n'
import { RobotSetupHeader } from '/app/organisms/ODD/RobotSetupHeader'
Expand All @@ -24,6 +26,7 @@ export function ChooseLanguage(): JSX.Element {
const { i18n, t } = useTranslation(['app_settings', 'shared'])
const navigate = useNavigate()
const dispatch = useDispatch<Dispatch>()
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()

const appLanguage = useSelector(getAppLanguage)

Expand Down Expand Up @@ -61,6 +64,12 @@ export function ChooseLanguage(): JSX.Element {
isSelected={lng.value === appLanguage}
onChange={() => {
dispatch(updateConfigValue('language.appLanguage', lng.value))
trackEventWithRobotSerial({
name: ANALYTICS_LANGUAGE_UPDATED_ODD_UNBOXING_FLOW,
properties: {
language: lng.value,
},
})
}}
></RadioButton>
))}
Expand Down
12 changes: 12 additions & 0 deletions app/src/redux/analytics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,15 @@ export const ANALYTICS_QUICK_TRANSFER_RERUN = 'quickTransferReRunFromSummary'
*/
export const ANALYTICS_RESOURCE_MONITOR_REPORT: 'analytics:RESOURCE_MONITOR_REPORT' =
'analytics:RESOURCE_MONITOR_REPORT'

/**
* Internationalization Analytics
*/
export const ANALYTICS_LANGUAGE_UPDATED_ODD_UNBOXING_FLOW: 'languageUpdatedOddUnboxingFlow' =
'languageUpdatedOddUnboxingFlow'
export const ANALYTICS_LANGUAGE_UPDATED_ODD_SETTINGS: 'languageUpdatedOddSettings' =
'languageUpdatedOddSettings'
export const ANALYTICS_LANGUAGE_UPDATED_DESKTOP_APP_MODAL: 'languageUpdatedDesktopAppModal' =
'languageUpdatedDesktopAppModal'
export const ANALYTICS_LANGUAGE_UPDATED_DESKTOP_APP_SETTINGS: 'languageUpdatedDesktopAppSettings' =
'languageUpdatedDesktopAppSettings'

0 comments on commit 79c1032

Please sign in to comment.