diff --git a/packages/common/src/models/Analytics.ts b/packages/common/src/models/Analytics.ts index 57a1d526578..9e7c5c7b034 100644 --- a/packages/common/src/models/Analytics.ts +++ b/packages/common/src/models/Analytics.ts @@ -482,6 +482,10 @@ export enum Name { // Chat CREATE_CHAT_SUCCESS = 'Create Chat: Success', CREATE_CHAT_FAILURE = 'Create Chat: Failure', + CHAT_BLAST_CTA_CLICKED = 'Chat Blast: CTA Clicked', + CREATE_CHAT_BLAST_SUCCESS = 'Chat Blast: Create - Success', + CREATE_CHAT_BLAST_FAILURE = 'Chat Blast: Create - Failure', + CHAT_BLAST_MESSAGE_SENT = 'Chat Blast: Message Sent', SEND_MESSAGE_SUCCESS = 'Send Message: Success', SEND_MESSAGE_FAILURE = 'Send Message: Failure', DELETE_CHAT_SUCCESS = 'Delete Chat: Success', @@ -2295,6 +2299,10 @@ type ConnectWalletError = { error: string } +type ChatBlastCTAClicked = { + eventName: Name.CHAT_BLAST_CTA_CLICKED +} + type CreateChatSuccess = { eventName: Name.CREATE_CHAT_SUCCESS } @@ -2303,6 +2311,29 @@ type CreateChatFailure = { eventName: Name.CREATE_CHAT_FAILURE } +type CreateChatBlastSuccess = { + eventName: Name.CREATE_CHAT_BLAST_SUCCESS + audience: string + audienceContentType?: string + audienceContentId?: ID + sentBy: ID +} + +type CreateChatBlastFailure = { + eventName: Name.CREATE_CHAT_BLAST_FAILURE + audience: string + audienceContentType?: string + audienceContentId?: ID + sentBy?: ID +} + +type ChatBlastMessageSent = { + eventName: Name.CHAT_BLAST_MESSAGE_SENT + audience: string + audienceContentType?: string + audienceContentId?: ID +} + type SendMessageSuccess = { eventName: Name.SEND_MESSAGE_SUCCESS } @@ -2743,9 +2774,12 @@ export type AllTrackingEvents = | ConnectWalletAlreadyAssociated | ConnectWalletAssociationError | ConnectWalletError - | SendMessageSuccess + | ChatBlastCTAClicked + | ChatBlastMessageSent | CreateChatSuccess | CreateChatFailure + | CreateChatBlastSuccess + | CreateChatBlastFailure | SendMessageSuccess | SendMessageFailure | DeleteChatSuccess diff --git a/packages/common/src/store/pages/chat/sagas.ts b/packages/common/src/store/pages/chat/sagas.ts index 6cd719d347b..b71cc607670 100644 --- a/packages/common/src/store/pages/chat/sagas.ts +++ b/packages/common/src/store/pages/chat/sagas.ts @@ -1,5 +1,6 @@ import { ChatBlast, + HashId, type ChatMessage, type TypedCommsResponse, type UserChat, @@ -464,8 +465,8 @@ function* doCreateChatBlast(action: ReturnType) { } = action.payload const { track, make } = yield* getContext('analytics') + const currentUserId = yield* select(getUserId) try { - const currentUserId = yield* select(getUserId) if (!currentUserId) { throw new Error('User not found') } @@ -499,7 +500,16 @@ function* doCreateChatBlast(action: ReturnType) { chat: newBlast }) ) - yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS })) + yield* call( + track, + make({ + eventName: Name.CREATE_CHAT_BLAST_SUCCESS, + audience, + audienceContentType, + audienceContentId, + sentBy: currentUserId + }) + ) } } catch (e) { console.error('createChatBlastFailed', e) @@ -519,7 +529,17 @@ function* doCreateChatBlast(action: ReturnType) { audienceContentType } }) - yield* call(track, make({ eventName: Name.CREATE_CHAT_FAILURE })) + + yield* call( + track, + make({ + eventName: Name.CREATE_CHAT_BLAST_FAILURE, + audience, + audienceContentType, + audienceContentId, + sentBy: currentUserId ?? undefined + }) + ) } } @@ -599,6 +619,15 @@ function* doSendMessage(action: ReturnType) { blastId: messageIdToUse, message }) + yield* call( + track, + make({ + eventName: Name.CHAT_BLAST_MESSAGE_SENT, + audience: chat.audience, + audienceContentType: chat.audience_content_type, + audienceContentId: HashId.parse(chat.audience_content_id) + }) + ) } else { yield* call([sdk.chats, sdk.chats.message], { chatId, diff --git a/packages/mobile/src/screens/chat-screen/ChatBlastCTA.tsx b/packages/mobile/src/screens/chat-screen/ChatBlastCTA.tsx index 43f4eec197c..f9309de4145 100644 --- a/packages/mobile/src/screens/chat-screen/ChatBlastCTA.tsx +++ b/packages/mobile/src/screens/chat-screen/ChatBlastCTA.tsx @@ -1,6 +1,7 @@ import React, { useCallback } from 'react' import { useCanSendChatBlast } from '@audius/common/hooks' +import { Name } from '@audius/common/models' import { TouchableHighlight } from 'react-native-gesture-handler' import { @@ -12,6 +13,7 @@ import { } from '@audius/harmony-native' import { KeyboardAvoidingView } from 'app/components/core' import { PLAY_BAR_HEIGHT } from 'app/components/now-playing-drawer/constants' +import { make, track } from 'app/services/analytics' import { useAppDrawerNavigation } from '../app-drawer-screen' @@ -32,6 +34,7 @@ export const ChatBlastCTA = () => { const handleClick = useCallback(() => { navigation.navigate('CreateChatBlast') + track(make({ eventName: Name.CHAT_BLAST_CTA_CLICKED })) }, [navigation]) const userMeetsRequirements = useCanSendChatBlast() diff --git a/packages/web/src/pages/chat-page/components/ChatBlastCTA.tsx b/packages/web/src/pages/chat-page/components/ChatBlastCTA.tsx index 40cc7eeb8fe..10bafe7e408 100644 --- a/packages/web/src/pages/chat-page/components/ChatBlastCTA.tsx +++ b/packages/web/src/pages/chat-page/components/ChatBlastCTA.tsx @@ -1,6 +1,7 @@ import { useCallback } from 'react' import { useCanSendChatBlast } from '@audius/common/hooks' +import { Name } from '@audius/common/models' import { useChatBlastModal } from '@audius/common/src/store' import { Box, @@ -13,6 +14,7 @@ import { IconTokenBronze } from '@audius/harmony' +import { make, track } from 'services/analytics' const messages = { title: 'Send a Message Blast', description: 'Send messages to your fans in bulk.', @@ -32,6 +34,7 @@ export const ChatBlastCTA = (props: ChatBlastCTAProps) => { const handleClick = useCallback(() => { onClick() openChatBlastModal() + track(make({ eventName: Name.CHAT_BLAST_CTA_CLICKED })) }, [onClick, openChatBlastModal]) const userMeetsRequirements = useCanSendChatBlast()