import React, { useEffect, useState } from 'react'; import { Shield, SlidersHorizontal, Info, Save, Globe } from 'lucide-react'; import { toast } from 'react-toastify'; import adminPrivacyService, { CookieIntegrationSettings, CookieIntegrationSettingsResponse, CookiePolicySettings, CookiePolicySettingsResponse, } from '../../features/content/services/adminPrivacyService'; import Loading from '../../shared/components/Loading'; const CookieSettingsPage: React.FC = () => { const [policy, setPolicy] = useState({ analytics_enabled: true, marketing_enabled: true, preferences_enabled: true, }); const [integrations, setIntegrations] = useState({ ga_measurement_id: '', fb_pixel_id: '', }); const [policyMeta, setPolicyMeta] = useState< Pick | null >(null); const [integrationMeta, setIntegrationMeta] = useState< Pick | null >(null); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const loadSettings = async () => { try { setLoading(true); const [policyRes, integrationRes] = await Promise.all([ adminPrivacyService.getCookiePolicy(), adminPrivacyService.getIntegrations(), ]); setPolicy(policyRes.data); setPolicyMeta({ updated_at: policyRes.updated_at, updated_by: policyRes.updated_by, }); setIntegrations(integrationRes.data || {}); setIntegrationMeta({ updated_at: integrationRes.updated_at, updated_by: integrationRes.updated_by, }); } catch (error: any) { toast.error(error.message || 'Failed to load cookie & integration settings'); } finally { setLoading(false); } }; useEffect(() => { void loadSettings(); }, []); const handleToggle = (key: keyof CookiePolicySettings) => { setPolicy((prev) => ({ ...prev, [key]: !prev[key], })); }; const handleSave = async () => { try { setSaving(true); const [policyRes, integrationRes] = await Promise.all([ adminPrivacyService.updateCookiePolicy(policy), adminPrivacyService.updateIntegrations(integrations), ]); setPolicy(policyRes.data); setPolicyMeta({ updated_at: policyRes.updated_at, updated_by: policyRes.updated_by, }); setIntegrations(integrationRes.data || {}); setIntegrationMeta({ updated_at: integrationRes.updated_at, updated_by: integrationRes.updated_by, }); toast.success('Cookie policy and integrations updated successfully'); } catch (error: any) { toast.error(error.message || 'Failed to update cookie settings'); } finally { setSaving(false); } }; const handleSaveIntegrations = async () => { try { setSaving(true); const integrationRes = await adminPrivacyService.updateIntegrations( integrations ); setIntegrations(integrationRes.data || {}); setIntegrationMeta({ updated_at: integrationRes.updated_at, updated_by: integrationRes.updated_by, }); toast.success('Integration IDs updated successfully'); } catch (error: any) { toast.error(error.message || 'Failed to update integration IDs'); } finally { setSaving(false); } }; if (loading) { return ; } return (
{}

Cookie & Privacy Controls

Define which cookie categories are allowed in the application. These settings control which types of cookies your users can consent to.

{}

How these settings affect the guest experience

Disabling a category here prevents it from being offered to guests as part of the cookie consent flow. For example, if marketing cookies are disabled, the website should not load marketing pixels even if a guest previously opted in.

{policyMeta?.updated_at && (

Last updated on{' '} {new Date(policyMeta.updated_at).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short', })} {policyMeta.updated_by && ( <> {' '}by {policyMeta.updated_by} )}

)}
{}

Analytics Cookies

Anonymous traffic and performance measurement (e.g. page views, conversion funnels).

When disabled, analytics tracking scripts should not be executed, regardless of user consent.

Marketing Cookies

Personalised offers, remarketing campaigns, and external ad networks.

When disabled, do not load any marketing pixels or share data with ad platforms.

Preference Cookies

Remember guest choices like language, currency, and layout.

When disabled, the application should avoid persisting non-essential preferences client-side.

{}

Third-Party Integrations

Configure IDs for supported analytics and marketing platforms. The application will only load these when both the policy and user consent allow it.

{integrationMeta?.updated_at && (

Last changed

{new Date(integrationMeta.updated_at).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short', })}

{integrationMeta.updated_by && (

by {integrationMeta.updated_by}

)}
)}
setIntegrations((prev) => ({ ...prev, ga_measurement_id: e.target.value || undefined, })) } placeholder="G-XXXXXXXXXX" className="enterprise-input text-sm" />

Example: G-ABCDE12345. This is used to load GA4 via gtag.js when analytics cookies are allowed.

setIntegrations((prev) => ({ ...prev, fb_pixel_id: e.target.value || undefined, })) } placeholder="123456789012345" className="enterprise-input text-sm" />

Numeric ID from your Meta Pixel. The application will only fire pixel events when marketing cookies are allowed.

); }; export default CookieSettingsPage;