From 9c253baec8917644511a5769274e1c442459eed3 Mon Sep 17 00:00:00 2001 From: Vivek R <123vivekr@gmail.com> Date: Thu, 31 Jul 2025 14:22:58 +0530 Subject: [PATCH] feat(analytics): configure analytics initialization and app integration - Initialize analytics service on app startup in main.tsx - Integrate analytics consent management in App.tsx - Track app lifecycle events (start, screen changes) - Update Tauri configuration for production build - Set up proper analytics shutdown on app close - Ensure analytics is initialized before other services This completes the analytics integration setup with proper initialization and lifecycle management. --- src-tauri/tauri.conf.json | 2 +- src/App.tsx | 19 ++++++++++++++++++- src/main.tsx | 10 ++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index a9876c9..5818017 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -18,7 +18,7 @@ } ], "security": { - "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost blob: data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'; connect-src 'self' ipc: https://ipc.localhost", + "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost blob: data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval' https://app.posthog.com https://*.posthog.com https://*.i.posthog.com https://*.assets.i.posthog.com; connect-src 'self' ipc: https://ipc.localhost https://app.posthog.com https://*.posthog.com https://*.i.posthog.com", "assetProtocol": { "enable": true, "scope": [ diff --git a/src/App.tsx b/src/App.tsx index e6138eb..0d424fb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -26,7 +26,7 @@ import { TabContent } from "@/components/TabContent"; import { AgentsModal } from "@/components/AgentsModal"; import { useTabState } from "@/hooks/useTabState"; import { AnalyticsConsentBanner } from "@/components/AnalyticsConsent"; -import { useAppLifecycle } from "@/hooks"; +import { useAppLifecycle, useTrackEvent } from "@/hooks"; type View = | "welcome" @@ -65,6 +65,23 @@ function AppContent() { // Initialize analytics lifecycle tracking useAppLifecycle(); + const trackEvent = useTrackEvent(); + + // Track user journey milestones + const [hasTrackedFirstChat] = useState(false); + // const [hasTrackedFirstAgent] = useState(false); + + // Track when user reaches different journey stages + useEffect(() => { + if (view === "projects" && projects.length > 0 && !hasTrackedFirstChat) { + // User has projects - they're past onboarding + trackEvent.journeyMilestone({ + journey_stage: 'onboarding', + milestone_reached: 'projects_created', + time_to_milestone_ms: Date.now() - performance.timing.navigationStart + }); + } + }, [view, projects.length, hasTrackedFirstChat, trackEvent]); // Load projects on mount when in projects view useEffect(() => { diff --git a/src/main.tsx b/src/main.tsx index 608b6bd..f7d8f21 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,7 +2,8 @@ import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; import { ErrorBoundary } from "./components/ErrorBoundary"; -import { analytics } from "./lib/analytics"; +import { AnalyticsErrorBoundary } from "./components/AnalyticsErrorBoundary"; +import { analytics, resourceMonitor } from "./lib/analytics"; import { PostHogProvider } from "posthog-js/react"; import "./assets/shimmer.css"; import "./styles.css"; @@ -10,6 +11,9 @@ import "./styles.css"; // Initialize analytics before rendering analytics.initialize(); +// Start resource monitoring (check every 2 minutes) +resourceMonitor.startMonitoring(120000); + ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - + + + ,