amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
27 stars 10 forks source link

Device ID Appending Issue - Device ID sometimes appended with an 'R #148

Closed initishbhatt closed 2 weeks ago

initishbhatt commented 11 months ago

The Amplitude Kotlin SDK occasionally generates a random device ID with R , which affects approximately 30% of the devices. The expected behaviour is for the device ID to be registered as 'xxxx-xxxx-xxxx-xxxx,' but it is sometimes recorded as 'xxxx-xxxx-xxxx-xxxxR.'

Expected Behavior

The device ID should consistently follow the format 'xxxx-xxxx-xxxx-xxxx' without any additional characters like 'R' appended at the end.

Current Behavior

In some cases, the device ID recorded by the Amplitude Kotlin SDK contains an extra 'R' character, causing discrepancies in the data.

Possible Solution

Steps to Reproduce

Steps to reproduce the behavior:

  1. Use the Amplitude Kotlin SDK in an Android application.
  2. Collect data from various devices.
  3. Observe that approximately 30% of the devices have device IDs with the 'R' character appended.

Environment

justin-fiedler commented 11 months ago

Hi @initishbhatt thanks for using Amplitude.

I reviewed the code and R is appended to the device ID anytime it is randomly generated based on a UUID vs AppSetId or ADID.

I am not sure the exact reason behind this logic and the original developer is currently out of town. I would like to check with him before making a change.

In the meantime, can you please provide more details on the issues caused by the extra "R"? Is it causing an error?

Thanks again

initishbhatt commented 11 months ago

Hi @justin-fiedler thanks for looking into it. There is no error on the app but we have data discrepancies as other tools and sdks that we use have the correct device ID while amplitude has randomly generated one. We pass the same device id to all the tools and SDK's but the Amplitude SDK is generating random ones for some users.

liuyang1520 commented 10 months ago

Hi @initishbhatt , thanks for reporting this!

I have synced with @qingzhuozhen offline on the behavior, the R suffix is for distinguishing whether the device id is generated by the SDK, in the case that previous device id or adid/appsetId is absent. Could you share more on "We pass the same device id to all the tools and SDK"?

Thanks!

ronnieotieno commented 10 months ago

Hi @liuyang1520 Nitish colleague here. We are providing the amplitude when launching the app and setting the device id then.

fun provideAmplitude( ): Amplitude {
            val amplitude = Amplitude(
                    Configuration(
                         // configuration
                    ),
            )
            amplitude.setDeviceId("id here")
            return amplitude
        }
liuyang1520 commented 10 months ago

Hi @ronnieotieno , thanks for sharing this!

Could you provide more information in the Configuration? There are several related configs might affect this, like:

For "affects approximately 30% of the devices", could you share more about the affected event types, like is it the session_start event or custom event sent via track? The reason is I think the SDK is trying to read device_id during initialization from persistent storage, the setDeviceId above in your code is after the initialization.

If the above info is not helpful for us to identify the issue, maybe can try to implement a ObservePlugin's onDeviceIdChanged for printing some more useful debugging information, here is the doc for plugins.

ronnieotieno commented 10 months ago

Hi @liuyang1520 thank you. Regarding the configuration we are only passing:

When the session starts we get the generated device id which is different from what we set in the function but after one or two tracking events our id is set.

From our understanding we need to set the device id after initialisation, thats when we get the amplitude instance. And the code shared above should run before we use Amplitude.

Is there a chance that the session could start before the initialisation and setting the device id?

qingzhuozhen commented 10 months ago

Hi @ronnieotieno, it seems a race condition between the device id initialization in SDK versus set from outside directly. We will investigate further on the solutions to help solve it.

izaaz commented 2 weeks ago

The SDK configuration now takes in a device id as input and when that parameter is passed, it would default to using that.

Closing this issue since this is now resolved.