27 lines
835 B
TypeScript
27 lines
835 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { useConsentStore } from "@/lib/consent-store";
|
|
import { GoogleAnalytics, GoogleTagManager } from "@next/third-parties/google";
|
|
|
|
export function AnalyticsWrapper() {
|
|
const { analytics, marketing, isInitialized, initialize } = useConsentStore();
|
|
|
|
useEffect(() => {
|
|
initialize();
|
|
}, [initialize]);
|
|
|
|
if (!isInitialized) return null;
|
|
|
|
return (
|
|
<>
|
|
{/* Ładujemy GTM tylko jeśli zgoda na marketing ATAK LUB analitykę,
|
|
w zależności od rygorystyczności, zazwyczaj GTM potrzebuje analityki/marketingu */}
|
|
{(analytics || marketing) && <GoogleTagManager gtmId="GTM-MBMRCD2N" />}
|
|
|
|
{/* Ładujemy GA4 tylko jeśli użytkownik zgodził się na analitykę */}
|
|
{analytics && <GoogleAnalytics gaId="G-1NGTSR4TWD" />}
|
|
</>
|
|
);
|
|
}
|