Amplitude-Kotlin icon indicating copy to clipboard operation
Amplitude-Kotlin copied to clipboard

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

Open initishbhatt opened this issue 1 year ago • 7 comments

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

  • SDK Version: 1.7.1
  • Device: All devices
  • Android SDK Version - 33
  • Gradle Version -8.0.2
  • KGP - 1.9.0

initishbhatt avatar Oct 09 '23 05:10 initishbhatt

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

justin-fiedler avatar Oct 10 '23 23:10 justin-fiedler

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.

initishbhatt avatar Oct 11 '23 07:10 initishbhatt

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!

liuyang1520 avatar Oct 16 '23 22:10 liuyang1520

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
        }

ronnieotieno avatar Oct 17 '23 05:10 ronnieotieno

Hi @ronnieotieno , thanks for sharing this!

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

  • useAdvertisingIdForDeviceId
  • useAppSetIdForDeviceId
  • newDeviceIdPerInstall
  • identityStorageProvider

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.

liuyang1520 avatar Oct 17 '23 18:10 liuyang1520

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

  • Application context
  • ApiKey
  • Server zone
  • OptOut as false

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?

ronnieotieno avatar Oct 18 '23 07:10 ronnieotieno

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.

qingzhuozhen avatar Oct 27 '23 18:10 qingzhuozhen

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.

izaaz avatar Aug 20 '24 23:08 izaaz