feat: expose getAnonymousId()#31
Merged
choudlet merged 4 commits intoApr 21, 2026
Merged
Conversation
Add getAnonymousId(): Promise<string | null> to AnalyticsInterface, delegating to the native MetaRouter SDK identity layer via a new MetaRouterIdentity bridge module on both iOS and Android. - Add MetaRouterIdentityModule (Android) and MetaRouterIdentity (iOS) native bridge modules with getAnonymousId method - Add NativeIdentity.ts JS wrapper with fault-tolerant bridge access - Wire getAnonymousId through MetaRouterAnalyticsClient, init binding, and proxy (async-queued pre-bind, immediate post-bind) - Resolve null for missing/unavailable native module (no rejection)
brandon-metarouter
approved these changes
Apr 16, 2026
brandon-metarouter
left a comment
Collaborator
There was a problem hiding this comment.
Left a type comment, otherwise looks good!
| * Guaranteed non-null after init() — the IdentityManager always generates | ||
| * or loads an anonymous ID before the client reaches the 'ready' state. | ||
| */ | ||
| async getAnonymousId(): Promise<string> { |
Collaborator
There was a problem hiding this comment.
Should this be returning: Promise<string|null>? I took a peek at IdentityManager.getAnonymousId and it's return type says null is possible.
/**
* Retrieves the current anonymous ID.
* @returns The anonymous ID or null if not initialized.
*/
getAnonymousId(): string | null {
return this.anonymousId;
}
Collaborator
Author
There was a problem hiding this comment.
changed to be in line with other SDKs and awaiting the string. So it's always going to be a string.
| reset: () => Promise<void>; | ||
| enableDebugLogging: () => void; | ||
| getDebugInfo: () => Promise<Record<string, any>>; | ||
| getAnonymousId: () => Promise<string>; |
Collaborator
There was a problem hiding this comment.
Same here, should this be Promise<string|null> ?
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.
Summary
getAnonymousId(): Promise<string>to the publicAnalyticsInterfaceIdentityManager— guaranteed non-null afterinit()(loaded from AsyncStorage, generated UUID, or timestamp-based fallback)Ticket: SC-37839
What changed
Public API
AnalyticsInterfaceintypes.ts: addedgetAnonymousId: () => Promise<string>Design decision
The anonymous ID is managed entirely in JS via
IdentityManager, which persists to AsyncStorage and always guarantees a value after initialization. No native bridge modules are needed — this avoids unnecessary complexity and platform-specific code for something the JS layer already handles.Test plan
MetaRouterAnalyticsClient.test.ts— 2 new tests: returns JS IdentityManager value, is async and returns a string (never null)proxyClient.test.ts— 2 new tests: pre-bind queuing + post-bind forwarding; "forwards all methods" updatedinit.test.ts— assertsgetAnonymousIdexposed on returned client