-
Notifications
You must be signed in to change notification settings - Fork 240
Add device_id as an automatic context value for Feature Flags #675
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: msiebert <[email protected]>
Using this commit as a reference, please implement tracking for for |
…ment_started events Co-authored-by: msiebert <[email protected]>
I've implemented tracking for
Both properties are now included in all |
The latest commit introduces the following compilation error:
|
Co-authored-by: msiebert <[email protected]>
... Fixed the compilation error by removing the intermediate |
Tests fail due to the following error:
|
…rties Co-authored-by: msiebert <[email protected]>
... Fixed the private access level issue by changing |
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.
Pull Request Overview
Adds device_id
to feature flags context using the anonymous ID and captures fetch timing metrics for feature flag requests.
- Extends
MixpanelFlagDelegate
withgetAnonymousId()
and updatesMixpanelInstance
- Updates feature-flags request logic to include
device_id
and record fetch start/end times - Adds tests for anonymous ID delegation and fetch timing properties
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
Sources/MixpanelInstance.swift | Implemented getAnonymousId() to expose the anonymousId . |
Sources/FeatureFlags.swift | Extended protocol, updated context building, and added timing metrics. |
MixpanelDemo/MixpanelDemoTests/MixpanelFeatureFlagTests.swift | Extended mock delegate and added tests for device_id and timing. |
Comments suppressed due to low confidence (3)
Sources/FeatureFlags.swift:74
- Adding a new protocol requirement is a breaking change for existing MixpanelFlagDelegate implementers; consider providing a default implementation in a protocol extension so clients aren't forced to update.
func getAnonymousId() -> String?
MixpanelDemo/MixpanelDemoTests/MixpanelFeatureFlagTests.swift:922
- This test asserts delegate call counts but doesn't verify that
device_id
actually appears in the request context payload; consider adding a test that intercepts the request body to confirmdevice_id
inclusion.
func testFeatureFlagContextIncludesDeviceId() {
Sources/FeatureFlags.swift:526
- [nitpick] The property key
timeLastFetched
uses camelCase, while other keys use snake_case or title case; consider standardizing naming convention for custom properties for consistency (e.g.,time_last_fetched
).
properties["timeLastFetched"] = Int(timeLastFetched.timeIntervalSince1970)
This PR adds
device_id
as an automatic context value for Feature Flags, using the anonymous ID as the context property value. Thedevice_id
is now included alongside the existingdistinct_id
in the feature flags context when making requests to the feature flags API.Changes Made
getAnonymousId()
method to provide access to the anonymous IDgetAnonymousId()
to return theanonymousId
propertydevice_id
in the context when anonymous ID is availableMockFeatureFlagDelegate
to support the new methoddevice_id
inclusion in both scenarios (with and without anonymous ID)Implementation Details
The implementation follows the same pattern as the Android SDK (as referenced in the issue). When building the feature flags context in
_performFetchRequest()
, the code now:This ensures that:
distinct_id
is always included (existing behavior)device_id
is included whenanonymousId
is not nilfeatureFlagsContext
Testing
Added comprehensive tests to verify:
device_id
is included in context when anonymous ID is availabledevice_id
is omitted when anonymous ID is nilFixes #674.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.