/** * Example React SPA with Analytics Integration * * This demonstrates a complete analytics setup in a React application. */ import { BrowserRouter, Routes, Route, Link } from 'react-router-dom'; import { AnalyticsSetup } from './analytics-setup'; import { usePageTracking } from './use-page-tracking'; import { useClickTracking, useOutboundLinkTracking } from './use-click-tracking'; // ───────────────────────────────────────────────────────────────────────────── // Root Layout (with page tracking) // ───────────────────────────────────────────────────────────────────────────── function RootLayout({ children }: { children: React.ReactNode }) { // Automatic page view tracking on route changes usePageTracking({ excludePaths: ['/admin'], // Don't track admin pages }); return (
{children}
); } // ───────────────────────────────────────────────────────────────────────────── // Home Page // ───────────────────────────────────────────────────────────────────────────── function HomePage() { const { createClickHandler } = useClickTracking(); return (

Welcome to Our App

The best app for doing app things.

{/* Track CTA button clicks */}
); } // ───────────────────────────────────────────────────────────────────────────── // Products Page // ───────────────────────────────────────────────────────────────────────────── interface Product { id: string; name: string; price: number; } function ProductsPage() { const { trackClick } = useClickTracking(); const products: Product[] = [ { id: 'prod-1', name: 'Widget Pro', price: 99 }, { id: 'prod-2', name: 'Widget Basic', price: 49 }, { id: 'prod-3', name: 'Widget Enterprise', price: 299 }, ]; const handleProductClick = (product: Product) => { // Track product card clicks trackClick({ elementId: 'product-card', category: 'product', metadata: { productId: product.id, productName: product.name, productPrice: product.price, }, }); }; return (

Our Products

{products.map((product) => (
handleProductClick(product)} >

{product.name}

${product.price}

))}
); } // ───────────────────────────────────────────────────────────────────────────── // About Page (with outbound link tracking) // ───────────────────────────────────────────────────────────────────────────── function AboutPage() { const { trackOutboundClick } = useOutboundLinkTracking(); return (

About Us

We make great software.

Follow us on{' '} trackOutboundClick('https://twitter.com/yourcompany')} > Twitter {' '}and{' '} trackOutboundClick('https://github.com/yourcompany')} > GitHub

); } // ───────────────────────────────────────────────────────────────────────────── // App Root // ───────────────────────────────────────────────────────────────────────────── export function App() { return ( } /> } /> } /> ); } export default App;