File tree Expand file tree Collapse file tree 4 files changed +10
-6
lines changed
core/src/main/java/com/segment/analytics/kotlin/core Expand file tree Collapse file tree 4 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -513,9 +513,9 @@ open class Analytics protected constructor(
513
513
514
514
log(" applying base attributes on ${Thread .currentThread().name} " )
515
515
analyticsScope.launch(analyticsDispatcher) {
516
- event.applyBaseEventData(store)
516
+ event.applyBaseEventData(store, enrichment )
517
517
log(" processing event on ${Thread .currentThread().name} " )
518
- timeline.process(event, enrichment )
518
+ timeline.process(event)
519
519
}
520
520
}
521
521
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ typealias AnalyticsContext = JsonObject
12
12
typealias Integrations = JsonObject
13
13
typealias Properties = JsonObject
14
14
typealias Traits = JsonObject
15
+ typealias EnrichmentClosure = (event: BaseEvent ? ) -> BaseEvent ?
15
16
16
17
val emptyJsonObject = JsonObject (emptyMap())
17
18
val emptyJsonArray = JsonArray (emptyList())
@@ -75,6 +76,8 @@ sealed class BaseEvent {
75
76
76
77
abstract var _metadata : DestinationMetadata
77
78
79
+ var enrichment: EnrichmentClosure ? = null
80
+
78
81
companion object {
79
82
internal const val ALL_INTEGRATIONS_KEY = " All"
80
83
}
@@ -85,9 +88,10 @@ sealed class BaseEvent {
85
88
this .messageId = UUID .randomUUID().toString()
86
89
}
87
90
88
- internal suspend fun applyBaseEventData (store : Store ) {
91
+ internal suspend fun applyBaseEventData (store : Store , enrichment : EnrichmentClosure ? ) {
89
92
val userInfo = store.currentState(UserInfo ::class ) ? : return
90
93
94
+ this .enrichment = enrichment
91
95
this .anonymousId = userInfo.anonymousId
92
96
this .integrations = emptyJsonObject
93
97
Original file line number Diff line number Diff line change @@ -24,10 +24,10 @@ internal class Timeline {
24
24
lateinit var analytics: Analytics
25
25
26
26
// initiate the event's lifecycle
27
- fun process (incomingEvent : BaseEvent , enrichmentClosure : EnrichmentClosure ? = null ): BaseEvent ? {
27
+ fun process (incomingEvent : BaseEvent ): BaseEvent ? {
28
28
val beforeResult = applyPlugins(Plugin .Type .Before , incomingEvent)
29
29
var enrichmentResult = applyPlugins(Plugin .Type .Enrichment , beforeResult)
30
- enrichmentClosure ?.let {
30
+ enrichmentResult?.enrichment ?.let {
31
31
enrichmentResult = it(enrichmentResult)
32
32
}
33
33
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ class StartupQueue : Plugin, Subscriber {
72
72
// after checking if the queue is empty so we only process if the event
73
73
// if it is indeed not NULL.
74
74
event?.let {
75
- analytics.process(it)
75
+ analytics.process(it, it.enrichment )
76
76
}
77
77
}
78
78
}
You can’t perform that action at this time.
0 commit comments