From fa45184c297f2c1db845f25f2598d212451d1dca Mon Sep 17 00:00:00 2001 From: = Date: Mon, 3 Feb 2025 09:55:51 -0500 Subject: [PATCH] Declare gtag interface in chat --- src/app/chat/ChatPageClient.tsx | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/app/chat/ChatPageClient.tsx b/src/app/chat/ChatPageClient.tsx index 2e28dfb5..11a6b3c8 100644 --- a/src/app/chat/ChatPageClient.tsx +++ b/src/app/chat/ChatPageClient.tsx @@ -12,6 +12,13 @@ import { LoadingAnimation } from '@/components/LoadingAnimation'; import { BlogPostCard } from '@/components/BlogPostCard'; import { ArticleWithSlug } from '@/lib/shared-types'; +// Add gtag type definition +declare global { + interface Window { + gtag?: (...args: any[]) => void; + } +} + const prepopulatedQuestions = [ "What is the programming bug?", "Why do you love Next.js so much?", @@ -37,10 +44,13 @@ export default function ChatPageClient() { }, headers: {}, onFinish() { - gtag("event", "chat_question", { - event_category: "chat", - event_label: input, - }); + // Make gtag calls safe + if (typeof window !== 'undefined' && window.gtag) { + window.gtag("event", "chat_question", { + event_category: "chat", + event_label: input, + }); + } track("chat", { question: input }); }, onError() { @@ -51,10 +61,13 @@ export default function ChatPageClient() { const handleSearch = async (query: string) => { setInput(query); - gtag("event", "chat_use_precanned_question", { - event_category: "chat", - event_label: query, - }); + // Make gtag calls safe + if (typeof window !== 'undefined' && window.gtag) { + window.gtag("event", "chat_use_precanned_question", { + event_category: "chat", + event_label: query, + }); + } track("chat-precanned", { question: query });