From 8ed0e9fa90c2543322dd8d467156cad2b78cdf3f Mon Sep 17 00:00:00 2001 From: vincentborko Date: Mon, 1 Jun 2026 15:11:05 +0200 Subject: [PATCH] feat(config): bridge PostHogConfig.getAnonymousId closure Expose the settable `getAnonymousId: (UUID) -> UUID` closure on PostHogConfig, mirroring posthog-ios/posthog-android. On Android the closure operates on java.util.UUID; the #if SKIP branch bridges to Foundation UUID via KotlinConverting (.kotlin() / init(platformValue:)). Lets apps seed PostHog's anonymous distinct_id from a durable client id so flag/experiment bucketing stays stable across the anon->identified switch. Co-Authored-By: Claude Opus 4.8 (1M context) --- Sources/SkipPostHog/SkipPostHog.swift | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sources/SkipPostHog/SkipPostHog.swift b/Sources/SkipPostHog/SkipPostHog.swift index 724204c..d3b13a7 100644 --- a/Sources/SkipPostHog/SkipPostHog.swift +++ b/Sources/SkipPostHog/SkipPostHog.swift @@ -763,6 +763,35 @@ public class PostHogConfig { } } + /// A closure that derives the anonymous ID for the current user. It receives + /// a freshly generated `UUID` and returns the `UUID` PostHog should use as + /// the anonymous identifier. + /// + /// Use this to seed the anonymous ID from a durable client identifier so the + /// same device keeps a stable distinct ID across reinstalls. Mirrors the iOS + /// `PostHogConfig.getAnonymousId` and Android `PostHogConfig.getAnonymousId`. + /// + /// On Android the underlying closure operates on `java.util.UUID`; the + /// `#if SKIP` branch bridges that to Foundation `UUID` via `KotlinConverting`. + public var getAnonymousId: (UUID) -> UUID { + get { + #if !SKIP + self.platformValue.getAnonymousId + #else + let platformClosure = self.platformValue.getAnonymousId + return { uuid in UUID(platformValue: platformClosure(uuid.kotlin())) } + #endif + } + + set { + #if !SKIP + self.platformValue.getAnonymousId = newValue + #else + self.platformValue.getAnonymousId = { uuid in newValue(UUID(platformValue: uuid)).kotlin() } + #endif + } + } + public var personProfiles: PostHogPersonProfiles { get { #if !SKIP