Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Amplitude tracking for chat report abuse (#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored Jun 23, 2023
1 parent 6f570c6 commit ab33206
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
9 changes: 8 additions & 1 deletion packages/common/src/models/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ export enum Name {
SEND_MESSAGE_REACTION_FAILURE = 'Send Message Reaction: Failure',
MESSAGE_UNFURL_TRACK = 'Message Unfurl: Track',
MESSAGE_UNFURL_PLAYLIST = 'Message Unfurl: Playlist',
TIP_UNLOCKED_CHAT = 'Unlocked Chat: Tip'
TIP_UNLOCKED_CHAT = 'Unlocked Chat: Tip',
CHAT_REPORT_USER = 'Report User: Chat'
}

type PageView = {
Expand Down Expand Up @@ -1598,6 +1599,11 @@ type TipUnlockedChat = {
recipientUserId: ID
}

type ChatReportUser = {
eventName: Name.CHAT_REPORT_USER
reportedUserId: ID
}

export type BaseAnalyticsEvent = { type: typeof ANALYTICS_TRACK_EVENT }

export type AllTrackingEvents =
Expand Down Expand Up @@ -1816,3 +1822,4 @@ export type AllTrackingEvents =
| MessageUnfurlTrack
| MessageUnfurlPlaylist
| TipUnlockedChat
| ChatReportUser
19 changes: 0 additions & 19 deletions packages/common/src/store/pages/chat/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const {
fetchBlockersSucceeded,
unblockUser,
blockUser,
reportUser,
fetchPermissions,
fetchPermissionsSucceeded,
fetchLinkUnfurl,
Expand Down Expand Up @@ -518,19 +517,6 @@ function* doUnblockUser(action: ReturnType<typeof unblockUser>) {
}
}

function* doReportUser(action: ReturnType<typeof reportUser>) {
try {
console.log('reportUser', action.payload)
} catch (e) {
console.error('reportUserFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
error: e as Error
})
}
}

function* doFetchPermissions(action: ReturnType<typeof fetchPermissions>) {
try {
const currentUserId = yield* select(getUserId)
Expand Down Expand Up @@ -681,10 +667,6 @@ function* watchUnblockUser() {
yield takeEvery(unblockUser, doUnblockUser)
}

function* watchReportUser() {
yield takeEvery(reportUser, doReportUser)
}

function* watchFetchPermissions() {
yield takeEvery(fetchPermissions, doFetchPermissions)
}
Expand Down Expand Up @@ -712,7 +694,6 @@ export const sagas = () => {
watchFetchBlockers,
watchBlockUser,
watchUnblockUser,
watchReportUser,
watchFetchPermissions,
watchFetchLinkUnfurlMetadata,
watchDeleteChat
Expand Down
3 changes: 0 additions & 3 deletions packages/common/src/store/pages/chat/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,6 @@ const slice = createSlice({
unblockUser: (_state, _action: PayloadAction<{ userId: ID }>) => {
// triggers saga
},
reportUser: (_state, _action: PayloadAction<{ userId: ID }>) => {
// triggers saga
},
fetchPermissions: (_state, _action: PayloadAction<{ userIds: ID[] }>) => {
// triggers saga
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import IconInfo from 'app/assets/images/iconInfo.svg'
import { Text, Button } from 'app/components/core'
import { NativeDrawer } from 'app/components/drawer'
import { useDrawer } from 'app/hooks/useDrawer'
import { track, make } from 'app/services/analytics'
import { setVisibility } from 'app/store/drawers/slice'
import { makeStyles, flexRowCentered } from 'app/styles'
import { spacing } from 'app/styles/spacing'
import { EventNames } from 'app/types/analytics'
import { useColor } from 'app/utils/theme'

const { getUser } = cacheUsersSelectors
const { getDoesBlockUser, getCanCreateChat } = chatSelectors
const { blockUser, unblockUser, createChat, reportUser } = chatActions
const { blockUser, unblockUser, createChat } = chatActions

const BLOCK_MESSAGES_MODAL_NAME = 'BlockMessages'

Expand Down Expand Up @@ -127,7 +129,12 @@ export const BlockMessagesDrawer = () => {
} else {
dispatch(blockUser({ userId }))
if (isReportAbuse) {
dispatch(reportUser({ userId }))
track(
make({
eventName: EventNames.CHAT_REPORT_USER,
reportedUserId: userId
})
)
}
}
dispatch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react'

import { User, chatActions } from '@audius/common'
import { User, chatActions, Name } from '@audius/common'
import {
Button,
ButtonType,
Expand All @@ -16,10 +16,11 @@ import { useDispatch } from 'react-redux'

import { HelpCallout } from 'components/help-callout/HelpCallout'
import { UserNameAndBadges } from 'components/user-name-and-badges/UserNameAndBadges'
import { track, make } from 'services/analytics'

import styles from './BlockUserConfirmationModal.module.css'

const { blockUser, reportUser } = chatActions
const { blockUser } = chatActions

const messages = {
title: 'Are you sure?',
Expand Down Expand Up @@ -56,7 +57,12 @@ export const BlockUserConfirmationModal = ({
const handleConfirmClicked = useCallback(() => {
dispatch(blockUser({ userId: user.user_id }))
if (isReportAbuse) {
dispatch(reportUser({ userId: user.user_id }))
track(
make({
eventName: Name.CHAT_REPORT_USER,
reportedUserId: user.user_id
})
)
}
onClose()
}, [dispatch, isReportAbuse, onClose, user.user_id])
Expand Down

0 comments on commit ab33206

Please sign in to comment.