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

[PAY-1457] Add amplitude analytics to chat features #3627

Merged
merged 15 commits into from
Jun 22, 2023
14 changes: 10 additions & 4 deletions packages/common/src/hooks/chats/useCanSendMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSelector } from 'react-redux'

import { User } from 'models/User'
import { CommonState } from 'store/index'
import { ChatPermissionAction, CommonState } from 'store/index'
import {
getCanSendMessage,
getOtherChatUsers
Expand All @@ -12,14 +12,20 @@ import { useProxySelector } from '..'
/**
* Returns whether or not the current user can send messages to the current chat
*/
export const useCanSendMessage = (currentChatId?: string) => {
export const useCanSendMessage = (
currentChatId?: string
): {
canSendMessage: boolean
callToAction: ChatPermissionAction
// Explicitly define type as undefinable since users could be empty
firstOtherUser: User | undefined
} => {
const users = useProxySelector(
(state) => getOtherChatUsers(state, currentChatId),
[currentChatId]
)

// Explicitly define type as undefinable since users could be empty
const firstOtherUser: User | undefined = users[0]
const firstOtherUser = users[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be able to avoid the returntype with const firstOtherUser = users[0] as User | undefined


const { canSendMessage, callToAction } = useSelector((state: CommonState) =>
getCanSendMessage(state, {
Expand Down
93 changes: 92 additions & 1 deletion packages/common/src/models/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ChatPermission } from '@audius/sdk'

import { FeedFilter } from 'models/FeedFilter'
import { ID, PlayableType } from 'models/Identifiers'
import { MonitorPayload, ServiceMonitorType } from 'models/Services'
Expand Down Expand Up @@ -319,7 +321,23 @@ export enum Name {
CONNECT_WALLET_NEW_WALLET_CONNECTED = 'Connect Wallet: New Wallet Connected',
CONNECT_WALLET_ALREADY_ASSOCIATED = 'Connect Wallet: Already Associated',
CONNECT_WALLET_ASSOCIATION_ERROR = 'Connect Wallet: Association Error',
CONNECT_WALLET_ERROR = 'Connect Wallet: Error'
CONNECT_WALLET_ERROR = 'Connect Wallet: Error',

// Chat
CREATE_CHAT_SUCCESS = 'Create Chat: Success',
CREATE_CHAT_FAILURE = 'Create Chat: Failure',
SEND_MESSAGE_SUCCESS = 'Send Message: Success',
SEND_MESSAGE_FAILURE = 'Send Message: Failure',
DELETE_CHAT_SUCCESS = 'Delete Chat: Success',
DELETE_CHAT_FAILURE = 'Delete Chat: Failure',
BLOCK_USER_SUCCESS = 'Block User: Success',
BLOCK_USER_FAILURE = 'Block User: Failure',
CHANGE_INBOX_SETTINGS_SUCCESS = 'Change Inbox Settings: Success',
CHANGE_INBOX_SETTINGS_FAILURE = 'Change Inbox Settings: Failure',
SEND_MESSAGE_REACTION_SUCCESS = 'Send Message Reaction: Success',
SEND_MESSAGE_REACTION_FAILURE = 'Send Message Reaction: Failure',
MESSAGE_UNFURL_TRACK = 'Message Unfurl: Track',
MESSAGE_UNFURL_PLAYLIST = 'Message Unfurl: Playlist'
}

type PageView = {
Expand Down Expand Up @@ -1512,6 +1530,64 @@ type ConnectWalletError = {
error: string
}

type CreateChatSuccess = {
eventName: Name.CREATE_CHAT_SUCCESS
}

type CreateChatFailure = {
eventName: Name.CREATE_CHAT_FAILURE
}

type SendMessageSuccess = {
eventName: Name.SEND_MESSAGE_SUCCESS
}

type SendMessageFailure = {
eventName: Name.SEND_MESSAGE_FAILURE
}

type DeleteChatSuccess = {
eventName: Name.DELETE_CHAT_SUCCESS
}

type DeleteChatFailure = {
eventName: Name.DELETE_CHAT_FAILURE
}

type BlockUserSuccess = {
eventName: Name.BLOCK_USER_SUCCESS
rickyrombo marked this conversation as resolved.
Show resolved Hide resolved
}

type BlockUserFailure = {
eventName: Name.BLOCK_USER_FAILURE
}

type ChangeInboxSettingsSuccess = {
eventName: Name.CHANGE_INBOX_SETTINGS_SUCCESS
permission: ChatPermission
}

type ChangeInboxSettingsFailure = {
eventName: Name.CHANGE_INBOX_SETTINGS_FAILURE
permission: ChatPermission
}

type SendMessageReactionSuccess = {
eventName: Name.SEND_MESSAGE_REACTION_SUCCESS
rickyrombo marked this conversation as resolved.
Show resolved Hide resolved
}

type SendMessageReactionFailure = {
eventName: Name.SEND_MESSAGE_REACTION_FAILURE
}

type MessageUnfurlTrack = {
eventName: Name.MESSAGE_UNFURL_TRACK
}

type MessageUnfurlPlaylist = {
eventName: Name.MESSAGE_UNFURL_PLAYLIST
}

export type BaseAnalyticsEvent = { type: typeof ANALYTICS_TRACK_EVENT }

export type AllTrackingEvents =
Expand Down Expand Up @@ -1714,3 +1790,18 @@ export type AllTrackingEvents =
| ConnectWalletAlreadyAssociated
| ConnectWalletAssociationError
| ConnectWalletError
| SendMessageSuccess
| CreateChatSuccess
| CreateChatFailure
| SendMessageSuccess
| SendMessageFailure
| DeleteChatSuccess
| DeleteChatFailure
| BlockUserSuccess
| BlockUserFailure
| ChangeInboxSettingsSuccess
| ChangeInboxSettingsFailure
| SendMessageReactionSuccess
| SendMessageReactionFailure
| MessageUnfurlTrack
| MessageUnfurlPlaylist
Loading