Skip to content

Commit 2cb5f44

Browse files
committed
Add analytics opt-out that matches ai-toolkit
1 parent 5837ad2 commit 2cb5f44

6 files changed

Lines changed: 39 additions & 4 deletions

File tree

.changeset/quiet-otters-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli-kit': patch
3+
---
4+
5+
Also treat `OPT_OUT_INSTRUMENTATION=true` as an analytics opt-out, in addition to the existing `SHOPIFY_CLI_NO_ANALYTICS=1` environment variable.

docs-shopify.dev/generated/generated_static_pages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"type": "Generic",
8484
"anchorLink": "reporting",
8585
"title": "Usage reporting",
86-
"sectionContent": "Anonymous usage statistics are collected by default. To opt out, you can use the environment variable `SHOPIFY_CLI_NO_ANALYTICS=1`."
86+
"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`."
8787
},
8888
{
8989
"type": "Generic",

docs-shopify.dev/static/cli.doc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Or, run the \`help\` command to get this information right in your terminal.
9797
type: 'Generic',
9898
anchorLink: 'reporting',
9999
title: 'Usage reporting',
100-
sectionContent: `Anonymous usage statistics are collected by default. To opt out, you can use the environment variable \`SHOPIFY_CLI_NO_ANALYTICS=1\`.`,
100+
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\`.`,
101101
},
102102
{
103103
type: 'Generic',

packages/cli-kit/src/private/node/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const environmentVariables = {
2121
env: 'SHOPIFY_CLI_ENV',
2222
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',
2323
noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',
24+
optOutInstrumentation: 'OPT_OUT_INSTRUMENTATION',
2425
appAutomationToken: 'SHOPIFY_APP_AUTOMATION_TOKEN',
2526
partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',
2627
runAsUser: 'SHOPIFY_RUN_AS_USER',

packages/cli-kit/src/public/node/context/local.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ describe('analitycsDisabled', () => {
183183
expect(got).toBe(true)
184184
})
185185

186+
test('returns true when OPT_OUT_INSTRUMENTATION is truthy', () => {
187+
// Given
188+
const env = {OPT_OUT_INSTRUMENTATION: 'true'}
189+
190+
// When
191+
const got = analyticsDisabled(env)
192+
193+
// Then
194+
expect(got).toBe(true)
195+
})
196+
197+
test('returns true when either opt-out env var is truthy', () => {
198+
// Given
199+
const env = {
200+
SHOPIFY_CLI_NO_ANALYTICS: '1',
201+
OPT_OUT_INSTRUMENTATION: 'true',
202+
}
203+
204+
// When
205+
const got = analyticsDisabled(env)
206+
207+
// Then
208+
expect(got).toBe(true)
209+
})
210+
186211
test('returns true when in development', () => {
187212
// Given
188213
const env = {SHOPIFY_CLI_ENV: 'development'}

packages/cli-kit/src/public/node/context/local.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ export function isUnitTest(env = process.env): boolean {
9595
* Returns true if reporting analytics is enabled.
9696
*
9797
* @param env - The environment variables from the environment of the current process.
98-
* @returns True unless SHOPIFY_CLI_NO_ANALYTICS is truthy or debug mode is enabled.
98+
* @returns True unless SHOPIFY_CLI_NO_ANALYTICS or OPT_OUT_INSTRUMENTATION is truthy, or debug mode is enabled.
9999
*/
100100
export function analyticsDisabled(env = process.env): boolean {
101-
return isTruthy(env[environmentVariables.noAnalytics]) || isDevelopment(env)
101+
return (
102+
isTruthy(env[environmentVariables.noAnalytics]) ||
103+
isTruthy(env[environmentVariables.optOutInstrumentation]) ||
104+
isDevelopment(env)
105+
)
102106
}
103107

104108
/**

0 commit comments

Comments
 (0)