Skip to content

feat(third-parties): add consent management support to GoogleTagManager #80719

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
wants to merge 6 commits into
base: canary
Choose a base branch
from

Conversation

NimaC
Copy link

@NimaC NimaC commented Jun 20, 2025

What?

Adds consent management support to GoogleTagManager component by making it more flexible to support different CMP integration approaches.

Why?

Component Inflexibility: The current GoogleTagManager component only supports standard script execution, but some CMPs require additional script attributes for integration. This forces developers to abandon the Next.js component for manual script injection.

CMP Integration Requirements: Some CMPs require:

  • type="text/plain" to prevent execution until consent
  • Platform-specific data-* attributes for identification

Known Compatible CMPs:

  • Cookiebot: data-cookieconsent="statistics"
  • Usercentrics: data-usercentrics="Google Tag Manager"
  • Others: Any CMP using similar HTML attribute patterns

How?

API (Backward Compatible):

// Standard GTM (unchanged)
<GoogleTagManager gtmId="GTM-XYZ" />

// With CMP integration
<GoogleTagManager
  gtmId="GTM-XYZ"
  type="text/plain"
  data-usercentrics="Google Tag Manager"
/>

Implementation:

  • Added type prop for script execution control
  • Added support for data-* attributes for CMP integration
  • Both initialization and external scripts receive same attributes
  • Zero breaking changes

Benefits

  • Enables CMP Integration: Supports CMPs that require script-level attributes
  • Component Flexibility: Developers can use Next.js component with their chosen CMP
  • Future-Proof: Works with any CMP using standard HTML attributes
  • Developer Experience: Clean API following React patterns

- Add type prop to control script execution (application/javascript | text/plain)
- Add support for data-* attributes for CMP platform integration
- Support all major CMP platforms (Usercentrics, OneTrust, Cookiebot, Didomi)
- Add comprehensive E2E tests for consent management scenarios
- Update documentation with consent management examples
- Maintain full backward compatibility

Closes #XXXXX
@ijjk ijjk added the tests label Jun 20, 2025
@ijjk
Copy link
Member

ijjk commented Jun 20, 2025

Allow CI Workflow Run

  • approve CI run for commit: 961ae80

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

…roach

- Replace verbose individual tests with concise loop-based testing
- Use structured test data for better maintainability
- Reduce code duplication while maintaining comprehensive coverage
- Improve readability and make it easier to add new CMP scenarios
@NimaC NimaC force-pushed the feat/gtm-consent-management branch from 2f03f8c to 3d4be75 Compare June 20, 2025 13:38
NimaC added 2 commits June 20, 2025 15:39
…ative case

- Reduce test complexity by using one CMP platform (Usercentrics) as representative
- Remove redundant test cases since all CMPs follow the same pattern
- Focus on testing core functionality: type prop and data-* attributes
- Improve test maintainability and execution speed
- Maintain comprehensive coverage of the feature being tested
@NimaC NimaC force-pushed the feat/gtm-consent-management branch from 7ee3691 to 9150e49 Compare June 20, 2025 13:45
NimaC added 2 commits June 20, 2025 15:49
- Remove redundant standard GTM test from gtm-consent test case
- Focus gtm-consent test only on new consent management functionality
- Maintain proper separation of concerns between gtm.js and gtm-consent.js
- Standard GTM behavior is already covered by existing gtm test
- Consent management test now only validates type=text/plain and data-* attributes
…tative case

- Replace multiple verbose code examples with one clear Usercentrics example
- List other CMP platforms with their data attributes in concise format
- Reduce documentation length while maintaining comprehensive coverage
- Focus on the pattern rather than repetitive code blocks
- Improve readability and maintainability of documentation
@NimaC
Copy link
Author

NimaC commented Jun 23, 2025

Hey @ijjk, thanks for reviewing this PR, its ready for a CI run now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants