{{-- Site-wide analytics injector. Reads /admin/settings/pwa "Analytics" card + the visitor's wadesk_cookie_consent cookie and emits ONLY the trackers they have consented to. Necessary (none) always renders nothing — there is no "essential" tracker. Analytics trackers (GA4, GTM, Clarity, Plausible, PostHog, Hotjar, Mixpanel) emit when consent.analytics=true. Marketing trackers (Meta Pixel, TikTok, LinkedIn Insight, X Pixel) emit when consent.marketing=true. Each script is the official snippet from the vendor — we just conditionally compose them and substitute the IDs from system_settings. GTM is a special case: when configured it also needs a noscript iframe in . partials/site-analytics-noscript.blade.php emits that — include it right after . --}} @php // Read consent cookie. Default = nothing emitted until user opts in. $consent = ['necessary' => true, 'analytics' => false, 'marketing' => false]; $raw = request()->cookie('wadesk_cookie_consent'); if ($raw) { try { $decoded = json_decode((string) $raw, true); if (is_array($decoded)) { $consent = array_merge($consent, $decoded); } } catch (\Throwable $e) { } } // If the cookie banner is OFF (admin choice), grant full consent — // privacy-friendly default is still off, but admins can deploy // without the modal if they handle consent elsewhere. $bannerOn = (bool) \App\Models\SystemSetting::get('privacy_cookie_banner_enabled', true); if (!$bannerOn) { $consent = ['necessary' => true, 'analytics' => true, 'marketing' => true]; } $ga4 = (string) \App\Models\SystemSetting::get('analytics_google_ga4', ''); $gtm = (string) \App\Models\SystemSetting::get('analytics_google_gtm', ''); $pixel = (string) \App\Models\SystemSetting::get('analytics_meta_pixel', ''); $clar = (string) \App\Models\SystemSetting::get('analytics_microsoft_clarity', ''); $plaus = (string) \App\Models\SystemSetting::get('analytics_plausible_domain', ''); $phKey = (string) \App\Models\SystemSetting::get('analytics_posthog_key', ''); $phHost = (string) \App\Models\SystemSetting::get('analytics_posthog_host', 'https://app.posthog.com'); $hotj = (string) \App\Models\SystemSetting::get('analytics_hotjar_site_id', ''); $tikt = (string) \App\Models\SystemSetting::get('analytics_tiktok_pixel', ''); $linkd = (string) \App\Models\SystemSetting::get('analytics_linkedin_partner', ''); $twPx = (string) \App\Models\SystemSetting::get('analytics_twitter_pixel', ''); $mxpnl = (string) \App\Models\SystemSetting::get('analytics_mixpanel_token', ''); @endphp {{-- ANALYTICS bucket --}} @if ($consent['analytics']) @if ($ga4) {{-- Google Analytics 4 — official gtag.js snippet --}} @endif @if ($gtm) {{-- Google Tag Manager — head snippet --}} @endif @if ($clar) {{-- Microsoft Clarity --}} @endif @if ($plaus) {{-- Plausible — privacy-first, no PII --}} @endif @if ($phKey) {{-- PostHog --}} @endif @if ($hotj) {{-- Hotjar --}} @endif @if ($mxpnl) {{-- Mixpanel --}} @endif @endif {{-- MARKETING bucket --}} @if ($consent['marketing']) @if ($pixel) {{-- Meta (Facebook) Pixel --}} @endif @if ($tikt) {{-- TikTok Pixel --}} @endif @if ($linkd) {{-- LinkedIn Insight Tag --}} @endif @if ($twPx) {{-- X (Twitter) Pixel --}} @endif @endif