rudderlabs / rudder-sdk-flutter

Flutter SDK for RudderStack - the Customer Data Platform for Developers. Now supports Android, iOS and Web tracking!
https://www.rudderstack.com
Other
6 stars 24 forks source link

BUG : anonymousId is not defaulting to deviceId #143

Closed Filmaluco closed 6 months ago

Filmaluco commented 6 months ago

Describe the bug Please provide the following information:

According to the documentation AnonymousId should be device id putAnonymousId is called. However using the code provided bellow, the anonymousId is different from the deviceId.

Which platform is the issue occurring on Is the error occurring on:

Expected behavior anonymousId is a 16 number digit and the same as deviceId

To Reproduce Use the following class and init on the start of the app.

class RudderStackAnalyticsProvider extends IAnalyticsProvider {
  RudderStackAnalyticsProvider(this._environmentType, this._writeKey);

  final String _writeKey;
  final EnvironmentType _environmentType;
  final RudderController _client = RudderController.instance;
  String _userId = 'user';

  @override
  Future<void> init() async {
    RudderLogger.init(
      _environmentType == EnvironmentType.development
          ? RudderLogger.DEBUG
          : RudderLogger.VERBOSE,
    );
    final builder = RudderConfigBuilder()
      ..withDataPlaneUrl('https://mindmanukih.dataplane.rudderstack.com')
      // https://github.com/rudderlabs/rudder-sdk-flutter/issues/37#issuecomment-999316787
      ..withMobileConfig(
        MobileConfig(
          autoCollectAdvertId: true,
        ),
      )
      ..withDebug(false); // Set to true for verbose logs from RudderStack

    _client.initialize(
      _writeKey,
      config: builder.build(),
    );
  }

  @override
  Future<void> logEvent({
    required String eventName,
    Map<String, dynamic>? parameters,
  }) async {
    final properties = RudderProperty();
    parameters?.forEach(properties.put);

    _client.track(eventName, properties: properties);
  }

  @override
  Future<void> flush() async {}

  @override
  Future<void> reset() async {
    _client.reset();
  }

  @override
  Future<void> updateUserId(String? userId) async {
    if (_userId == userId) {
      return;
    } else if (userId != null) {
      _userId = userId;
      _client.identify(userId);
    } else {
      _userId = 'user';
      _client
        ..identify('user')
        ..reset();
    }
  }

  @override
  Future<void> addTraits(Map<String, Object?> traits) async {
    final rudderTraits = RudderTraits();
    traits.forEach(rudderTraits.put);
    _client.identify(_userId, traits: rudderTraits);
  }
}

Version of the Flutter SDK Please provide the following information:

rudder_sdk_flutter: ^2.6.0

SDK initialisation snippet provided above

Framework version of the SDK Flutter 3.13.3 Dart 3.1.1

desusai7 commented 6 months ago

Hi @Filmaluco,

Starting from version 2.5.0 of the Rudderstack Flutter SDK, we are not using the device ID as anonymousId. We had also documented it here.