1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

chore: add Plausible events to Unleash AI chat (#8494)

https://linear.app/unleash/issue/2-2856/add-plausible-tracking-in-unleash-ai-open-close-chat-send-message

Adds Plausible tracking to some Unleash AI chat events:
 - Open chat
 - Close chat
 - Send message
This commit is contained in:
Nuno Góis 2024-10-21 14:58:13 +01:00 committed by GitHub
parent 69fcb572ef
commit c170580064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import { AIChatMessage } from './AIChatMessage';
import { AIChatHeader } from './AIChatHeader';
import { Resizable } from 'component/common/Resizable/Resizable';
import { AIChatDisclaimer } from './AIChatDisclaimer';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
const AI_ERROR_MESSAGE = {
role: 'assistant',
@ -90,6 +91,7 @@ export const AIChat = () => {
const [loading, setLoading] = useState(false);
const { setToastApiError } = useToast();
const { chat, newChat } = useAIApi();
const { trackEvent } = usePlausibleTracker();
const [messages, setMessages] = useState<ChatMessage[]>([]);
@ -136,6 +138,12 @@ export const AIChat = () => {
const onSend = async (content: string) => {
if (!content.trim() || loading) return;
trackEvent('unleash-ai-chat', {
props: {
eventType: 'send',
},
});
try {
setLoading(true);
setMessages((currentMessages) => [
@ -168,7 +176,17 @@ export const AIChat = () => {
if (!open) {
return (
<StyledAIIconContainer>
<StyledAIIconButton size='large' onClick={() => setOpen(true)}>
<StyledAIIconButton
size='large'
onClick={() => {
trackEvent('unleash-ai-chat', {
props: {
eventType: 'open',
},
});
setOpen(true);
}}
>
<SmartToyIcon />
</StyledAIIconButton>
</StyledAIIconContainer>
@ -187,7 +205,14 @@ export const AIChat = () => {
<StyledChat>
<AIChatHeader
onNew={onNewChat}
onClose={() => setOpen(false)}
onClose={() => {
trackEvent('unleash-ai-chat', {
props: {
eventType: 'close',
},
});
setOpen(false);
}}
/>
<StyledChatContent>
<AIChatDisclaimer />

View File

@ -70,7 +70,8 @@ export type CustomEvents =
| 'event-timeline'
| 'onboarding'
| 'personal-dashboard'
| 'order-environments';
| 'order-environments'
| 'unleash-ai-chat';
export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);