mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +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 { 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 />
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user