Files
thermcool/components/ui/AnalyticsWrapper.tsx
T

45 lines
1.3 KiB
TypeScript

'use client';
import Script from 'next/script';
import { useConsentStore } from '@/lib/consent-store';
const GA_ID = 'G-VW3GD6SS7K';
const CLARITY_ID = 'xdo6q3i06e';
export function AnalyticsWrapper() {
const { analyticsConsent } = useConsentStore();
if (!analyticsConsent) return null;
return (
<>
{/* GA4 */}
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`}
strategy="afterInteractive"
/>
<Script id="ga4-init" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_ID}', {
page_path: window.location.pathname,
});
`}
</Script>
{/* Microsoft Clarity */}
<Script id="clarity-init" strategy="afterInteractive">
{`
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "${CLARITY_ID}");
`}
</Script>
</>
);
}