From 69a5b485d3c1d633c5697923e6d9d573f5198bd7 Mon Sep 17 00:00:00 2001 From: ndom91 Date: Thu, 11 Jul 2024 13:28:32 +0200 Subject: [PATCH] fix: useEffect swetrix --- src/components/analytics.jsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/analytics.jsx b/src/components/analytics.jsx index 486e929..f00d28e 100644 --- a/src/components/analytics.jsx +++ b/src/components/analytics.jsx @@ -1,19 +1,21 @@ 'use client' import * as Swetrix from 'swetrix' -import { Suspense } from 'react' +import { useEffect, Suspense } from 'react' import { usePathname } from 'next/navigation' function SwetrixComponent() { const pathname = usePathname() - if (window.location.host === 'briefkastenhq.com') { - Swetrix.init(process.env.NEXT_PUBLIC_SWETRIX_PROJECT, { - apiURL: process.env.NEXT_PUBLIC_SWETRIX_API_HOST, - }) - let url = pathname - Swetrix.trackPageview(url) - } + useEffect(() => { + if (window.location.host === 'briefkastenhq.com') { + Swetrix.init(process.env.NEXT_PUBLIC_SWETRIX_PROJECT, { + apiURL: process.env.NEXT_PUBLIC_SWETRIX_API_HOST, + }) + let url = pathname + Swetrix.trackPageview(url) + } + }, [pathname]) return
}