-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Expected Behavior
When passing userId and deviceId in the Configuration object during Amplitude initialization, the SDK should use the provided values instead of generating its own.
Current Behavior
Both the userId and deviceId parameters in the Configuration object are completely ignored by both iOS and Android native implementations. The SDK generates its own device ID during initialization, and when getUserId() and getDeviceId() are called later, they return auto-generated/null values instead of the ones provided in the configuration.
Possible Solution
The native iOS and Android plugins need to handle both userId and deviceId parameters in their getConfiguration methods:
iOS (SwiftAmplitudeFlutterPlugin.swift):
Add these to the getConfiguration method around line 221:
if let userId = args["userId"] as? String {
configuration.userId = userId
}
if let deviceId = args["deviceId"] as? String {
configuration.deviceId = deviceId
}Android (AmplitudeFlutterPlugin.kt):
Add these to the getConfiguration method around line 226:
call.argument<String>("userId")?.let { configuration.userId = it }
call.argument<String>("deviceId")?.let { configuration.deviceId = it }Steps to Reproduce
- Create a Configuration object with custom userId and deviceId:
final config = Configuration(
apiKey: 'your-api-key',
userId: 'custom-user-123',
deviceId: 'custom-device-id-456',
);- Initialize Amplitude with this configuration:
final amplitude = Amplitude(config);
await amplitude.isBuilt;- Retrieve the user ID and device ID:
final userId = await amplitude.getUserId();
final deviceId = await amplitude.getDeviceId();
print('User ID: $userId'); // This will NOT be 'custom-user-123'
print('Device ID: $deviceId'); // This will NOT be 'custom-device-id-456'- Both returned values will be auto-generated/null instead of the custom ones provided in the configuration.
Environment
- SDK Version: amplitude_flutter 4.3.7
Additional Notes
- Both
setUserId()andsetDeviceId()methods work correctly when called after initialization - Both
userIdanddeviceIdparameters are included in theConfiguration.toMap()output but ignored by native plugins - This affects both iOS and Android platforms
- Workaround: Use
setUserId()andsetDeviceId()after initialization instead of passing them in Configuration