Add new analytics events for group chats (#10830)

This commit is contained in:
DS Boyce
2026-06-10 13:56:39 -07:00
committed by GitHub
parent 974d2b15d5
commit 871e9506df
11 changed files with 184 additions and 29 deletions
@@ -1,3 +1,4 @@
import {useEffect} from 'react'
import {View} from 'react-native'
import {
ChatBskyGroupDefs,
@@ -10,6 +11,7 @@ import {useNavigation} from '@react-navigation/native'
import {useQueryClient} from '@tanstack/react-query'
import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'
import {useCallOnce} from '#/lib/once'
import {makeProfileLink} from '#/lib/routes/links'
import {type NavigationProp} from '#/lib/routes/types'
import {isNetworkError} from '#/lib/strings/errors'
@@ -45,6 +47,7 @@ import {InlineLinkText} from '#/components/Link'
import {Loader} from '#/components/Loader'
import * as Toast from '#/components/Toast'
import {Text} from '#/components/Typography'
import {useAnalytics} from '#/analytics'
import {ProfileBadges} from '../ProfileBadges'
export function GroupChatJoinDialog() {
@@ -83,6 +86,14 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
const moderationOpts = useModerationOpts()
const navigation = useNavigation<NavigationProp>()
const queryClient = useQueryClient()
const ax = useAnalytics()
const logViewOnce = useCallOnce()
useEffect(() => {
logViewOnce(() => {
ax.metric('groupchat:landingPage:view', {hasSession})
})
}, [ax, hasSession, logViewOnce])
const {data, error, isLoading} = useJoinLinkPreviewsQuery({
codes: code ? [code] : undefined,
@@ -96,6 +107,7 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
if (code) void invalidateJoinLinkPreviewsForCode(queryClient, code)
switch (data.status) {
case 'pending':
ax.metric('groupchat:inviteLink:redeem', {})
control.close(() => {
Toast.show(
l`Access requested! The group owner will review your request.`,
@@ -104,6 +116,7 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
break
case 'joined': {
if (data.convo && data.convo.id) {
ax.metric('groupchat:inviteLink:redeem', {})
control.close(() => {
Toast.show(l`Successfully joined the group chat!`)
navigation.navigate('MessagesConversation', {
@@ -140,6 +153,15 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
error instanceof ChatBskyGroupRequestJoin.MemberLimitReachedError
) {
errorMessage = l`The member limit has been reached.`
const preview = data?.joinLinkPreviews[0]
if (
ChatBskyGroupDefs.isJoinLinkPreviewView(preview) &&
preview.convo?.id
) {
ax.metric('groupchat:join:memberLimitReached', {
convoId: preview.convo.id,
})
}
} else if (error instanceof ChatBskyGroupRequestJoin.UserKickedError) {
errorMessage = l`You have been previously removed from this group and cant join it using this link.`
}