From 2cb5f440dfc58aaaa5c18b15a61f4577f7664728 Mon Sep 17 00:00:00 2001 From: Donald Merand Date: Fri, 8 May 2026 16:47:16 -0400 Subject: [PATCH] Add analytics opt-out that matches ai-toolkit --- .changeset/quiet-otters-wave.md | 5 ++++ .../generated/generated_static_pages.json | 2 +- docs-shopify.dev/static/cli.doc.ts | 2 +- .../cli-kit/src/private/node/constants.ts | 1 + .../src/public/node/context/local.test.ts | 25 +++++++++++++++++++ .../cli-kit/src/public/node/context/local.ts | 8 ++++-- 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .changeset/quiet-otters-wave.md diff --git a/.changeset/quiet-otters-wave.md b/.changeset/quiet-otters-wave.md new file mode 100644 index 00000000000..2fa6abfc868 --- /dev/null +++ b/.changeset/quiet-otters-wave.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli-kit': patch +--- + +Also treat `OPT_OUT_INSTRUMENTATION=true` as an analytics opt-out, in addition to the existing `SHOPIFY_CLI_NO_ANALYTICS=1` environment variable. diff --git a/docs-shopify.dev/generated/generated_static_pages.json b/docs-shopify.dev/generated/generated_static_pages.json index 79a6d9141ba..9890edc5b0a 100644 --- a/docs-shopify.dev/generated/generated_static_pages.json +++ b/docs-shopify.dev/generated/generated_static_pages.json @@ -83,7 +83,7 @@ "type": "Generic", "anchorLink": "reporting", "title": "Usage reporting", - "sectionContent": "Anonymous usage statistics are collected by default. To opt out, you can use the environment variable `SHOPIFY_CLI_NO_ANALYTICS=1`." + "sectionContent": "Anonymous usage statistics are collected by default. To opt out, you can use either `SHOPIFY_CLI_NO_ANALYTICS=1` or `OPT_OUT_INSTRUMENTATION=true`." }, { "type": "Generic", diff --git a/docs-shopify.dev/static/cli.doc.ts b/docs-shopify.dev/static/cli.doc.ts index 8449574b59c..ccce114e1bd 100644 --- a/docs-shopify.dev/static/cli.doc.ts +++ b/docs-shopify.dev/static/cli.doc.ts @@ -97,7 +97,7 @@ Or, run the \`help\` command to get this information right in your terminal. type: 'Generic', anchorLink: 'reporting', title: 'Usage reporting', - sectionContent: `Anonymous usage statistics are collected by default. To opt out, you can use the environment variable \`SHOPIFY_CLI_NO_ANALYTICS=1\`.`, + sectionContent: `Anonymous usage statistics are collected by default. To opt out, you can use either \`SHOPIFY_CLI_NO_ANALYTICS=1\` or \`OPT_OUT_INSTRUMENTATION=true\`.`, }, { type: 'Generic', diff --git a/packages/cli-kit/src/private/node/constants.ts b/packages/cli-kit/src/private/node/constants.ts index 40417176c61..aac03a2f4cb 100644 --- a/packages/cli-kit/src/private/node/constants.ts +++ b/packages/cli-kit/src/private/node/constants.ts @@ -21,6 +21,7 @@ export const environmentVariables = { env: 'SHOPIFY_CLI_ENV', firstPartyDev: 'SHOPIFY_CLI_1P_DEV', noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS', + optOutInstrumentation: 'OPT_OUT_INSTRUMENTATION', appAutomationToken: 'SHOPIFY_APP_AUTOMATION_TOKEN', partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN', runAsUser: 'SHOPIFY_RUN_AS_USER', diff --git a/packages/cli-kit/src/public/node/context/local.test.ts b/packages/cli-kit/src/public/node/context/local.test.ts index a4116f8cea9..fa109147773 100644 --- a/packages/cli-kit/src/public/node/context/local.test.ts +++ b/packages/cli-kit/src/public/node/context/local.test.ts @@ -183,6 +183,31 @@ describe('analitycsDisabled', () => { expect(got).toBe(true) }) + test('returns true when OPT_OUT_INSTRUMENTATION is truthy', () => { + // Given + const env = {OPT_OUT_INSTRUMENTATION: 'true'} + + // When + const got = analyticsDisabled(env) + + // Then + expect(got).toBe(true) + }) + + test('returns true when either opt-out env var is truthy', () => { + // Given + const env = { + SHOPIFY_CLI_NO_ANALYTICS: '1', + OPT_OUT_INSTRUMENTATION: 'true', + } + + // When + const got = analyticsDisabled(env) + + // Then + expect(got).toBe(true) + }) + test('returns true when in development', () => { // Given const env = {SHOPIFY_CLI_ENV: 'development'} diff --git a/packages/cli-kit/src/public/node/context/local.ts b/packages/cli-kit/src/public/node/context/local.ts index d43f0675cd0..2388db690d6 100644 --- a/packages/cli-kit/src/public/node/context/local.ts +++ b/packages/cli-kit/src/public/node/context/local.ts @@ -95,10 +95,14 @@ export function isUnitTest(env = process.env): boolean { * Returns true if reporting analytics is enabled. * * @param env - The environment variables from the environment of the current process. - * @returns True unless SHOPIFY_CLI_NO_ANALYTICS is truthy or debug mode is enabled. + * @returns True unless SHOPIFY_CLI_NO_ANALYTICS or OPT_OUT_INSTRUMENTATION is truthy, or debug mode is enabled. */ export function analyticsDisabled(env = process.env): boolean { - return isTruthy(env[environmentVariables.noAnalytics]) || isDevelopment(env) + return ( + isTruthy(env[environmentVariables.noAnalytics]) || + isTruthy(env[environmentVariables.optOutInstrumentation]) || + isDevelopment(env) + ) } /**