Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

📊 feat: Let Deployments Skip the Analytics Consent Prompt (#17552)

Marco Beretta74e7252c3edb
diff --git a/client/src/components/Nav/Settings/context.tsx b/client/src/components/Nav/Settings/context.tsx
index 66e90f5cb9..6e9b9e5f0b 100644
--- a/client/src/components/Nav/Settings/context.tsx
+++ b/client/src/components/Nav/Settings/context.tsx
@@ -62,7 +62,10 @@ export function useSettingsContext(): SettingsContextValue {
replyConfigLoaded && replyNotificationsConfig?.desktop !== false;
const replyNotificationSoundAllowed =
replyConfigLoaded && replyNotificationsConfig?.sound !== false;
- const analyticsConfigured = hasAnalyticsGtmId(startupConfig?.analyticsGtmId);
+ /* No toggle when the deployment granted consent for everyone: there is no choice to change. */
+ const analyticsConfigured =
+ hasAnalyticsGtmId(startupConfig?.analyticsGtmId) &&
+ startupConfig?.interface?.analyticsConsent !== false;
const hasRemoteAgentsBool = hasRemoteAgents === true;
const hasMultiConvoBool = hasMultiConvo === true;
const hasPromptsBool = hasPrompts === true;
diff --git a/client/src/components/Share/ShareView.tsx b/client/src/components/Share/ShareView.tsx
index 94302dcc62..e0d26f7da3 100644
--- a/client/src/components/Share/ShareView.tsx
+++ b/client/src/components/Share/ShareView.tsx
@@ -208,7 +208,10 @@ function SharedView() {
langfuseSessionUrl={data.langfuseSessionUrl}
onContinue={handleContinue}
isContinuing={forkShare.isLoading}
- analyticsConfigured={hasAnalyticsGtmId(config?.analyticsGtmId)}
+ analyticsConfigured={
+ hasAnalyticsGtmId(config?.analyticsGtmId) &&
+ config?.interface?.analyticsConsent !== false
+ }
/>
<ShareMessagesProvider messages={data.messages}>
<MessagesView messagesTree={messagesTree} conversationId={SHARED_CONVO_KEY} />
@@ -240,7 +243,10 @@ function SharedView() {
<div className="text-text-primary relative flex h-full min-h-0 flex-col" role="presentation">
{content}
{footer}
- <AnalyticsConsent gtmId={config?.analyticsGtmId} />
+ <AnalyticsConsent
+ gtmId={config?.analyticsGtmId}
+ consentRequired={config?.interface?.analyticsConsent !== false}
+ />
</div>
</div>
);
diff --git a/client/src/components/System/AnalyticsConsent.tsx b/client/src/components/System/AnalyticsConsent.tsx
index 5c0fbb6b4d..f70351de03 100644
--- a/client/src/components/System/AnalyticsConsent.tsx
+++ b/client/src/components/System/AnalyticsConsent.tsx
@@ -6,6 +6,9 @@ import { useLocalize } from '~/hooks';
type AnalyticsConsentProps = {
/** The deployment's `ANALYTICS_GTM_ID`, from the startup config of the page shell. */
gtmId?: string | null;
+ /** False when the deployment set `interface.analyticsConsent: false`: the
+ * container loads without asking. */
+ consentRequired?: boolean;
};
/**
@@ -14,8 +17,8 @@ type AnalyticsConsentProps = {
* the bottom of the viewport: it does not take focus or block the page, and
* either answer hides it. The choice can be changed later in Settings.
*/
-export default function AnalyticsConsent({ gtmId }: AnalyticsConsentProps) {
- const { enabled, consent, setConsent } = useAnalytics(gtmId);
+export default function AnalyticsConsent({ gtmId, consentRequired }: AnalyticsConsentProps) {
+ const { enabled, consent, setConsent } = useAnalytics(gtmId, consentRequired);
if (!enabled || consent != null) {
return null;
diff --git a/client/src/components/System/__tests__/AnalyticsConsent.spec.tsx b/client/src/components/System/__tests__/AnalyticsConsent.spec.tsx
index 5d59535e31..1578d84e76 100644
--- a/client/src/components/System/__tests__/AnalyticsConsent.spec.tsx
+++ b/client/src/components/System/__tests__/AnalyticsConsent.spec.tsx
@@ -15,10 +15,10 @@ jest.mock('~/hooks', () => ({
const initialize = TagManager.initialize as jest.Mock;
-const renderConsent = (gtmId?: string | null) =>
+const renderConsent = (gtmId?: string | null, consentRequired?: boolean) =>
render(
<Provider>
- <AnalyticsConsent gtmId={gtmId} />
+ <AnalyticsConsent gtmId={gtmId} consentRequired={consentRequired} />
</Provider>,
);
@@ -187,4 +187,18 @@ describe('AnalyticsConsent', () => {
expect(startEvents).toHaveLength(1);
document.querySelector('script[src*="gtm.js"]')?.remove();
});
+
+ it('loads GTM without a banner when the deployment does not require consent', () => {
+ localStorage.setItem('analyticsConsent', JSON.stringify('denied'));
+ renderConsent('GTM-TEST', false);
+ expect(getBanner()).not.toBeInTheDocument();
+ expect(initialize).toHaveBeenCalledTimes(1);
+ expect(initialize).toHaveBeenCalledWith({ gtmId: 'GTM-TEST' });
+ });
+
+ it('still never loads GTM without a container when consent is not required', () => {
+ renderConsent(undefined, false);
+ expect(getBanner()).not.toBeInTheDocument();
+ expect(initialize).not.toHaveBeenCalled();
+ });
});
diff --git a/client/src/hooks/Config/useAnalytics.ts b/client/src/hooks/Config/useAnalytics.ts
index 56ee711447..c8d9582c06 100644
--- a/client/src/hooks/Config/useAnalytics.ts
+++ b/client/src/hooks/Config/useAnalytics.ts
@@ -78,11 +78,14 @@ function initializeContainer(gtmId: string) {
/**
* The only place Google Tag Manager is initialized. It loads when the
* deployment set `ANALYTICS_GTM_ID` and the viewer granted consent, never before.
+ * With `consentRequired` false (`interface.analyticsConsent: false`) the
+ * deployment has granted it for every viewer and the stored answer is ignored.
* Mount it once per page shell (the signed-in layout and the shared-link view).
*/
-export default function useAnalytics(gtmId: string | null | undefined) {
- const [consent, setConsent] = useAtom(analyticsConsentAtom);
+export default function useAnalytics(gtmId: string | null | undefined, consentRequired = true) {
+ const [storedConsent, setConsent] = useAtom(analyticsConsentAtom);
const enabled = hasAnalyticsGtmId(gtmId);
+ const consent = consentRequired ? storedConsent : 'granted';
useEffect(() => {
if (!enabled || consent !== 'granted') {
diff --git a/client/src/routes/Root.tsx b/client/src/routes/Root.tsx
index 0cc4d41ea1..05247a3387 100644
--- a/client/src/routes/Root.tsx
+++ b/client/src/routes/Root.tsx
@@ -248,7 +248,10 @@ function RootLayout() {
<KeyboardShortcutsProvider />
<ReplyNotifications />
<MessagesRetention />
- <AnalyticsConsent gtmId={config?.analyticsGtmId} />
+ <AnalyticsConsent
+ gtmId={config?.analyticsGtmId}
+ consentRequired={config?.interface?.analyticsConsent !== false}
+ />
</AgentsMapContext.Provider>
{config?.interface?.termsOfService?.modalAcceptance === true && (
<TermsAndConditionsModal
diff --git a/e2e/specs/mock/scenarios/analytics-consent.spec.ts b/e2e/specs/mock/scenarios/analytics-consent.spec.ts
index 66b83ab3f4..b4a5da59c3 100644
--- a/e2e/specs/mock/scenarios/analytics-consent.spec.ts
+++ b/e2e/specs/mock/scenarios/analytics-consent.spec.ts
@@ -43,13 +43,23 @@ async function expectNoGtm(page: Page, gtm: Probe, expected: number) {
await expect(page.locator('script[src*="googletagmanager.com"]')).toHaveCount(0);
}
-async function serveGtmId(page: Page, gtmId: string | null = GTM_ID): Promise<Probe> {
+/** `consentRequired: false` stands in for `interface.analyticsConsent: false` in the
+ * deployment's yaml, layered the same way as the id. */
+async function serveGtmId(
+ page: Page,
+ gtmId: string | null = GTM_ID,
+ { consentRequired = true }: { consentRequired?: boolean } = {},
+): Promise<Probe> {
const withId = (payload: Record<string, unknown>) => {
const served = { ...payload };
delete served.analyticsGtmId;
if (gtmId !== null) {
served.analyticsGtmId = gtmId;
}
+ if (!consentRequired) {
+ const iface = (served.interface ?? {}) as Record<string, unknown>;
+ served.interface = { ...iface, analyticsConsent: false };
+ }
return served;
};
await page.route(
@@ -245,4 +255,47 @@ test.describe('analytics consent', () => {
await expect(dialog.getByRole('switch', { name: 'Allow analytics' })).toHaveCount(0);
expect(gtm.requests()).toBe(0);
});
+
+ test('a deployment that settles consent itself loads Google Tag Manager without asking @scenario:consent-disabled-loads-gtm-without-prompt', async ({
+ page,
+ }) => {
+ test.setTimeout(90000);
+ /** An answer stored before the operator turned the prompt off no longer applies. */
+ await page.addInitScript(() =>
+ window.localStorage.setItem('analyticsConsent', JSON.stringify('denied')),
+ );
+ const gtm = await serveGtmId(page, GTM_ID, { consentRequired: false });
+ await openNewChat(page);
+
+ await expect.poll(gtm.requests).toBeGreaterThan(0);
+ await expect(banner(page)).toHaveCount(0);
+
+ /** There is no choice left for the viewer, so Settings offers none. */
+ await openSettings(page);
+ const dialog = page.getByRole('dialog');
+ await dialog.getByRole('tab', { name: 'Data & Privacy' }).click();
+ await expect(dialog.getByRole('button', { name: 'Archive all chats' })).toBeVisible();
+ await expect(dialog.getByRole('switch', { name: 'Allow analytics' })).toHaveCount(0);
+ });
+
+ test('a shared link loads Google Tag Manager without asking when the deployment settles consent @scenario:shared-link-consent-disabled-loads-gtm', async ({
+ page,
+ }) => {
+ test.setTimeout(120000);
+ await serveGtmId(page, null);
+ const shareId = await createSharedLink(page);
+ await page.unrouteAll({ behavior: 'wait' });
+
+ const gtm = await serveGtmId(page, GTM_ID, { consentRequired: false });
+ await page.goto(`/share/${shareId}`, { timeout: 15000 });
+ await expect(page.getByTestId('messages-view')).toBeVisible({ timeout: 20000 });
+ await expect.poll(gtm.requests).toBeGreaterThan(0);
+ await expect(banner(page)).toHaveCount(0);
+
+ await page.getByRole('button', { name: 'Settings', exact: true }).click();
+ await expect(page.getByRole('dialog')).toBeVisible();
+ await expect(
+ page.getByRole('dialog').getByRole('switch', { name: 'Allow analytics' }),
+ ).toHaveCount(0);
+ });
});
diff --git a/librechat.example.yaml b/librechat.example.yaml
index 498b41582f..c0bab9b61f 100644
--- a/librechat.example.yaml
+++ b/librechat.example.yaml
@@ -301,6 +301,9 @@ interface:
# Allow the artifacts pane to be moved into its own browser window
# (desktop only; the mobile sheet is unaffected). Default: true.
artifactUndocking: true
+ # Ask each viewer before loading Google Tag Manager (ANALYTICS_GTM_ID).
+ # Set false when the deployment settles consent itself, e.g. internal use. Default: true.
+ # analyticsConsent: true
agents:
use: true
create: true
diff --git a/packages/api/src/shared-links/config.test.ts b/packages/api/src/shared-links/config.test.ts
index 2f85430098..b596452f99 100644
--- a/packages/api/src/shared-links/config.test.ts
+++ b/packages/api/src/shared-links/config.test.ts
@@ -242,6 +242,19 @@ describe('buildSharedLinkStartupPayload', () => {
expect(buildSharedLinkStartupPayload(config, {}).interface).toEqual({ theme: 'clickhouse' });
});
+ it('passes a consent-free analytics setting to the share view', () => {
+ const payload = buildSharedLinkStartupPayload(
+ appConfig({ interfaceConfig: { analyticsConsent: false } }),
+ { ANALYTICS_GTM_ID: 'GTM-XYZ' },
+ );
+
+ expect(payload).toEqual({
+ appTitle: 'LibreChat',
+ analyticsGtmId: 'GTM-XYZ',
+ interface: { analyticsConsent: false },
+ });
+ });
+
it('defaults the app title and omits unrelated interface config', () => {
const payload = buildSharedLinkStartupPayload(
appConfig({ interfaceConfig: { modelSelect: true } }),
diff --git a/packages/api/src/shared-links/config.ts b/packages/api/src/shared-links/config.ts
index e53206b545..9a27ce2944 100644
--- a/packages/api/src/shared-links/config.ts
+++ b/packages/api/src/shared-links/config.ts
@@ -104,8 +104,13 @@ export function buildSharedLinkStartupPayload(
payload.customFooter = env.CUSTOM_FOOTER;
}
- const { privacyPolicy, termsOfService, codeHighlightThrottleMs, artifactUndocking } =
- withSafePolicyLinks(appConfig?.interfaceConfig) ?? {};
+ const {
+ privacyPolicy,
+ termsOfService,
+ codeHighlightThrottleMs,
+ artifactUndocking,
+ analyticsConsent,
+ } = withSafePolicyLinks(appConfig?.interfaceConfig) ?? {};
const parsedTheme = deploymentThemeSchema.safeParse(appConfig?.interfaceConfig?.theme);
const theme = parsedTheme.success ? parsedTheme.data : undefined;
/* A shared conversation shows the same artifacts pane, so it needs the same
@@ -115,7 +120,8 @@ export function buildSharedLinkStartupPayload(
termsOfService ||
codeHighlightThrottleMs != null ||
theme ||
- artifactUndocking === false
+ artifactUndocking === false ||
+ analyticsConsent === false
) {
payload.interface = {
...(codeHighlightThrottleMs != null ? { codeHighlightThrottleMs } : {}),
@@ -123,6 +129,7 @@ export function buildSharedLinkStartupPayload(
...(termsOfService ? { termsOfService } : {}),
...(theme ? { theme } : {}),
...(artifactUndocking === false ? { artifactUndocking } : {}),
+ ...(analyticsConsent === false ? { analyticsConsent } : {}),
};
}
diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts
index 049fbb2e19..81829127d6 100644
--- a/packages/data-provider/src/config.ts
+++ b/packages/data-provider/src/config.ts
@@ -3179,6 +3179,11 @@ export const interfaceSchema = z
* default; a deployment that cannot use popups can turn it off and keep
* the docked pane. */
artifactUndocking: z.boolean().optional(),
+ /** Asks each viewer for consent before Google Tag Manager (`ANALYTICS_GTM_ID`)
+ * loads. A deployment that settles consent itself, such as an internal one
+ * covered by its own policy, can set false to load the container without the
+ * banner or the Settings toggle. */
+ analyticsConsent: z.boolean().optional(),
feedback: z.boolean().optional(),
currency: z
.object({
@@ -3789,7 +3794,12 @@ export type TStartupConfig = {
export type TSharedLinkStartupInterface = Pick<
Partial<TInterfaceConfig>,
- 'privacyPolicy' | 'termsOfService' | 'codeHighlightThrottleMs' | 'theme' | 'artifactUndocking'
+ | 'privacyPolicy'
+ | 'termsOfService'
+ | 'codeHighlightThrottleMs'
+ | 'theme'
+ | 'artifactUndocking'
+ | 'analyticsConsent'
>;
export type TSharedLinkStartupConfig = Pick<TStartupConfig, 'appTitle'> &
diff --git a/packages/data-schemas/src/app/interface.spec.ts b/packages/data-schemas/src/app/interface.spec.ts
index bbdbfb02ef..9bac6955e4 100644
--- a/packages/data-schemas/src/app/interface.spec.ts
+++ b/packages/data-schemas/src/app/interface.spec.ts
@@ -236,6 +236,24 @@ describe('loadDefaultInterface', () => {
expect(interfaceConfig?.artifactUndocking).toBe(true);
});
+ it('carries a disabled analytics consent prompt to the clients', async () => {
+ const interfaceConfig = await loadDefaultInterface({
+ config: { interface: { analyticsConsent: false } },
+ configDefaults: getConfigDefaults(),
+ });
+
+ expect(interfaceConfig?.analyticsConsent).toBe(false);
+ });
+
+ it('leaves analytics consent unset so clients keep asking', async () => {
+ const interfaceConfig = await loadDefaultInterface({
+ config: {},
+ configDefaults: getConfigDefaults(),
+ });
+
+ expect(interfaceConfig).not.toHaveProperty('analyticsConsent');
+ });
+
it('preserves enabled build info config', async () => {
const config: Partial<TCustomConfig> = {
interface: {
diff --git a/packages/data-schemas/src/app/interface.ts b/packages/data-schemas/src/app/interface.ts
index 8261eb77a2..08b9d20ec0 100644
--- a/packages/data-schemas/src/app/interface.ts
+++ b/packages/data-schemas/src/app/interface.ts
@@ -100,6 +100,7 @@ export async function loadDefaultInterface({
mascot: interfaceConfig?.mascot ?? defaults.mascot,
contextUsage: interfaceConfig?.contextUsage ?? defaults.contextUsage,
artifactUndocking: interfaceConfig?.artifactUndocking ?? defaults.artifactUndocking,
+ analyticsConsent: interfaceConfig?.analyticsConsent,
contextCost: interfaceConfig?.contextCost ?? defaults.contextCost,
feedback: interfaceConfig?.feedback ?? defaults.feedback,
currency: interfaceConfig?.currency ?? defaults.currency,