Skip to content

Commit

Permalink
feat: set the client userId and deviceId in identify call (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao900914 authored Jun 4, 2022
1 parent a4e0801 commit 2c8b3f1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/src/main/java/com/amplitude/core/Amplitude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ open class Amplitude internal constructor(
* @return the Amplitude instance
*/
@JvmOverloads
fun identify(userProperties: Map<String, Any>, options: EventOptions? = null): Amplitude {
fun identify(userProperties: Map<String, Any?>?, options: EventOptions? = null): Amplitude {
return identify(convertPropertiesToIdentify(userProperties), options)
}

Expand All @@ -146,9 +146,13 @@ open class Amplitude internal constructor(
fun identify(identify: Identify, options: EventOptions? = null): Amplitude {
val event = IdentifyEvent()
event.userProperties = identify.properties
options ?. let {
event.mergeEventOptions(it)

options ?. let { eventOptions ->
event.mergeEventOptions(eventOptions)
eventOptions.userId ?.let { this.setUserId(it) }
eventOptions.deviceId ?.let { this.setDeviceId(it) }
}

process(event)
return this
}
Expand Down Expand Up @@ -189,7 +193,7 @@ open class Amplitude internal constructor(
* @return the Amplitude instance
*/
@JvmOverloads
fun groupIdentify(groupType: String, groupName: String, groupProperties: Map<String, Any>, options: EventOptions? = null): Amplitude {
fun groupIdentify(groupType: String, groupName: String, groupProperties: Map<String, Any?>?, options: EventOptions? = null): Amplitude {
return groupIdentify(groupType, groupName, convertPropertiesToIdentify(groupProperties), options)
}

Expand Down Expand Up @@ -330,10 +334,10 @@ open class Amplitude internal constructor(
}
}

private fun convertPropertiesToIdentify(userProperties: Map<String, Any>): Identify {
private fun convertPropertiesToIdentify(userProperties: Map<String, Any?>?): Identify {
val identify = Identify()
userProperties.forEach { property ->
identify.set(property.key, property.value)
userProperties?.forEach { property ->
property.value?.let { identify.set(property.key, it) }
}
return identify
}
Expand Down

0 comments on commit 2c8b3f1

Please sign in to comment.