filtering null values from the identify properties

- resetting values to null may cause inconsistent cross device tracking
This commit is contained in:
Adam Brown 2022-02-03 09:57:44 +00:00
parent 63a937c096
commit 48b339075b

View file

@ -176,7 +176,7 @@ class DefaultVectorAnalytics @Inject constructor(
} }
override fun updateUserProperties(identity: Identity) { override fun updateUserProperties(identity: Identity) {
posthog?.identify(REUSE_EXISTING_ID, identity.getProperties().toPostHogProperties(), IGNORED_OPTIONS) posthog?.identify(REUSE_EXISTING_ID, identity.getProperties()?.toPostHogUserProperties(), IGNORED_OPTIONS)
} }
private fun Map<String, Any?>?.toPostHogProperties(): Properties? { private fun Map<String, Any?>?.toPostHogProperties(): Properties? {
@ -186,4 +186,14 @@ class DefaultVectorAnalytics @Inject constructor(
putAll(this@toPostHogProperties) putAll(this@toPostHogProperties)
} }
} }
/**
* We avoid sending nulls as part of the UserProperties as this will reset the values across all devices
* The Identify event has nullable properties to allow for clients to opt in
*/
private fun Map<String, Any?>.toPostHogUserProperties(): Properties {
return Properties().apply {
putAll(this@toPostHogUserProperties.filter { it.value != null })
}
}
} }