diff --git a/.changeset/alias-distinct-id-property.md b/.changeset/alias-distinct-id-property.md new file mode 100644 index 000000000..3bf20da9b --- /dev/null +++ b/.changeset/alias-distinct-id-property.md @@ -0,0 +1,5 @@ +--- +"posthog": patch +--- + +fix: include `distinct_id` alongside `alias` in `$create_alias` event properties diff --git a/posthog/src/main/java/com/posthog/PostHog.kt b/posthog/src/main/java/com/posthog/PostHog.kt index b74829757..64d0be165 100644 --- a/posthog/src/main/java/com/posthog/PostHog.kt +++ b/posthog/src/main/java/com/posthog/PostHog.kt @@ -1319,6 +1319,9 @@ public class PostHog private constructor( val props = mutableMapOf() props["alias"] = alias + // The source identity is also duplicated into the properties so consumers that only + // read the event properties can resolve both sides of the alias linkage. + props["distinct_id"] = distinctId capture(PostHogEventName.CREATE_ALIAS.event, properties = props) } diff --git a/posthog/src/test/java/com/posthog/PostHogTest.kt b/posthog/src/test/java/com/posthog/PostHogTest.kt index 2ac6b9ffe..1c81a92d1 100644 --- a/posthog/src/test/java/com/posthog/PostHogTest.kt +++ b/posthog/src/test/java/com/posthog/PostHogTest.kt @@ -2008,6 +2008,7 @@ internal class PostHogTest { assertEquals("\$create_alias", theEvent.event) assertNotNull(theEvent.distinctId) assertEquals("theAlias", theEvent.properties!!["alias"] as String) + assertEquals(theEvent.distinctId, theEvent.properties!!["distinct_id"] as String) sut.close() }