- Popup consentement salariés: bandeau style identique employeurs, card Odentas, détails visibles, bouton Accepter visible (sky-600) - Hook useAnalyticsConsent: détection pages salariés (/auto-declaration, /signature-salarie) - ConsentManager: orchestrateur affichage popups selon contexte B2B/B2C - PostHogProvider: init conditionnelle au consentement salarié - Politique Section 9 bis: liste exhaustive organismes (Audiens, AGIRC-ARRCO, CNAV, FNAS, FCAP, etc.), adresse postale pour exercice droits - PopupInfoSuivi: card Odentas Media SAS engagement transparence - Conformité RGPD: B2B (intérêt légitime) + B2C (consentement opt-in Article 6.1.a)
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
'use client';
|
|
|
|
import posthog from 'posthog-js';
|
|
import { PostHogProvider as PHProvider } from 'posthog-js/react';
|
|
import { useEffect } from 'react';
|
|
import { usePathname } from 'next/navigation';
|
|
|
|
const EMPLOYEE_PAGES = ['/auto-declaration', '/signature-salarie'];
|
|
const CONSENT_KEY = 'odentas_analytics_consent_employee';
|
|
|
|
export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|
const pathname = usePathname();
|
|
|
|
useEffect(() => {
|
|
// Vérifier si on est sur une page salarié
|
|
const isEmployeePage = EMPLOYEE_PAGES.some(page => pathname?.includes(page));
|
|
|
|
// Si page salarié, vérifier le consentement
|
|
if (isEmployeePage) {
|
|
const consent = localStorage.getItem(CONSENT_KEY);
|
|
|
|
// Si pas de consentement ou refusé, ne pas initialiser PostHog
|
|
if (consent !== 'accepted') {
|
|
console.log('PostHog: Désactivé (page salarié sans consentement)');
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Initialiser PostHog uniquement côté client et une seule fois
|
|
if (typeof window !== 'undefined' && !posthog.__loaded) {
|
|
const key = process.env.NEXT_PUBLIC_POSTHOG_KEY;
|
|
const host = process.env.NEXT_PUBLIC_POSTHOG_HOST;
|
|
|
|
if (!key || !host) {
|
|
console.error('PostHog: Variables d\'environnement manquantes');
|
|
return;
|
|
}
|
|
|
|
posthog.init(key, {
|
|
api_host: host,
|
|
person_profiles: 'identified_only',
|
|
capture_pageview: false,
|
|
capture_pageleave: true,
|
|
loaded: (posthog) => {
|
|
if (process.env.NODE_ENV === 'development') {
|
|
(window as any).posthog = posthog;
|
|
}
|
|
},
|
|
});
|
|
|
|
console.log('PostHog: Initialisé', isEmployeePage ? '(salarié avec consentement)' : '(client B2B)');
|
|
}
|
|
}, [pathname]);
|
|
|
|
return <PHProvider client={posthog}>{children}</PHProvider>;
|
|
}
|