From b2f1d649fb287895495ed976e9e881dd3039ef59 Mon Sep 17 00:00:00 2001 From: Wenxi Zeng Date: Wed, 1 Oct 2025 14:55:39 -0500 Subject: [PATCH 1/3] add auto instrumentation settings --- .../main/java/com/segment/analytics/kotlin/core/Settings.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt b/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt index 13926816..a0efb34c 100644 --- a/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt +++ b/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt @@ -22,7 +22,8 @@ data class Settings( var edgeFunction: JsonObject = emptyJsonObject, var middlewareSettings: JsonObject = emptyJsonObject, var metrics: JsonObject = emptyJsonObject, - var consentSettings: JsonObject = emptyJsonObject + var consentSettings: JsonObject = emptyJsonObject, + var autoInstrumentation: JsonObject = emptyJsonObject ) { inline fun destinationSettings( name: String, From 2d78e4aa5c60201d34d8d3db3f5d4f67317c39d0 Mon Sep 17 00:00:00 2001 From: Wenxi Zeng Date: Mon, 6 Oct 2025 16:19:07 -0500 Subject: [PATCH 2/3] add subscribe and unsubscribe userinfo --- .../analytics/kotlin/core/Analytics.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt b/core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt index 0975d1eb..80598854 100644 --- a/core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt +++ b/core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt @@ -700,6 +700,69 @@ open class Analytics protected constructor( return anonymousId() } + /** + * Subscribes to UserInfo state changes. + * + * The handler is called immediately with the current UserInfo, then again whenever + * the user's identity, traits, or referrer changes. The subscription remains active + * for the lifetime of the Analytics instance unless explicitly unsubscribed. + * + * - Parameter handler: A closure called on the main queue with updated UserInfo. + * + * - Returns: A subscription ID that can be passed to `unsubscribe(_:)` to stop + * receiving updates. If you don't need to unsubscribe, you can ignore the return value. + * + * - Note: Multiple calls create multiple independent subscriptions. + * + * ## Example + * ```kotlin + * // Subscribe for the lifetime of Analytics + * analytics.subscribeToUserInfo { userInfo -> + * print("User: ${userInfo.userId ?: userInfo.anonymousId}") + * } + * + * // Subscribe with manual cleanup + * val subscriptionId = analytics.subscribeToUserInfo { userInfo -> + * // ... handle update + * } + * // Later, when you're done... + * analytics.unsubscribe(subscriptionId) + * ``` + * + */ + suspend fun subscribeToUserInfo(handler: (UserInfo) -> Unit) = + store.subscribe( + this, + UserInfo::class, + initialState = true, + handler = handler, + queue = fileIODispatcher + ) + + /** + * Unsubscribes from state updates. + * + * Stops receiving updates for the subscription associated with the given ID. + * After calling this, the handler will no longer be invoked for state changes. + * + * - Parameter id: The subscription ID returned from a previous subscribe call. + * + * - Note: Unsubscribing an already-unsubscribed or invalid ID is a no-op. + * + * ## Example + * ```kotlin + * val id = analytics.subscribeToUserInfo { userInfo -> + * print("User changed: ${userInfo.userId ?: "anonymous"}") + * } + * + * // Later, stop listening + * analytics.unsubscribe(id) + * ``` + */ + suspend fun unsubscribe(id: Int) { + store.unsubscribe(id) + } + /** * Retrieve the version of this library in use. * - Returns: A string representing the version in "BREAKING.FEATURE.FIX" format. From 5a35953968a08eb956fd1a60f5694ff3cd32d955 Mon Sep 17 00:00:00 2001 From: Wenxi Zeng Date: Tue, 7 Oct 2025 15:13:34 -0500 Subject: [PATCH 3/3] update ci --- .github/workflows/build.yml | 8 +++++++- .github/workflows/release.yml | 7 ++++++- .github/workflows/snapshot.yml | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 493cc5bc..dc6e5b86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,13 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + - name: Grant execute permission for gradlew run: chmod +x gradlew - name: cache gradle dependencies diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 742d0f40..0b2e27d7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,12 @@ jobs: runs-on: ubuntu-22.04 environment: deployment steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' - name: Get tag id: vars run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index b65c32cd..5f5f2f73 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -9,7 +9,12 @@ jobs: runs-on: ubuntu-22.04 environment: deployment steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' - name: Grant execute permission for gradlew run: chmod +x gradlew - name: cache gradle dependencies