Skip to content

userId and deviceId in Configuration are ignored #281

@jerelevine

Description

@jerelevine

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

  1. 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',
);
  1. Initialize Amplitude with this configuration:
final amplitude = Amplitude(config);
await amplitude.isBuilt;
  1. 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'
  1. 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() and setDeviceId() methods work correctly when called after initialization
  • Both userId and deviceId parameters are included in the Configuration.toMap() output but ignored by native plugins
  • This affects both iOS and Android platforms
  • Workaround: Use setUserId() and setDeviceId() after initialization instead of passing them in Configuration

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions