Skip to content

Commit

Permalink
Merge pull request #628 from zackproser/fix-chat
Browse files Browse the repository at this point in the history
Declare gtag interface in chat
  • Loading branch information
zackproser authored Feb 3, 2025
2 parents d7f3e6e + fa45184 commit 30e5ef5
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/app/chat/ChatPageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand All @@ -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() {
Expand All @@ -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 });

Expand Down

0 comments on commit 30e5ef5

Please sign in to comment.