This commit is contained in:
20
components/analytics/AnalyticsProvider.tsx
Normal file
20
components/analytics/AnalyticsProvider.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { usePathname, useSearchParams } from 'next/navigation';
|
||||
import { getAppServices } from '@/lib/services/create-services';
|
||||
|
||||
// Minimal client-side hook that sends Umami pageviews on route changes.
|
||||
export default function AnalyticsProvider() {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
const services = getAppServices();
|
||||
const url = `${pathname}${searchParams?.size ? `?${searchParams.toString()}` : ''}`;
|
||||
services.analytics.trackPageview(url);
|
||||
}, [pathname, searchParams]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
19
components/analytics/UmamiScript.tsx
Normal file
19
components/analytics/UmamiScript.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import Script from 'next/script';
|
||||
|
||||
export default function UmamiScript() {
|
||||
const websiteId = process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID;
|
||||
if (!websiteId) return null;
|
||||
|
||||
const src =
|
||||
process.env.NEXT_PUBLIC_UMAMI_SCRIPT_URL ??
|
||||
'https://analytics.infra.mintel.me/script.js';
|
||||
|
||||
return (
|
||||
<Script
|
||||
src={src}
|
||||
data-website-id={websiteId}
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user