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:
parent
69fcb572ef
commit
c170580064
@ -15,6 +15,7 @@ import { AIChatMessage } from './AIChatMessage';
|
|||||||
import { AIChatHeader } from './AIChatHeader';
|
import { AIChatHeader } from './AIChatHeader';
|
||||||
import { Resizable } from 'component/common/Resizable/Resizable';
|
import { Resizable } from 'component/common/Resizable/Resizable';
|
||||||
import { AIChatDisclaimer } from './AIChatDisclaimer';
|
import { AIChatDisclaimer } from './AIChatDisclaimer';
|
||||||
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
|
|
||||||
const AI_ERROR_MESSAGE = {
|
const AI_ERROR_MESSAGE = {
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
@ -90,6 +91,7 @@ export const AIChat = () => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { setToastApiError } = useToast();
|
const { setToastApiError } = useToast();
|
||||||
const { chat, newChat } = useAIApi();
|
const { chat, newChat } = useAIApi();
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
|
||||||
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
||||||
|
|
||||||
@ -136,6 +138,12 @@ export const AIChat = () => {
|
|||||||
const onSend = async (content: string) => {
|
const onSend = async (content: string) => {
|
||||||
if (!content.trim() || loading) return;
|
if (!content.trim() || loading) return;
|
||||||
|
|
||||||
|
trackEvent('unleash-ai-chat', {
|
||||||
|
props: {
|
||||||
|
eventType: 'send',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setMessages((currentMessages) => [
|
setMessages((currentMessages) => [
|
||||||
@ -168,7 +176,17 @@ export const AIChat = () => {
|
|||||||
if (!open) {
|
if (!open) {
|
||||||
return (
|
return (
|
||||||
<StyledAIIconContainer>
|
<StyledAIIconContainer>
|
||||||
<StyledAIIconButton size='large' onClick={() => setOpen(true)}>
|
<StyledAIIconButton
|
||||||
|
size='large'
|
||||||
|
onClick={() => {
|
||||||
|
trackEvent('unleash-ai-chat', {
|
||||||
|
props: {
|
||||||
|
eventType: 'open',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<SmartToyIcon />
|
<SmartToyIcon />
|
||||||
</StyledAIIconButton>
|
</StyledAIIconButton>
|
||||||
</StyledAIIconContainer>
|
</StyledAIIconContainer>
|
||||||
@ -187,7 +205,14 @@ export const AIChat = () => {
|
|||||||
<StyledChat>
|
<StyledChat>
|
||||||
<AIChatHeader
|
<AIChatHeader
|
||||||
onNew={onNewChat}
|
onNew={onNewChat}
|
||||||
onClose={() => setOpen(false)}
|
onClose={() => {
|
||||||
|
trackEvent('unleash-ai-chat', {
|
||||||
|
props: {
|
||||||
|
eventType: 'close',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<StyledChatContent>
|
<StyledChatContent>
|
||||||
<AIChatDisclaimer />
|
<AIChatDisclaimer />
|
||||||
|
@ -70,7 +70,8 @@ export type CustomEvents =
|
|||||||
| 'event-timeline'
|
| 'event-timeline'
|
||||||
| 'onboarding'
|
| 'onboarding'
|
||||||
| 'personal-dashboard'
|
| 'personal-dashboard'
|
||||||
| 'order-environments';
|
| 'order-environments'
|
||||||
|
| 'unleash-ai-chat';
|
||||||
|
|
||||||
export const usePlausibleTracker = () => {
|
export const usePlausibleTracker = () => {
|
||||||
const plausible = useContext(PlausibleContext);
|
const plausible = useContext(PlausibleContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user