Amplitude-Kotlin
Amplitude-Kotlin copied to clipboard
Second call Identify.set() with existing key has no effect
Hello.
When I run
val identify = Identify()
identify.set("propertyName1", "str1")
amplitude.identify(identify)
amplitude.track("someEvent1", mapOf<String, Any?>...))
identify.set("propertyName2", "str2")
amplitude.identify(identify)
amplitude.track("someEvent2", mapOf<String, Any?>...)
identify.set("propertyName1", "str3")
amplitude.identify(identify)
amplitude.track("someEvent3", mapOf<String, Any?>...)
As result, I saw in user properties: propertyName1: "str1" with someEvent1 propertyName2: "str2" with someEvent2 propertyName1: "str1" with someEvent3
I expected: propertyName1: "str1" with someEvent1 propertyName2: "str2" with someEvent2 propertyName1: "str3" with someEvent3
because I used method set(), not setOnce().
After investigating the situation a bit, I saw that the internal map of the Identify object does not change if I send a new value ("str3") for the same key ("propertyName1"), if I send a new key it works as I expected.
For what created separate method setOnce() if the method set() works the same way?
If I use new object of Identify() for every changes it works as I expected.
Thank you for attention.
Thanks for raising this question @kirkaDev. Yes, looking at the code, the same object does not liking adding the same property twice. I believe the general expectation was that we recycle identify objects after they are used. It's going to be hard to change this behaviour since that would make it a breaking change and we'd have to increase the major version of the SDK. We'll keep this in mind for future releases.
Thank you for answer, @izaaz.