Track installation package manager in analytics#7348
Open
alfonso-noriega wants to merge 2 commits intomainfrom
Open
Track installation package manager in analytics#7348alfonso-noriega wants to merge 2 commits intomainfrom
alfonso-noriega wants to merge 2 commits intomainfrom
Conversation
Wire inferPackageManagerForGlobalCLI() into the analytics payload as env_install_package_manager. This field correctly identifies how the CLI was globally installed (homebrew via SHOPIFY_HOMEBREW_FORMULA env var, or yarn/pnpm/bun via binary path inspection, falling back to npm). Previously ~34% of users had unknown package manager in analytics because packageManagerFromUserAgent() requires npm_config_user_agent, which is only set when a package manager spawns the process — not when users run the CLI binary directly from the shell (the common global install case). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Aligns with Shopify/monorail#23445 which adds env_install_package_manager to the schema. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/private/node/analytics.d.ts@@ -19,6 +19,7 @@ interface EnvironmentData {
env_device_id: string;
env_cloud: string;
env_package_manager: string;
+ env_install_package_manager: string;
env_is_global: boolean;
env_auth_method: string;
env_is_wsl: boolean;
packages/cli-kit/dist/public/node/monorail.d.ts@@ -2,7 +2,7 @@ import { JsonMap } from '../../private/common/json.js';
import { DeepRequired } from '../common/ts/deep-required.js';
export { DeepRequired };
type Optional<T> = T | null;
-export declare const MONORAIL_COMMAND_TOPIC = "app_cli3_command/1.21";
+export declare const MONORAIL_COMMAND_TOPIC = "app_cli3_command/1.22";
export interface Schemas {
[MONORAIL_COMMAND_TOPIC]: {
sensitive: {
@@ -129,6 +129,7 @@ export interface Schemas {
env_ci_platform?: Optional<string>;
env_device_id?: Optional<string>;
env_package_manager?: Optional<string>;
+ env_install_package_manager?: Optional<string>;
env_package_manager_workspaces?: Optional<boolean>;
env_plugin_installed_any_custom?: Optional<boolean>;
env_plugin_installed_shopify?: Optional<string>;
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
~34% of CLI users (77K unique devices in the last 30 days) have
unknownas their package manager in analytics. This happens becausecmd_all_launcherandenv_package_managerboth rely onnpm_config_user_agent, which is only set when a package manager spawns the CLI process. Users who run theshopifybinary directly from the shell (the common case for global installs) never have this env var set.Global installs are 85% of all CLI traffic, and 39% of those events have
unknownpackage manager.Solution
Add a new
env_install_package_managerfield to the analytics payload, populated byinferPackageManagerForGlobalCLI()— a function that was already written, tested, and used for upgrade logic, but never wired into analytics.Detection logic (in priority order):
SHOPIFY_HOMEBREW_FORMULAenv var →homebrew(injected by the brew formula wrapper — most reliable)yarn/pnpm/bun→ respective PM/cellar/→homebrew(symlink resolved Intel/AS Mac path)npmPaths are already lowercased before matching, so Windows paths with mixed case (e.g.
Yarn) are handled correctly.What changes
analytics.ts: import and callinferPackageManagerForGlobalCLI(), addenv_install_package_managertoEnvironmentDatainterface and return valuemonorail.ts: addenv_install_package_managerto the public payload schemaNote on existing fields
This is intentionally a new field rather than replacing
env_package_manager. The two fields mean different things:env_package_manager— the project's package manager (detected via lockfile in cwd)env_install_package_manager— how the CLI itself was installed globallyTest plan
analytics.test.ts,is-global.test.ts)env_install_package_managerappears in Monorail events after deploy🤖 Generated with Claude Code