Skip to content

Conversation

@jack482653
Copy link
Collaborator

@jack482653 jack482653 commented Dec 14, 2025

This PR implements cookie consent banner with third-party cookies tracking.

Changes

  • Cookie Consent Banner (components/CookieBanner.tsx)

    • Accept/Reject buttons for user consent
    • Only shows when __sciwork_show_cookie_banner=true cookie exists
    • Keeps choice for 365 days
  • Analytics Blocker (public/ga-destroyer.js)

    • Blocks GA/GTM scripts until user consents
    • Uses MutationObserver to intercept scripts in real-time
  • Cookie Utilities (utils/cookies.ts)

    • needShowCookieBanner() - checks if banner should display
    • setCookieConsent() - stores user choice
    • hasCookieConsent() - checks if user already decided
  • UI Updates

    • Added "secondary" variant to Button component
    • Integrated banner into app layout

Critical Setup Required Before Published to main Branch

  • ga-destroyer.js MUST be injected via Netlify post-processing BEFORE GA scripts
  • Why this matters: The script sets __sciwork_show_cookie_banner=true and monitors DOM changes. If it loads after GA, tracking will start before we can block it.

How It Works

  1. ga-destroyer.js loads → sets __sciwork_show_cookie_banner=true
  2. Banner checks: needShowCookieBanner() && !hasCookieConsent()
  3. If true → show banner; if false → hide
  4. User clicks Accept/Reject → sets __sciwork_is_cookie_consented
  5. Blocker stops intercepting scripts after user visiting website again (if accepted)

Test Plan

  • Banner appears on first visit
  • Accept enables GA, Reject blocks GA
  • Choice persists across pages
  • Netlify post-processing injects script correctly
  • Responsive design works on mobile/tablet

Specially thanks for the hard work of @b95702041 at #11

b95702041 and others added 4 commits December 14, 2025 21:59
- Add CookieBanner component with website styling
- Add cookieUtils for consent management and analytics
- Add AnalyticsInitializer for default gtag consent state
- Update layout.tsx to integrate CookieBanner
- Add 'secondary' variant to Button component for gray styling
- Replace hard-coded button elements in CookieBanner with Button component
- Move cookieUtils from components/ to utils/ folder
- Change AnalyticsInitializer from Client to Server Component
- Use next/script with beforeInteractive strategy
- Ensures consent is denied before any GA requests are sent
- Remove duplicate cookieUtils.ts from components folder
- Update CookieBanner component to manage user consent for cookies.
- Introduce constants for cookie keys in configurations.
- Create ga-destroyer.js to block Google Analytics until consent is given.
- Enhance cookie utility functions for managing consent state.
@netlify
Copy link

netlify bot commented Dec 14, 2025

Deploy Preview for swconf2025 ready!

Name Link
🔨 Latest commit 24d0076
🔍 Latest deploy log https://app.netlify.com/projects/swconf2025/deploys/694037a9687ac9000849907b
😎 Deploy Preview https://deploy-preview-49--swconf2025.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants