-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add cookie consent banner #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
b95702041
commented
Oct 18, 2025
- Add CookieBanner component with website styling
- Add cookieUtils for consent management and analytics
- Update layout.tsx to integrate CookieBanner
✅ Deploy Preview for swconf2025 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
components/cookieUtils.ts
Outdated
|
|
||
| // Google Analytics (gtag.js) | ||
| if (typeof window !== 'undefined' && (window as any).gtag) { | ||
| (window as any).gtag('consent', 'update', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developers.google.com/tag-platform/gtagjs/reference#consent
<consent_arg> should use default
There was a problem hiding this comment.
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.
components/cookieUtils.ts
Outdated
|
|
||
| // Google Analytics (gtag.js) | ||
| if (typeof window !== 'undefined' && (window as any).gtag) { | ||
| (window as any).gtag('consent', 'update', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
3a590ab to
667cf6d
Compare
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
@b95702041 thanks for the contribution. @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. |
|
I got the same result… it looks like the default consent state isn't working. |
components/CookieBanner.tsx
Outdated
| 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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
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). |

