@@ -3,10 +3,14 @@ package com.segment.analytics.liveplugins.kotlin
3
3
import android.content.Context
4
4
import com.segment.analytics.kotlin.android.Analytics
5
5
import com.segment.analytics.kotlin.core.Analytics
6
+ import com.segment.analytics.kotlin.core.BaseEvent
6
7
import com.segment.analytics.kotlin.core.platform.Plugin
8
+ import com.segment.analytics.kotlin.core.utilities.putInContext
7
9
import com.segment.analytics.substrata.kotlin.JSObject
8
10
import com.segment.analytics.substrata.kotlin.JSScope
9
11
import com.segment.analytics.substrata.kotlin.JsonElementConverter
12
+ import kotlinx.serialization.json.buildJsonObject
13
+ import kotlinx.serialization.json.put
10
14
import java.lang.ref.WeakReference
11
15
12
16
object LivePluginsHolder {
@@ -64,39 +68,57 @@ class JSAnalytics {
64
68
}
65
69
66
70
fun track (event : String ) {
67
- analytics.track(event)
71
+ analytics.track(event) {
72
+ it?.insertEventOrigin()
73
+ }
68
74
}
69
75
70
76
fun track (event : String , properties : JSObject ) {
71
- analytics.track(event, JsonElementConverter .read(properties))
77
+ analytics.track(event, JsonElementConverter .read(properties)) {
78
+ it?.insertEventOrigin()
79
+ }
72
80
}
73
81
74
82
fun identify (userId : String ) {
75
- analytics.identify(userId)
83
+ analytics.identify(userId) {
84
+ it?.insertEventOrigin()
85
+ }
76
86
}
77
87
78
88
fun identify (userId : String , traits : JSObject ) {
79
- analytics.identify(userId, JsonElementConverter .read(traits))
89
+ analytics.identify(userId, JsonElementConverter .read(traits)) {
90
+ it?.insertEventOrigin()
91
+ }
80
92
}
81
93
82
94
fun screen (title : String , category : String ) {
83
- analytics.screen(title, category)
95
+ analytics.screen(title, category) {
96
+ it?.insertEventOrigin()
97
+ }
84
98
}
85
99
86
100
fun screen (title : String , category : String , properties : JSObject ) {
87
- analytics.screen(title, JsonElementConverter .read(properties), category)
101
+ analytics.screen(title, JsonElementConverter .read(properties), category) {
102
+ it?.insertEventOrigin()
103
+ }
88
104
}
89
105
90
106
fun group (groupId : String ) {
91
- analytics.group(groupId)
107
+ analytics.group(groupId) {
108
+ it?.insertEventOrigin()
109
+ }
92
110
}
93
111
94
112
fun group (groupId : String , traits : JSObject ) {
95
- analytics.group(groupId, JsonElementConverter .read(traits))
113
+ analytics.group(groupId, JsonElementConverter .read(traits)) {
114
+ it?.insertEventOrigin()
115
+ }
96
116
}
97
117
98
118
fun alias (newId : String ) {
99
- analytics.alias(newId)
119
+ analytics.alias(newId) {
120
+ it?.insertEventOrigin()
121
+ }
100
122
}
101
123
102
124
fun flush () {
@@ -126,4 +148,10 @@ class JSAnalytics {
126
148
}
127
149
return result
128
150
}
151
+
152
+ private fun BaseEvent.insertEventOrigin () : BaseEvent {
153
+ return putInContext(" __eventOrigin" , buildJsonObject {
154
+ put(" type" , " js" )
155
+ })
156
+ }
129
157
}
0 commit comments