-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add server metametrics id #24479
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,8 @@ const exceptionsToFilter = { | |
* @typedef {object} MetaMetricsControllerState | ||
* @property {string} [metaMetricsId] - The user's metaMetricsId that will be | ||
* attached to all non-anonymized event payloads | ||
* @property {string} [serverMetaMetricsId] - A server generated metametrics id that will be | ||
* attached to logged in user events | ||
* @property {boolean} [participateInMetaMetrics] - The user's preference for | ||
* participating in the MetaMetrics analytics program. This setting controls | ||
* whether or not events are tracked | ||
|
@@ -154,6 +156,7 @@ export default class MetaMetricsController { | |
this.store = new ObservableStore({ | ||
participateInMetaMetrics: null, | ||
metaMetricsId: null, | ||
serverMetaMetricsId: null, | ||
eventsBeforeMetricsOptIn: [], | ||
traits: {}, | ||
previousUserTraits: {}, | ||
|
@@ -497,9 +500,10 @@ export default class MetaMetricsController { | |
) { | ||
return; | ||
} | ||
const { metaMetricsId } = this.state; | ||
const idTrait = metaMetricsId ? 'userId' : 'anonymousId'; | ||
const idValue = metaMetricsId ?? METAMETRICS_ANONYMOUS_ID; | ||
const { metaMetricsId, serverMetaMetricsId } = this.state; | ||
const unifiedMetaMetrics = serverMetaMetricsId ?? metaMetricsId; | ||
const idTrait = unifiedMetaMetrics ? 'userId' : 'anonymousId'; | ||
const idValue = unifiedMetaMetrics ?? METAMETRICS_ANONYMOUS_ID; | ||
this._submitSegmentAPICall('page', { | ||
messageId: buildUniqueMessageId({ actionId }), | ||
[idTrait]: idValue, | ||
|
@@ -652,6 +656,21 @@ export default class MetaMetricsController { | |
}); | ||
} | ||
|
||
// Retrieve (or generate if doesn't exist) the client metametrics id | ||
getClientMetaMetricsId() { | ||
let { metaMetricsId } = this.state; | ||
if (!metaMetricsId) { | ||
metaMetricsId = this.generateMetaMetricsId(); | ||
this.store.updateState({ metaMetricsId }); | ||
} | ||
return metaMetricsId; | ||
} | ||
|
||
// New authentication can return a server metametrics id that we can utilize in our events | ||
setServerMetaMetricsId(metaMetricsId) { | ||
this.store.updateState({ serverMetaMetricsId: metaMetricsId }); | ||
} | ||
|
||
/** PRIVATE METHODS */ | ||
|
||
/** | ||
|
@@ -904,7 +923,8 @@ export default class MetaMetricsController { | |
* @param {object} userTraits | ||
*/ | ||
_identify(userTraits) { | ||
const { metaMetricsId } = this.state; | ||
const { metaMetricsId, serverMetaMetricsId } = this.state; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Effected Segment Events:
|
||
const unifiedMetaMetrics = serverMetaMetricsId ?? metaMetricsId; | ||
|
||
if (!userTraits || Object.keys(userTraits).length === 0) { | ||
console.warn('MetaMetricsController#_identify: No userTraits found'); | ||
|
@@ -913,7 +933,7 @@ export default class MetaMetricsController { | |
|
||
try { | ||
this._submitSegmentAPICall('identify', { | ||
userId: metaMetricsId, | ||
userId: unifiedMetaMetrics, | ||
traits: userTraits, | ||
}); | ||
} catch (err) { | ||
|
@@ -990,7 +1010,9 @@ export default class MetaMetricsController { | |
flushImmediately, | ||
} = options || {}; | ||
let idType = 'userId'; | ||
let idValue = this.state.metaMetricsId; | ||
const unifiedMetaMetrics = | ||
this.state.serverMetaMetricsId ?? this.state.metaMetricsId; | ||
let idValue = unifiedMetaMetrics; | ||
let excludeMetaMetricsId = options?.excludeMetaMetricsId ?? false; | ||
// This is carried over from the old implementation, and will likely need | ||
// to be updated to work with the new tracking plan. I think we should use | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As comment mentioned, we need this to be used on Mobile. Seeing that the metametrics controller is still inside the extension, my guess is that mobile uses a different approach.