File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
lib/src/main/java/com/segment/analytics/kotlin/destinations/amplitude Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,8 @@ class AmplitudeSession (private val sessionTimeoutMs : Long = 300000) : EventPlu
9191 )
9292
9393 var modified = super .execute(event)
94+ modified = insertSession(modified)
95+
9496 if (modified is ScreenEvent ) {
9597 val screenName = modified.name
9698 modified.properties = updateJsonObject(modified.properties) {
@@ -109,7 +111,6 @@ class AmplitudeSession (private val sessionTimeoutMs : Long = 300000) : EventPlu
109111 }
110112 else if (modified.event.contains(AMP_PREFIX )) {
111113 modified = modified.disableCloudIntegrations(exceptKeys = listOf (key))
112- modified = modified.putIntegrations(key, mapOf (" session_id" to sessionId))
113114 }
114115 }
115116
@@ -128,6 +129,15 @@ class AmplitudeSession (private val sessionTimeoutMs : Long = 300000) : EventPlu
128129 return payload
129130 }
130131
132+ private fun insertSession (event : BaseEvent ? ): BaseEvent ? {
133+ // for session start or session end, session id is already attached, so skip it
134+ if (event?.integrations?.get(key)?.safeJsonObject?.containsKey(" session_id" ) == true ) {
135+ return event
136+ }
137+
138+ return event?.putIntegrations(key, mapOf (" session_id" to sessionId))
139+ }
140+
131141 private fun onBackground () {
132142 lastEventTime = java.lang.System .currentTimeMillis()
133143 }
You can’t perform that action at this time.
0 commit comments