Skip to content

🍪 fix: Load Google Tag Manager Only After Analytics Consent - #16999

Merged
berry-13 merged 55 commits into
devfrom
berry-13/gtm-consent
Oct 12, 2026
Merged

berry-13 merged 55 commits into
devfrom
berry-13/gtm-consent

Conversation

@berry-13

@berry-13 berry-13 commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When ANALYTICS_GTM_ID was set, Google Tag Manager initialized as soon as the chat footer or chat route mounted, for signed-in users and shared-link viewers alike, with no consent check.

A single useAnalytics hook now owns initialization and loads GTM only after the viewer accepts a non-modal consent banner. The banner is a labelled region with Decline and Allow analytics at equal weight; it does not take focus and appears only when a GTM id is configured and no choice has been made. It mounts in the signed-in layout and on shared links. The choice is stored per browser and can be changed in Settings > Data controls; withdrawing consent pushes a consent-mode update to a loaded container and takes full effect after a reload. Deployments without ANALYTICS_GTM_ID see no change.

Stacked on #16998.

Type of change

  • Bug fix
  • Feature

Testing

Tested environments/configuration:

  • ANALYTICS_GTM_ID=GTM-TEST123, Chromium, light and dark, 1280px and 390px.

Automated tests:

  • Added client/src/components/System/__tests__/AnalyticsConsent.spec.tsx (8 tests) and client/src/components/Nav/SettingsTabs/Data/__tests__/AnalyticsConsent.spec.tsx (3 tests); updated registry, sidebar, footer and useAppStartup specs. 17 suites, 138 tests passed.
  • Client typecheck, npx eslint, npx prettier --check and sort-imports on changed files: clean.
  • Manual: no request to googletagmanager.com before consent; gtm.js?id=GTM-TEST123 loads right after Allow analytics and on reload, with no banner shown again.

Screenshots / recordings

New surface, so there is no before.

Light Dark
Banner light Banner dark

Banner at phone width

Risk / compatibility

GTM now loads on every signed-in route once consent is granted, not only the chat route. At phone width the banner covers the composer until the viewer answers. Operators who run a consent platform inside their GTM container will now see LibreChat's banner first.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • Required documentation PR: N/A

@berry-13 berry-13 changed the title berry-13/gtm-consent 🍪 fix: Load Google Tag Manager Only After Analytics Consent Oct 11, 2026
@berry-13
berry-13 marked this pull request as ready for review October 11, 2026 21:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T13:21:48.700315Z b9fb893 New commits
🔒 Security Review ✅ Completed 2026-10-11T21:58:48.779005Z 73d3840 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73d3840c02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/components/Share/ShareView.tsx
Comment thread client/src/hooks/Config/useAnalytics.ts Outdated
@berry-13
berry-13 force-pushed the berry-13/gtm-consent branch from 41f82e0 to af26db5 Compare October 12, 2026 12:12
Google Tag Manager initialized as soon as the chat footer or the chat route mounted whenever ANALYTICS_GTM_ID was set, for signed-in users and shared-link viewers alike, with no consent check. A single useAnalytics hook now owns initialization and loads the container only after the viewer grants consent, recorded in a persisted Jotai atom. A non-modal banner asks for that consent in the signed-in layout and on shared links, and a Data controls toggle changes it later; withdrawing consent pushes a consent mode update to a loaded container and completes on reload.
@berry-13
berry-13 force-pushed the berry-13/gtm-consent branch from af26db5 to 3708416 Compare October 12, 2026 12:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37084164fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Config/useAnalytics.ts Outdated
Base automatically changed from berry-13/tts-cache-cleanup to berry-13/plugin-auth-encrypt-v3 October 12, 2026 13:59
@berry-13
berry-13 added this pull request to stack #17022 October 12, 2026 13:59
Base automatically changed from berry-13/plugin-auth-encrypt-v3 to dev October 12, 2026 14:33
@berry-13
berry-13 merged commit c3989de into dev Oct 12, 2026
31 checks passed
@berry-13
berry-13 deleted the berry-13/gtm-consent branch October 12, 2026 14:33
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.

1 participant