-
-
Notifications
You must be signed in to change notification settings - Fork 368
Add c15t consent management #1009
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
Open
tannerlinsley
wants to merge
1
commit into
main
Choose a base branch
from
taren/c15t-consent-management
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import * as React from 'react' | ||
| import type { ReactNode } from 'react' | ||
| import { | ||
| ConsentBanner, | ||
| ConsentDialog, | ||
| ConsentManagerProvider, | ||
| type ConsentManagerOptions, | ||
| } from '@c15t/react' | ||
| import { gtag } from '@c15t/scripts/google-tag' | ||
|
|
||
| const C15T_BACKEND_URL = 'https://eager-kayak-phobos-tanstack-com.inth.app' | ||
| const GOOGLE_ANALYTICS_ID = 'G-JMT1Z50SPS' | ||
| const LEGAL_LINKS: Array<'privacyPolicy' | 'termsOfService'> = [ | ||
| 'privacyPolicy', | ||
| 'termsOfService', | ||
| ] | ||
|
|
||
| const consentManagerOptions = { | ||
| mode: 'hosted', | ||
| backendURL: C15T_BACKEND_URL, | ||
| consentCategories: ['necessary', 'measurement'], | ||
| overrides: import.meta.env.DEV ? { country: 'DE' } : undefined, | ||
| legalLinks: { | ||
| privacyPolicy: { | ||
| href: '/privacy', | ||
| target: '_self', | ||
| }, | ||
| termsOfService: { | ||
| href: '/terms', | ||
| target: '_self', | ||
| }, | ||
| }, | ||
| scripts: [ | ||
| gtag({ | ||
| id: GOOGLE_ANALYTICS_ID, | ||
| category: 'measurement', | ||
| }), | ||
| ], | ||
| } satisfies ConsentManagerOptions | ||
|
|
||
| export function ConsentManager({ | ||
| children, | ||
| showControls = true, | ||
| }: { | ||
| children: ReactNode | ||
| showControls?: boolean | ||
| }) { | ||
| const [hasMounted, setHasMounted] = React.useState(false) | ||
|
|
||
| React.useEffect(() => { | ||
| setHasMounted(true) | ||
| }, []) | ||
|
|
||
| // c15t injects runtime theme styles; mount after hydration so Start's SSR | ||
| // markup stays byte-stable. | ||
| if (!hasMounted) { | ||
| return <>{children}</> | ||
| } | ||
|
|
||
| return ( | ||
| <ConsentManagerProvider options={consentManagerOptions}> | ||
| {showControls ? ( | ||
| <> | ||
| <ConsentBanner legalLinks={LEGAL_LINKS} /> | ||
| <ConsentDialog legalLinks={LEGAL_LINKS} /> | ||
| </> | ||
| ) : null} | ||
| {children} | ||
| </ConsentManagerProvider> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| @import 'tailwindcss'; | ||
| @import '@c15t/react/styles.css'; | ||
|
|
||
| @plugin "@tailwindcss/typography"; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🩺 Stability & Availability | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 1290
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 6447
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 50377
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 5647
🌐 Web query:
c15t React provider mount first render consent manager hydration gtag alwaysLoad docs💡 Result:
In the c15t consent manager system, the 'alwaysLoad' option is used for third-party scripts that must be present from the start of the page load, such as Google Tag Manager or gtag.js [1][2][3]. When 'alwaysLoad' is set to true, the script is injected into the DOM immediately, regardless of the user's current consent state [1][2]. Regarding the behavior during mount and hydration: 1. Consent Initialization: When the ConsentManagerProvider mounts, it creates a cached consent runtime and reads stored consent from the browser (e.g., localStorage/cookies) [4]. 2. Google Tag Handling: For 'alwaysLoad' integrations like gtag.js, c15t automatically initializes the vendor with Consent Mode v2 defaults set to 'denied' before any user interaction occurs [2][3]. This ensures that while the script is present, data transmission is suppressed until explicit consent is granted [2][3]. 3. Hydration and First Render: To prevent hydration mismatches or consent banner flashes, it is recommended to use server-side utilities to fetch initial consent data (e.g., 'fetchSSRData' or 'fetchInitialData') and pass this as a promise to the provider's 'ssrData' option [5][6][7]. This allows the provider to initialize with the correct state on the first render rather than waiting for a client-side API fetch [4][7]. 4. Stability: Mounting the provider as high as possible in the React tree is advised to avoid remounting during client-side navigation, which keeps the consent state stable [8]. You do not need to manually wrap calls to vendor SDKs (like gtag) in consent checks if they are correctly integrated via 'alwaysLoad', as the vendor's internal Consent Mode API handles the suppression [2][3]. If the integration is not 'alwaysLoad', the script will remain blocked until the relevant consent category is granted [1][9].
Citations:
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 8987
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 386
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 2079
Keep
ConsentManagerProvidermounted from the first render. The early return defers c15t initialization until after hydration, so the consent runtime and Google TagalwaysLoadsetup start late. Move only the hydration-specific workaround intoConsentBanner/ConsentDialog, or use c15t’s SSR data path.🤖 Prompt for AI Agents