Add translate metrics (#8171)

* Add translate metrics

* Format
This commit is contained in:
Eric Bailey
2025-04-09 17:00:40 -05:00
committed by GitHub
parent 4c0213b3e9
commit 5371114609
4 changed files with 64 additions and 14 deletions
@@ -7,11 +7,11 @@ import {
} from 'react-native'
import * as Clipboard from 'expo-clipboard'
import {
AppBskyFeedDefs,
type AppBskyFeedDefs,
AppBskyFeedPost,
AppBskyFeedThreadgate,
type AppBskyFeedThreadgate,
AtUri,
RichText as RichTextAPI,
type RichText as RichTextAPI,
} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
@@ -20,7 +20,10 @@ import {useNavigation} from '@react-navigation/native'
import {useOpenLink} from '#/lib/hooks/useOpenLink'
import {getCurrentRoute} from '#/lib/routes/helpers'
import {makeProfileLink} from '#/lib/routes/links'
import {CommonNavigatorParams, NavigationProp} from '#/lib/routes/types'
import {
type CommonNavigatorParams,
type NavigationProp,
} from '#/lib/routes/types'
import {shareText, shareUrl} from '#/lib/sharing'
import {logEvent} from '#/lib/statsig/statsig'
import {richTextToString} from '#/lib/strings/rich-text-helpers'
@@ -28,7 +31,7 @@ import {toShareUrl} from '#/lib/strings/url-helpers'
import {getTranslatorLink} from '#/locale/helpers'
import {logger} from '#/logger'
import {isWeb} from '#/platform/detection'
import {Shadow} from '#/state/cache/post-shadow'
import {type Shadow} from '#/state/cache/post-shadow'
import {useProfileShadow} from '#/state/cache/profile-shadow'
import {useFeedFeedbackContext} from '#/state/feed-feedback'
import {useLanguagePrefs} from '#/state/preferences'
@@ -85,6 +88,7 @@ import {
useReportDialogControl,
} from '#/components/moderation/ReportDialog'
import * as Prompt from '#/components/Prompt'
import * as bsky from '#/types/bsky'
import * as Toast from '../Toast'
let PostDropdownMenuItems = ({
@@ -248,7 +252,20 @@ let PostDropdownMenuItems = ({
const onPressTranslate = React.useCallback(async () => {
await openLink(translatorUrl, true)
}, [openLink, translatorUrl])
if (
bsky.dangerousIsType<AppBskyFeedPost.Record>(
post.record,
AppBskyFeedPost.isRecord,
)
) {
logger.metric('translate', {
sourceLanguages: post.record.langs ?? [],
targetLanguage: langPrefs.primaryLanguage,
textLength: post.record.text.length,
})
}
}, [openLink, translatorUrl, langPrefs, post])
const onHidePost = React.useCallback(() => {
hidePost({uri: postUri})