Skip to content

Commit 5d04aeb

Browse files
committed
Add device type to the outcome event request
1 parent 81fc303 commit 5d04aeb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ internal interface IOutcomeEventsBackendService {
1515
* @param appId The ID of the application this outcome event occurred under.
1616
* @param userId The OneSignal user ID that is active during the outcome event.
1717
* @param subscriptionId The subscription ID that is active during the outcome event.
18+
* @param deviceType The type of device that the outcome event occurred on.
1819
* @param direct Whether this outcome event is direct. `true` if it is, `false` if it isn't, `null` if should not be specified.
1920
* @param event The outcome event to send up.
2021
*/
21-
suspend fun sendOutcomeEvent(appId: String, userId: String, subscriptionId: String, direct: Boolean?, event: OutcomeEvent)
22+
suspend fun sendOutcomeEvent(appId: String, userId: String, subscriptionId: String, deviceType: String, direct: Boolean?, event: OutcomeEvent)
2223
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import org.json.JSONObject
77
internal class OutcomeEventsBackendService(private val _http: IHttpClient) :
88
IOutcomeEventsBackendService {
99

10-
override suspend fun sendOutcomeEvent(appId: String, userId: String, subscriptionId: String, direct: Boolean?, event: OutcomeEvent) {
10+
override suspend fun sendOutcomeEvent(appId: String, userId: String, subscriptionId: String, deviceType: String, direct: Boolean?, event: OutcomeEvent) {
1111
val jsonObject = JSONObject()
1212
.put("app_id", appId)
1313
.put("onesignal_id", userId)
1414
.put(
1515
"subscription",
1616
JSONObject()
17-
.put("id", subscriptionId),
17+
.put("id", subscriptionId)
18+
.put("type", deviceType)
1819
)
1920

2021
if (direct != null) {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Process
44
import com.onesignal.common.exceptions.BackendException
55
import com.onesignal.common.threading.suspendifyOnThread
66
import com.onesignal.core.internal.config.ConfigModelStore
7+
import com.onesignal.core.internal.device.IDeviceService
78
import com.onesignal.core.internal.startup.IStartableService
89
import com.onesignal.core.internal.time.ITime
910
import com.onesignal.debug.internal.logging.Logging
@@ -14,6 +15,7 @@ import com.onesignal.session.internal.influence.InfluenceType
1415
import com.onesignal.session.internal.outcomes.IOutcomeEventsController
1516
import com.onesignal.session.internal.session.ISessionLifecycleHandler
1617
import com.onesignal.session.internal.session.ISessionService
18+
import com.onesignal.user.internal.backend.SubscriptionObjectType
1719
import com.onesignal.user.internal.identity.IdentityModelStore
1820
import com.onesignal.user.internal.subscriptions.ISubscriptionManager
1921

@@ -26,6 +28,7 @@ internal class OutcomeEventsController(
2628
private val _configModelStore: ConfigModelStore,
2729
private val _identityModelStore: IdentityModelStore,
2830
private val _subscriptionManager: ISubscriptionManager,
31+
private val _deviceService: IDeviceService,
2932
private val _time: ITime,
3033
) : IOutcomeEventsController, IStartableService, ISessionLifecycleHandler {
3134
// Keeps track of unique outcome events sent for UNATTRIBUTED sessions on a per session level
@@ -267,10 +270,11 @@ Outcome event was cached and will be reattempted on app cold start""",
267270
private suspend fun requestMeasureOutcomeEvent(eventParams: OutcomeEventParams) {
268271
val appId: String = _configModelStore.model.appId
269272
val subscriptionId = _subscriptionManager.subscriptions.push.id
273+
val deviceType = SubscriptionObjectType.fromDeviceType(_deviceService.deviceType).value
270274

271275
// if we don't have a subscription ID yet, throw an exception. The outcome will be saved and processed
272276
// later, when we do have a subscription ID.
273-
if (subscriptionId.isEmpty()) {
277+
if (subscriptionId.isEmpty() || deviceType.isEmpty()) {
274278
throw BackendException(0)
275279
}
276280

@@ -282,6 +286,6 @@ Outcome event was cached and will be reattempted on app cold start""",
282286
else -> null
283287
}
284288

285-
_outcomeEventsBackend.sendOutcomeEvent(appId, _identityModelStore.model.onesignalId, subscriptionId, direct, event)
289+
_outcomeEventsBackend.sendOutcomeEvent(appId, _identityModelStore.model.onesignalId, subscriptionId, deviceType, direct, event)
286290
}
287291
}

0 commit comments

Comments
 (0)