Spaces:
Runtime error
Runtime error
Nikolay Angelov
commited on
Commit
·
f7c1665
1
Parent(s):
3b3fbd6
adding google analytics
Browse files
frontend/src/components/ChatBot.tsx
CHANGED
@@ -9,6 +9,13 @@ import SendFeedback from './SendFeedback';
|
|
9 |
import ChatFooter from './ChatFooter';
|
10 |
import { Message, ChatResponse, FeedbackFormData } from '../types';
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
const ChatContainer = styled.div`
|
13 |
display: flex;
|
14 |
flex-direction: column;
|
@@ -63,6 +70,7 @@ const ChatBot: React.FC = () => {
|
|
63 |
};
|
64 |
|
65 |
const sendMessage = async (content: string) => {
|
|
|
66 |
// Add user message to chat
|
67 |
const userMessage: Message = { role: 'user', content };
|
68 |
setMessages(prev => [...prev, userMessage]);
|
@@ -72,6 +80,14 @@ const ChatBot: React.FC = () => {
|
|
72 |
// Create new abort controller
|
73 |
cancelTokenRef.current = new AbortController();
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
try {
|
76 |
// Send message to API
|
77 |
const response = await axios.post<ChatResponse>('/agent/query', {
|
@@ -235,6 +251,13 @@ const ChatBot: React.FC = () => {
|
|
235 |
};
|
236 |
|
237 |
const handleSendFeedbackSubmit = async (data: FeedbackFormData) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
try {
|
239 |
console.log('Sending feedback data:', JSON.stringify(data));
|
240 |
const url = new URL('/agent/feedback', window.location.origin);
|
|
|
9 |
import ChatFooter from './ChatFooter';
|
10 |
import { Message, ChatResponse, FeedbackFormData } from '../types';
|
11 |
|
12 |
+
// Declare gtag on the Window object to resolve TypeScript error
|
13 |
+
declare global {
|
14 |
+
interface Window {
|
15 |
+
gtag?: (...args: any[]) => void;
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
const ChatContainer = styled.div`
|
20 |
display: flex;
|
21 |
flex-direction: column;
|
|
|
70 |
};
|
71 |
|
72 |
const sendMessage = async (content: string) => {
|
73 |
+
|
74 |
// Add user message to chat
|
75 |
const userMessage: Message = { role: 'user', content };
|
76 |
setMessages(prev => [...prev, userMessage]);
|
|
|
80 |
// Create new abort controller
|
81 |
cancelTokenRef.current = new AbortController();
|
82 |
|
83 |
+
if (window.gtag) {
|
84 |
+
window.gtag('event', 'click-send-message', {
|
85 |
+
event_category: 'ChatBot',
|
86 |
+
event_label: 'SendMessage',
|
87 |
+
value: 1,
|
88 |
+
});
|
89 |
+
}
|
90 |
+
|
91 |
try {
|
92 |
// Send message to API
|
93 |
const response = await axios.post<ChatResponse>('/agent/query', {
|
|
|
251 |
};
|
252 |
|
253 |
const handleSendFeedbackSubmit = async (data: FeedbackFormData) => {
|
254 |
+
if (window.gtag) {
|
255 |
+
window.gtag('event', 'click-send-feedback', {
|
256 |
+
event_category: 'ChatBot',
|
257 |
+
event_label: 'SendFeedback',
|
258 |
+
value: 1,
|
259 |
+
});
|
260 |
+
}
|
261 |
try {
|
262 |
console.log('Sending feedback data:', JSON.stringify(data));
|
263 |
const url = new URL('/agent/feedback', window.location.origin);
|
frontend/src/components/ChatFooter.tsx
CHANGED
@@ -50,7 +50,7 @@ interface ChatFooterProps {
|
|
50 |
const ChatFooter: React.FC<ChatFooterProps> = ({ onOpenFeedback, onOpenPDP }) => {
|
51 |
const handlePDPButtonClick = () => {
|
52 |
if (window.gtag) {
|
53 |
-
window.gtag('event', 'click', {
|
54 |
event_category: 'ChatFooter',
|
55 |
event_label: 'PDPButton',
|
56 |
value: 1,
|
|
|
50 |
const ChatFooter: React.FC<ChatFooterProps> = ({ onOpenFeedback, onOpenPDP }) => {
|
51 |
const handlePDPButtonClick = () => {
|
52 |
if (window.gtag) {
|
53 |
+
window.gtag('event', 'click-pdp-button', {
|
54 |
event_category: 'ChatFooter',
|
55 |
event_label: 'PDPButton',
|
56 |
value: 1,
|
frontend/src/components/PDPDialog.tsx
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import React, { useState, FC, ChangeEvent, DragEvent, MouseEvent } from 'react';
|
2 |
import styled from 'styled-components';
|
3 |
|
4 |
-
// Declare gtag on the Window object to resolve TypeScript error
|
5 |
declare global {
|
6 |
interface Window {
|
7 |
gtag?: (...args: any[]) => void;
|
@@ -233,7 +232,7 @@ const PDPDialog: FC<PDPDialogProps> = ({ isOpen, onClose, onSubmit }) => {
|
|
233 |
|
234 |
// Track Generate PDP button click
|
235 |
if (window.gtag) {
|
236 |
-
window.gtag('event', 'click', {
|
237 |
'event_category': 'Button',
|
238 |
'event_label': 'Generate PDP Button - Dialog',
|
239 |
});
|
|
|
1 |
import React, { useState, FC, ChangeEvent, DragEvent, MouseEvent } from 'react';
|
2 |
import styled from 'styled-components';
|
3 |
|
|
|
4 |
declare global {
|
5 |
interface Window {
|
6 |
gtag?: (...args: any[]) => void;
|
|
|
232 |
|
233 |
// Track Generate PDP button click
|
234 |
if (window.gtag) {
|
235 |
+
window.gtag('event', 'click-pdp-submit', {
|
236 |
'event_category': 'Button',
|
237 |
'event_label': 'Generate PDP Button - Dialog',
|
238 |
});
|