Skip to content

Add store command shop id analytics#7429

Open
dmerand wants to merge 1 commit intodlm-store-command-metricsfrom
dlm-store-command-shop-id-metrics
Open

Add store command shop id analytics#7429
dmerand wants to merge 1 commit intodlm-store-command-metricsfrom
dlm-store-command-shop-id-metrics

Conversation

@dmerand
Copy link
Copy Markdown
Contributor

@dmerand dmerand commented Apr 29, 2026

WHY are these changes introduced?

This is the shop_id portion of store command analytics attribution, split from #7428 because it depends on a Monorail schema update.

Together with the reliable user_id recorded by #7428, shop_id gives downstream analytics the attribution dimensions they need for shopify store auth / shopify store execute.

Schema dependency:

  • Shopify/monorail#23541 adds optional shop_id: long as app_cli3_command/1.23
  • this PR updates the CLI local topic mirror to emit app_cli3_command/1.23

WHAT is this pull request doing?

Adds best-effort shop_id recording for store commands:

  • adds shop_id to the local cli-kit Monorail schema mirror
  • bumps MONORAIL_COMMAND_TOPIC from app_cli3_command/1.22 to app_cli3_command/1.23
  • extracts numeric shop IDs from Admin GIDs like gid://shopify/Shop/123
  • records shop_id after store auth by querying Admin GraphQL shop { id } with the newly acquired token
  • records shop_id during normal store execute version discovery by adding shop { id } to the existing Admin publicApiVersions request
  • records shop_id for store execute --version unstable through the standalone best-effort Admin helper, since that path skips version discovery

Important constraints preserved:

  • uses only Admin GraphQL shop { id } as the source of truth for shop_id
  • logs failures only at debug level; analytics collection does not block the command

Post-release steps

  • Ensure Shopify/monorail#23541 has landed before publishing this change.
  • Confirm downstream warehouse extraction exposes payload.shop_id where CLI analytics consumers need it.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • This is not user-facing CLI behavior and does not need a changeset

Copy link
Copy Markdown
Contributor Author

dmerand commented Apr 29, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label Apr 29, 2026
@dmerand dmerand force-pushed the dlm-store-command-metrics branch from 6d2463a to 4e58f7b Compare April 29, 2026 21:18
@dmerand dmerand force-pushed the dlm-store-command-shop-id-metrics branch from fc65d9c to 18dd652 Compare April 29, 2026 21:18
@dmerand dmerand force-pushed the dlm-store-command-shop-id-metrics branch from 18dd652 to a566b43 Compare April 30, 2026 14:34
@dmerand dmerand force-pushed the dlm-store-command-metrics branch 2 times, most recently from bac2759 to c447b80 Compare May 1, 2026 18:57
@dmerand dmerand force-pushed the dlm-store-command-shop-id-metrics branch from a566b43 to 8920736 Compare May 1, 2026 18:57
@dmerand dmerand marked this pull request as ready for review May 1, 2026 19:09
@dmerand dmerand requested a review from a team as a code owner May 1, 2026 19:09
@dmerand dmerand force-pushed the dlm-store-command-shop-id-metrics branch from 8920736 to d5ec5cc Compare May 1, 2026 19:21
@dmerand dmerand force-pushed the dlm-store-command-metrics branch from c447b80 to 58ecacb Compare May 1, 2026 19:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Differences in type declarations

We 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:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/metadata.d.ts
@@ -34,7 +34,7 @@ export type SensitiveSchema<T> = T extends RuntimeMetadataManager<infer _TPublic
  * @returns A container for the metadata.
  */
 export declare function createRuntimeMetadataContainer<TPublic extends AnyJson, TSensitive extends AnyJson = Record<string, never>>(defaultPublicMetadata?: Partial<TPublic>): RuntimeMetadataManager<TPublic, TSensitive>;
-type CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> & PickByPrefix<MonorailEventPublic, 'cmd_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_create_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_theme_'> & PickByPrefix<MonorailEventPublic, 'store_'> & PickByPrefix<MonorailEventPublic, 'env_auto_upgrade_'>;
+type CmdFieldsFromMonorail = Pick<MonorailEventPublic, 'shop_id'> & PickByPrefix<MonorailEventPublic, 'cmd_all_'> & PickByPrefix<MonorailEventPublic, 'cmd_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_create_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_theme_'> & PickByPrefix<MonorailEventPublic, 'store_'> & PickByPrefix<MonorailEventPublic, 'env_auto_upgrade_'>;
 declare const coreData: RuntimeMetadataManager<CmdFieldsFromMonorail, {
     commandStartOptions: {
         startTime: number;
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.22";
+export declare const MONORAIL_COMMAND_TOPIC = "app_cli3_command/1.23";
 export interface Schemas {
     [MONORAIL_COMMAND_TOPIC]: {
         sensitive: {
@@ -32,6 +32,7 @@ export interface Schemas {
             node_version: string;
             is_employee: boolean;
             store_fqdn_hash?: Optional<string>;
+            shop_id?: Optional<number>;
             user_id: string;
             cmd_all_alias_used?: Optional<string>;
             cmd_all_launcher?: Optional<string>;
packages/cli-kit/dist/public/node/session.d.ts
@@ -16,6 +16,12 @@ export interface Session {
     userId: string;
 }
 export type AccountInfo = UserAccountInfo | ServiceAccountInfo | UnknownAccountInfo;
+/**
+ * Records the user ID that should be attached to command analytics for this process.
+ *
+ * @param userId - User identifier to report on the command analytics event.
+ */
+export declare function setLastSeenUserId(userId: string): void;
 interface UserAccountInfo {
     type: 'UserAccount';
     email: string;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant