Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*/}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions core/src/main/java/com/segment/analytics/kotlin/core/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reified T : Any> destinationSettings(
name: String,
Expand Down