Skip to content

Conversation

@b95702041
Copy link

  • Add CookieBanner component with website styling
  • Add cookieUtils for consent management and analytics
  • Update layout.tsx to integrate CookieBanner

@netlify
Copy link

netlify bot commented Oct 18, 2025

Deploy Preview for swconf2025 ready!

Name Link
🔨 Latest commit 7eaa1cd
🔍 Latest deploy log https://app.netlify.com/projects/swconf2025/deploys/69288813ddca0a0008733d75
😎 Deploy Preview https://deploy-preview-11--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.


// Google Analytics (gtag.js)
if (typeof window !== 'undefined' && (window as any).gtag) {
(window as any).gtag('consent', 'update', {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new components/AnalyticsInitializer.tsx file to set the default consent state, while keeping the original code to update (enable/disable) analytics.


// Google Analytics (gtag.js)
if (typeof window !== 'undefined' && (window as any).gtag) {
(window as any).gtag('consent', 'update', {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new components/AnalyticsInitializer.tsx file to set the default consent state, while keeping the original code to update (enable/disable) analytics.

@b95702041 b95702041 force-pushed the develop branch 3 times, most recently from 3a590ab to 667cf6d Compare October 19, 2025 21:40
@jack482653
Copy link
Collaborator

It still collects data after I reject cookies
CleanShot 2025-10-21 at 18 42 16

app/layout.tsx Outdated
import "@fortawesome/fontawesome-svg-core/styles.css";
import Hero from "@/components/Hero";
import CookieBanner from "@/components/CookieBanner";
import AnalyticsInitializer from "@/components/AnalyticsInitializer"; // Add this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnalyticsInitializer looks not used here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I added in app/layout.tsx.

- 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
@chestercheng
Copy link
Contributor

@b95702041 thanks for the contribution.
Unless it's absolutely necessary, please avoid using force-push, it makes the PR difficult to review.

@c1ydehhx could you please take a look at this PR? I believe we can also port this to swportal so that we can fully control the cookie consent banner style.

@chestercheng
Copy link
Contributor

It still collects data after I reject cookies CleanShot 2025-10-21 at 18 42 16

I got the same result… it looks like the default consent state isn't working.
@jack482653 maybe we should move this before the GA script

className="tw:px-6 tw:py-2.5 tw:bg-rose-500 tw:text-white tw:rounded-full tw:font-semibold tw:text-base hover:tw:bg-rose-700 tw:transition-colors"
>
Accept All
</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d prefer to use components/Button.tsx instead of hard-coding the button element.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the CookieBanner.tsx and Button.tsx.

- 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
@b95702041
Copy link
Author

After rejection, it still sends a request, but it's anonymous (cookieless ping). From the Network tab (filtered by "collect"), parameters show: pscdl = denied, gcs = G100, npa = 1 (personalized ads not allowed), seg = 0 (session not tracked).
Per Google's documentation: "While consent is denied, the Google tags send cookieless pings."

@jack482653 jack482653 mentioned this pull request Dec 14, 2025
5 tasks
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.

3 participants