Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-otters-wave.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion docs-shopify.dev/generated/generated_static_pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs-shopify.dev/static/cli.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/cli-kit/src/private/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
25 changes: 25 additions & 0 deletions packages/cli-kit/src/public/node/context/local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
8 changes: 6 additions & 2 deletions packages/cli-kit/src/public/node/context/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}

/**
Expand Down
Loading