Skip to content

Conversation

@thabofletcher
Copy link
Contributor

@thabofletcher thabofletcher commented Nov 17, 2025

Ticket [ENg-1968]

Description Of Changes

Introduces the gcm() integrataion to support Google Consent Mode v2 in situations where Google Tag Manager is not in use (our current gtm() integration support GCMv2 through the use of a GTM template)

Code Changes

  • Adds the gcm integration and tests

Steps to Confirm

  1. Find a site with a sloppy OneTrust integration and Gtag that starts with it on by default (I used grainger.com)
  2. Check window.dataLayer to see the current gtag events
  3. Inject Fides.js from your local env on the page using chrome tools or bookmarklet
  4. Run Fides.gcm() (this should work if you have default categories like essetnial, marketing, adverstising, etc from the default mappings)
  5. Check the dataLayer again - you should see consent update events setting things to your envs defaults
  6. Run Fides.showModal() and change a few thing, then rechck dataLayer to make sure another consent update event was logged

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

- Renamed gtag-consent to gcm for better naming consistency
- Updated default mapping to include data_sales_and_sharing and marketing consent keys (per JJ's PR feedback)
- Both map to [ad_storage, ad_personalization, ad_user_data] for comprehensive Google ad consent
- Made integration resilient to missing consent keys - only processes keys present in both mapping and Fides consent
- Added comprehensive JSDoc documentation with usage examples
- Integrated into Fides global API (Fides.gcm())

Addresses feedback from PR #6950
- Replaced all console.log, console.warn, console.error calls with fidesDebugger
- Removed debug option from GcmOptions interface
- Removed debug parameter from buildGoogleConsent and pushConsentToGtag functions
- Updated JSDoc to remove references to debug flag
- Matches the pattern used in aep integration for consistent debugging approach
- fidesDebugger handles debug flag internally via Fides.options.debug
Test coverage includes:
- Default purpose mapping with all standard consent keys (analytics, advertising, functional, data_sales_and_sharing, marketing)
- Custom purpose mapping with various configurations
- Consent granted vs denied states
- Graceful degradation when consent keys are missing from Fides
- Multiple consent keys mapping to same Google type (last write wins)
- Single consent key mapping to multiple Google types
- Edge cases: empty consent, undefined values, falsy values, truthy non-boolean values
- gtag not loaded scenario (graceful failure)
- Event subscription (FidesReady, FidesUpdated)
- Immediate consent push when Fides already initialized
- consent() API (returns null as gtag doesn't provide read API)
- All seven Google consent types supported

Follows same test patterns as aep.test.ts but excludes debug logging tests per user request
@vercel
Copy link

vercel bot commented Nov 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
fides-plus-nightly Ready Ready Preview Comment Nov 17, 2025 10:30pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
fides-privacy-center Ignored Ignored Nov 17, 2025 10:30pm

The test was failing because event listeners from previous tests accumulate.
Instead of checking that gtag was never called (which fails due to accumulated listeners),
we verify that gtag was never called with an empty consent object.

This tests the actual behavior: when mapping has empty arrays, the integration
correctly skips calling gtag (returns early when Object.keys(googleConsent).length === 0).

All 23 tests now pass.
@thabofletcher thabofletcher force-pushed the ENG-1968-google-consent-mode branch from 567689d to 65d9e69 Compare November 17, 2025 18:05
Regenerated TypeDoc documentation to include Fides.gcm() API
@thabofletcher thabofletcher mentioned this pull request Nov 17, 2025
thabofletcher and others added 4 commits November 17, 2025 13:22
Co-authored-by: Jason Gill <jason.gill@ethyca.com>
Instead of gtag?: (...args: any[]) => void, define:
- GtagConsentCommand: specific signature for consent commands we use
- GtagFunction: intersection type for consent + general gtag calls

Provides proper type safety while allowing gtag to be called with other
commands outside our integration (e.g., event tracking, config, etc.)
@thabofletcher thabofletcher marked this pull request as ready for review November 17, 2025 22:05
@thabofletcher thabofletcher requested a review from a team as a code owner November 17, 2025 22:05
@thabofletcher thabofletcher requested review from speaker-ender and removed request for a team and speaker-ender November 17, 2025 22:05
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 17, 2025

Greptile Summary

  • Adds new gcm() integration to FidesJS that syncs consent preferences with Google Consent Mode v2 via gtag()
  • Includes comprehensive test suite with edge case coverage and graceful handling of missing consent keys

Confidence Score: 4/5

  • This PR is safe to merge with one minor type declaration fix needed
  • The implementation is solid with excellent test coverage and follows established patterns from other integrations. Score of 4 reflects the missing fidesDebugger global declaration which will cause TypeScript compilation errors
  • Pay close attention to clients/fides-js/src/integrations/gcm.ts - needs the global fidesDebugger declaration added

Important Files Changed

Filename Overview
clients/fides-js/src/integrations/gcm.ts New Google Consent Mode v2 integration with comprehensive documentation and graceful error handling
clients/fides-js/tests/integrations/gcm.test.ts Comprehensive test coverage for gcm integration including edge cases, custom mappings, and error scenarios

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

Copy link
Contributor

@gilluminate gilluminate left a comment

Choose a reason for hiding this comment

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

Looking good to me! Tested on granger.com and was able to see the dataLayer working as expected

Image

@thabofletcher thabofletcher added this pull request to the merge queue Nov 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@thabofletcher thabofletcher added this pull request to the merge queue Nov 18, 2025
Merged via the queue into main with commit 8a0e68f Nov 18, 2025
42 of 43 checks passed
@thabofletcher thabofletcher deleted the ENG-1968-google-consent-mode branch November 18, 2025 17:06
jjdaurora pushed a commit that referenced this pull request Dec 5, 2025
Co-authored-by: Jason Gill <jason.gill@ethyca.com>
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