Skip to content

Commit 43fa3cc

Browse files
committed
Send influenced session outcome
* Create separate outcome-related method `sendSessionEndOutcomeEvent` * We were also sending session_time in ms, but it should be seconds.
1 parent 19afb08 commit 43fa3cc

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/outcomes/IOutcomeEventsController.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ package com.onesignal.session.internal.outcomes
44
* The gateway to outcomes logic.
55
*/
66
interface IOutcomeEventsController {
7+
/**
8+
* Send a session ending outcome event to the backend.
9+
*/
10+
suspend fun sendSessionEndOutcomeEvent(duration: Long): IOutcomeEvent?
11+
712
/**
813
* Send a unique outcome event to the backend.
914
*/

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/outcomes/impl/OutcomeEventsController.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ Outcome event was cached and will be reattempted on app cold start""",
8181
}
8282
}
8383

84+
override suspend fun sendSessionEndOutcomeEvent(duration: Long): OutcomeEvent? {
85+
val influences: List<Influence> = _influenceManager.influences
86+
87+
// only send the outcome if there are any influences associated with the session
88+
for (influence in influences) {
89+
if (influence.ids != null) {
90+
return sendAndCreateOutcomeEvent("os__session_duration", 0f, duration, influences)
91+
}
92+
}
93+
return null
94+
}
95+
8496
override suspend fun sendUniqueOutcomeEvent(name: String): OutcomeEvent? {
8597
val sessionResult: List<Influence> = _influenceManager.influences
8698
return sendUniqueOutcomeEvent(name, sessionResult)

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/session/impl/SessionListener.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ internal class SessionListener(
4747
}
4848

4949
override fun onSessionEnded(duration: Long) {
50-
_operationRepo.enqueue(TrackSessionEndOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId, duration))
50+
val durationInSeconds = duration / 1000
51+
_operationRepo.enqueue(TrackSessionEndOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId, durationInSeconds))
5152

5253
suspendifyOnThread {
53-
_outcomeEventsController.sendOutcomeEvent("os__session_duration")
54+
_outcomeEventsController.sendSessionEndOutcomeEvent(durationInSeconds)
5455
}
5556
}
5657
}

0 commit comments

Comments
 (0)