Skip to content

Commit 30b5cf6

Browse files
committed
pr suggestions
1 parent 85d5763 commit 30b5cf6

File tree

10 files changed

+101
-79
lines changed

10 files changed

+101
-79
lines changed

core/src/main/kotlin/io/customer/sdk/core/pipeline/DataPipeline.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ import io.customer.base.internal.InternalCustomerIOApi
1212
*/
1313
@InternalCustomerIOApi
1414
interface DataPipeline {
15-
val userId: String?
15+
val isUserIdentified: Boolean
1616
fun track(name: String, properties: Map<String, Any?>)
1717
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.customer.sdk.core.pipeline
2+
3+
import io.customer.base.internal.InternalCustomerIOApi
4+
5+
/**
6+
* Interface for modules that contribute context entries to identify events.
7+
*
8+
* Implementations return a map of primitive-valued entries (String, Number, Boolean)
9+
* that will be added to the identify event's context via `putInContext()`.
10+
* Return an empty map when there is nothing to contribute.
11+
*
12+
* These are NOT profile traits/attributes — they are context-level enrichment
13+
* data (e.g., location coordinates) attached to the identify event payload.
14+
*
15+
* This is an internal SDK contract — not intended for use by host app developers.
16+
*/
17+
@InternalCustomerIOApi
18+
interface IdentifyContextProvider {
19+
fun getIdentifyContext(): Map<String, Any>
20+
}

core/src/main/kotlin/io/customer/sdk/core/pipeline/ProfileEnrichmentRegistry.kt renamed to core/src/main/kotlin/io/customer/sdk/core/pipeline/IdentifyContextRegistry.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ import io.customer.base.internal.InternalCustomerIOApi
44
import io.customer.sdk.core.di.SDKComponent
55

66
/**
7-
* Thread-safe registry of [ProfileEnrichmentProvider] instances.
7+
* Thread-safe registry of [IdentifyContextProvider] instances.
88
*
99
* Modules register providers during initialization. The datapipelines module
10-
* queries all providers when enriching identify events.
10+
* queries all providers when enriching identify event context.
1111
*
1212
* Cleared automatically when [SDKComponent.reset] clears singletons.
1313
*
1414
* This is an internal SDK contract — not intended for use by host app developers.
1515
*/
1616
@InternalCustomerIOApi
17-
class ProfileEnrichmentRegistry {
18-
private val providers = mutableListOf<ProfileEnrichmentProvider>()
17+
class IdentifyContextRegistry {
18+
private val providers = mutableListOf<IdentifyContextProvider>()
1919

2020
@Synchronized
21-
fun register(provider: ProfileEnrichmentProvider) {
21+
fun register(provider: IdentifyContextProvider) {
2222
if (provider !in providers) {
2323
providers.add(provider)
2424
}
2525
}
2626

2727
@Synchronized
28-
fun getAll(): List<ProfileEnrichmentProvider> = providers.toList()
28+
fun getAll(): List<IdentifyContextProvider> = providers.toList()
2929

3030
@Synchronized
3131
fun clear() {
@@ -34,8 +34,8 @@ class ProfileEnrichmentRegistry {
3434
}
3535

3636
/**
37-
* Singleton accessor for [ProfileEnrichmentRegistry] via [SDKComponent].
37+
* Singleton accessor for [IdentifyContextRegistry] via [SDKComponent].
3838
*/
3939
@InternalCustomerIOApi
40-
val SDKComponent.profileEnrichmentRegistry: ProfileEnrichmentRegistry
41-
get() = singleton { ProfileEnrichmentRegistry() }
40+
val SDKComponent.identifyContextRegistry: IdentifyContextRegistry
41+
get() = singleton { IdentifyContextRegistry() }

core/src/main/kotlin/io/customer/sdk/core/pipeline/ProfileEnrichmentProvider.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

datapipelines/api/datapipelines.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public final class io/customer/sdk/CustomerIO : io/customer/sdk/DataPipelineInst
144144
public fun initialize ()V
145145
public static final fun initialize (Lio/customer/sdk/CustomerIOConfig;)V
146146
public static final fun instance ()Lio/customer/sdk/CustomerIO;
147+
public fun isUserIdentified ()Z
147148
public fun setDeviceAttributes (Ljava/util/Map;)V
148149
public fun setDeviceAttributesDeprecated (Ljava/util/Map;)V
149150
public fun setProfileAttributes (Ljava/util/Map;)V

datapipelines/src/main/kotlin/io/customer/datapipelines/plugins/ProfileEnrichmentPlugin.kt renamed to datapipelines/src/main/kotlin/io/customer/datapipelines/plugins/IdentifyContextPlugin.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import com.segment.analytics.kotlin.core.IdentifyEvent
66
import com.segment.analytics.kotlin.core.platform.EventPlugin
77
import com.segment.analytics.kotlin.core.platform.Plugin
88
import com.segment.analytics.kotlin.core.utilities.putInContext
9-
import io.customer.sdk.core.pipeline.ProfileEnrichmentRegistry
9+
import io.customer.sdk.core.pipeline.IdentifyContextRegistry
1010
import io.customer.sdk.core.util.Logger
1111
import kotlinx.serialization.json.JsonPrimitive
1212

1313
/**
1414
* Generic Segment enrichment plugin that queries all registered
15-
* [ProfileEnrichmentProvider] instances and adds their attributes
16-
* to identify event context.
15+
* [IdentifyContextProvider][io.customer.sdk.core.pipeline.IdentifyContextProvider]
16+
* instances and adds their entries to the identify event context.
1717
*
1818
* This plugin has zero knowledge of specific modules — providers
1919
* manage their own state and return primitive-valued maps.
2020
*/
21-
internal class ProfileEnrichmentPlugin(
22-
private val registry: ProfileEnrichmentRegistry,
21+
internal class IdentifyContextPlugin(
22+
private val registry: IdentifyContextRegistry,
2323
private val logger: Logger
2424
) : EventPlugin {
2525
override val type: Plugin.Type = Plugin.Type.Enrichment
@@ -28,21 +28,22 @@ internal class ProfileEnrichmentPlugin(
2828
override fun identify(payload: IdentifyEvent): BaseEvent {
2929
for (provider in registry.getAll()) {
3030
try {
31-
val attributes = provider.getProfileEnrichmentAttributes() ?: continue
32-
for ((key, value) in attributes) {
31+
val context = provider.getIdentifyContext()
32+
if (context.isEmpty()) continue
33+
for ((key, value) in context) {
3334
val jsonValue = when (value) {
3435
is String -> JsonPrimitive(value)
3536
is Number -> JsonPrimitive(value)
3637
is Boolean -> JsonPrimitive(value)
3738
else -> {
38-
logger.debug("Skipping non-primitive enrichment attribute: $key")
39+
logger.debug("Skipping non-primitive context entry: $key")
3940
continue
4041
}
4142
}
4243
payload.putInContext(key, jsonValue)
4344
}
4445
} catch (e: Exception) {
45-
logger.error("ProfileEnrichmentProvider failed: ${e.message}")
46+
logger.error("IdentifyContextProvider failed: ${e.message}")
4647
}
4748
}
4849
return payload

datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import io.customer.datapipelines.plugins.AutomaticActivityScreenTrackingPlugin
2525
import io.customer.datapipelines.plugins.AutomaticApplicationLifecycleTrackingPlugin
2626
import io.customer.datapipelines.plugins.ContextPlugin
2727
import io.customer.datapipelines.plugins.CustomerIODestination
28-
import io.customer.datapipelines.plugins.ProfileEnrichmentPlugin
28+
import io.customer.datapipelines.plugins.IdentifyContextPlugin
2929
import io.customer.datapipelines.plugins.ScreenFilterPlugin
3030
import io.customer.sdk.communication.Event
3131
import io.customer.sdk.communication.subscribe
3232
import io.customer.sdk.core.di.AndroidSDKComponent
3333
import io.customer.sdk.core.di.SDKComponent
3434
import io.customer.sdk.core.module.CustomerIOModule
3535
import io.customer.sdk.core.pipeline.DataPipeline
36-
import io.customer.sdk.core.pipeline.profileEnrichmentRegistry
36+
import io.customer.sdk.core.pipeline.identifyContextRegistry
3737
import io.customer.sdk.core.util.CioLogLevel
3838
import io.customer.sdk.core.util.Logger
3939
import io.customer.sdk.data.model.CustomAttributes
@@ -130,7 +130,7 @@ class CustomerIO private constructor(
130130

131131
// Add plugin to filter events based on SDK configuration
132132
analytics.add(ScreenFilterPlugin(moduleConfig.screenViewUse))
133-
analytics.add(ProfileEnrichmentPlugin(SDKComponent.profileEnrichmentRegistry, logger))
133+
analytics.add(IdentifyContextPlugin(SDKComponent.identifyContextRegistry, logger))
134134
analytics.add(ApplicationLifecyclePlugin())
135135

136136
// Register this instance as DataPipeline so modules can send track events directly
@@ -325,6 +325,9 @@ class CustomerIO private constructor(
325325
override val userId: String?
326326
get() = analytics.userId()
327327

328+
override val isUserIdentified: Boolean
329+
get() = !analytics.userId().isNullOrEmpty()
330+
328331
@Deprecated("Use setDeviceAttributes() function instead")
329332
@set:JvmName("setDeviceAttributesDeprecated")
330333
override var deviceAttributes: CustomAttributes

location/src/main/kotlin/io/customer/location/LocationTracker.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package io.customer.location
33
import io.customer.location.store.LocationPreferenceStore
44
import io.customer.location.sync.LocationSyncFilter
55
import io.customer.sdk.core.pipeline.DataPipeline
6-
import io.customer.sdk.core.pipeline.ProfileEnrichmentProvider
6+
import io.customer.sdk.core.pipeline.IdentifyContextProvider
77
import io.customer.sdk.core.util.Logger
88
import io.customer.sdk.util.EventNames
99

1010
/**
1111
* Coordinates all location state management: persistence, restoration,
1212
* profile enrichment, and sending location track events.
1313
*
14-
* Implements [ProfileEnrichmentProvider] to enrich identify events with
15-
* the latest location. Sends location track events directly via
14+
* Implements [IdentifyContextProvider] to enrich identify event context
15+
* with the latest location. Sends location track events directly via
1616
* [DataPipeline], applying the userId gate and sync filter locally.
1717
*
1818
* Tracks the last known userId to detect profile switches and reset
@@ -23,16 +23,16 @@ internal class LocationTracker(
2323
private val locationPreferenceStore: LocationPreferenceStore,
2424
private val locationSyncFilter: LocationSyncFilter,
2525
private val logger: Logger
26-
) : ProfileEnrichmentProvider {
26+
) : IdentifyContextProvider {
2727

2828
@Volatile
2929
private var lastLocation: LocationCoordinates? = null
3030

3131
@Volatile
3232
private var lastKnownUserId: String? = null
3333

34-
override fun getProfileEnrichmentAttributes(): Map<String, Any>? {
35-
val location = lastLocation ?: return null
34+
override fun getIdentifyContext(): Map<String, Any> {
35+
val location = lastLocation ?: return emptyMap()
3636
return mapOf(
3737
"location_latitude" to location.latitude,
3838
"location_longitude" to location.longitude
@@ -115,7 +115,7 @@ internal class LocationTracker(
115115
*/
116116
private fun trySendLocationTrack(latitude: Double, longitude: Double) {
117117
val pipeline = dataPipeline ?: return
118-
if (pipeline.userId.isNullOrEmpty()) return
118+
if (!pipeline.isUserIdentified) return
119119
if (!locationSyncFilter.filterAndRecord(latitude, longitude)) return
120120

121121
logger.debug("Sending location track: lat=$latitude, lng=$longitude")

location/src/main/kotlin/io/customer/location/ModuleLocation.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.customer.sdk.communication.subscribe
1010
import io.customer.sdk.core.di.SDKComponent
1111
import io.customer.sdk.core.module.CustomerIOModule
1212
import io.customer.sdk.core.pipeline.DataPipeline
13-
import io.customer.sdk.core.pipeline.profileEnrichmentRegistry
13+
import io.customer.sdk.core.pipeline.identifyContextRegistry
1414
import io.customer.sdk.core.util.Logger
1515

1616
/**
@@ -46,6 +46,7 @@ class ModuleLocation @JvmOverloads constructor(
4646
) : CustomerIOModule<LocationModuleConfig> {
4747
override val moduleName: String = MODULE_NAME
4848

49+
@Volatile
4950
private var _locationServices: LocationServices? = null
5051

5152
/**
@@ -76,8 +77,8 @@ class ModuleLocation @JvmOverloads constructor(
7677

7778
locationTracker.restorePersistedLocation()
7879

79-
// Register as ProfileEnrichmentProvider for identify enrichment
80-
SDKComponent.profileEnrichmentRegistry.register(locationTracker)
80+
// Register as IdentifyContextProvider so location is added to identify event context
81+
SDKComponent.identifyContextRegistry.register(locationTracker)
8182

8283
eventBus.subscribe<Event.ResetEvent> {
8384
locationTracker.onReset()

0 commit comments

Comments
 (0)