Improve user_id detection for analytics#7326
Merged
gonzaloriestra merged 1 commit intomainfrom Apr 16, 2026
Merged
Conversation
Contributor
Author
|
/snapit |
Contributor
|
🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm. Test the snapshot by installing your package globally: i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260416091104Caution After installing, validate the version by running |
71da41b to
50e5af7
Compare
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/session.d.ts@@ -63,14 +63,14 @@ export interface OAuthSession {
}
type AuthMethod = 'partners_token' | 'device_auth' | 'theme_access_token' | 'custom_app_token' | 'none';
/**
- * Retrieves the user ID from the current session or returns 'unknown' if not found.
+ * Retrieves a stable user identifier for analytics, or if none applies.
*
- * This function performs the following steps:
- * 1. Checks for a cached user ID in memory (obtained in the current run).
- * 2. Attempts to fetch it from the local storage (from a previous auth session).
- * 3. Checks if a custom token was used (either as a theme password or partners token).
- * 4. If a custom token is present in the environment, generates a UUID and uses it as userId.
- * 5. If after all this we don't have a userId, then reports as 'unknown'.
+ * Evaluation order:
+ * 1. If an app automation token or theme token is used, returns a deterministic UUID
+ * derived from that secret.
+ * 2. Otherwise, if was called (e.g. after OAuth), returns that value.
+ * 3. Otherwise, if a persisted CLI session id is available, returns it.
+ * 4. Otherwise returns .
*
* @returns A Promise that resolves to the user ID as a string.
*/
|
alfonso-noriega
approved these changes
Apr 16, 2026
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.
WHY are these changes introduced?
When you have a stored session, but you are also using a token (like
SHOPIFY_APP_AUTOMATION_TOKEN), we are sending to monorail the saved user ID from the session, but that's not actually used.See https://shopify.slack.com/archives/C0ASQECGH2Q/p1776243522246889?thread_ts=1776203153.988669&cid=C0ASQECGH2Q
WHAT is this pull request doing?
If a token is being used, send the user ID generated from that instead of the stored session.
How to test your changes?
shopify app deploy --verboseSHOPIFY_APP_AUTOMATION_TOKEN=xxx shopify app deploy --verboseChecklist
pnpm changeset add