[5.0.0] Fix outcome requests#1793
Conversation
* Add `sessionTime` as an additional property to an `OutcomeEvent` object * This is for the influenced session ending outcomes that send session_time to the outcomes endpoint * For `OutcomeEventParams` constructor, don't make the parameter `timestamp` optional, so not to confuse with other parameters when instantiating an instance
* Create separate outcome-related method `sendSessionEndOutcomeEvent` * We were also sending session_time in ms, but it should be seconds.
* Update database version to v9 and make migration. * I default this new `session_time` to a value of `1` instead of `0` intentionally to work around an issue from the v5.0.0-beta's for migration's sake and get these outcomes migrated, sent, and done with. * When outcome requests fail, they are cached for retrying. The v5.0.0-beta's likely encountered failure responses and cached these. If there are cached `os__session_duration` outcomes and we send them off with zero session_time, the server will keep sending us a failure response. So, let's just send a time of 1 second.
| var weight: Float, // This field is optional. | ||
| var timestamp: Long = 0, | ||
| var sessionTime: Long, // This field is optional | ||
| var timestamp: Long, |
There was a problem hiding this comment.
timestamp previously set its default value to 0. Was removing this default intentional?
There was a problem hiding this comment.
Yes it was intentional, it was briefly mentioned in a commit but here is more information about why I changed it.
The SDK actually always passed in a value for timestamp to the OutcomeEventParams constructor, so this default was not needed. In addition, it was not to confuse with the new sessionTime parameter. After adding sessionTime to the constructor, the app and unit tests built because the argument we used to pass for timestamp is now interpreted as sessionTime and sessionTime started defaulting to 0.
But I think it is a good note what this parameter means, that it starts out 0 until it fails and becomes cached.
emawby
left a comment
There was a problem hiding this comment.
Reviewed 7 of 8 files at r1, 9 of 9 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jennantilla, @jkasten2, and @shepherd-l)
* When an outcome is created, its `timestamp` should start out as zero. * When the outcome request is sent and fails, the SDK will save and retry the outcome, then it will save the current `timestamp` for future sending
[5.0.0] Fix outcome requests
[5.0.0] Fix outcome requests
[5.0.0] Fix outcome requests
Description
One Line Summary
Fix outcome request payload to include
device_typeandsession_time(if the outcome type isos__session_duration).Details
Motivation
The outcomes endpoint expects
device_typeto be in the request body but we were not sending it, and we receive a 400 error in response. Now, we will always sendtypein thesubscriptiondata.{ "app_id": "YOUR_APP_ID", "onesignal_id": "YOUR_ONESIGNAL_ID", "subscription": { "id": "YOUR_PUSH_SUBSCRIPTION_ID", "type": "AndroidPush" }, "id": "some_outcome_value" }The second problem this PR addresses is for influenced session ending outcomes, the server expects a non-zero value for
session_timeto be in the request body if the outcome has an ID ofos__session_duration. However, we were not sendingsession_timeand receive a 400 error response"There was a problem in the JSON you submitted","\"session_time\" must be positive when submitting os__session_duration". Now, we sill send anos__session_durationoutcome withsession_timeif the session that just ended is attributed.Another detail is that failed outcome requests keep the outcome in the cache (database) so that they are re-sent on the next app start.
Note that before, we were sending a
os__session_durationoutcome with no influences when a session that just ended is unattributed. We will no longer do this, but these outcomes may be cached and need to be addressed.The
session_timethat we were sending to update user endpoint was actually in milliseconds, and this is fixed in this PR to be seconds, which is what the server expects.To make the minimal amount of changes, I added a
session_timeproperty toOutcomeEventand a new column to the outcomes table. Not all outcomes will utilizesession_timeif these areaddOutcomemethods.Scope
session_time.session_timeof1just to get them successfully sent and done with, even though thissession_timemay not be accurate. Otherwise, they may keep staying in the cache and retrying.Details about Commits Below
1. Add device type to the outcome event request
2. Add session_time to OutcomeEvent
sessionTimeas an additional property to anOutcomeEventobjectOutcomeEventParamsconstructor, don't make the parametertimestampoptional, so not to confuse with other parameters when instantiating an instance3. Send influenced session outcome
sendSessionEndOutcomeEvent4. update outcomes table to include session_time column
session_timeto a value of1instead of0intentionally to work around an issue from the v5.0.0-beta's for migration's sake and get these outcomes migrated, sent, and done with.os__session_durationoutcomes and we send them off with zero session_time, the server will keep sending us a failure response. So, let's just send a time of 1 second.Testing
Unit testing
Manual testing
Tested on Pixel emulator on API 30.
session_timeof1added, successful response, and be removed from the outcomes tableAffected code checklist
Checklist
Overview
Testing
Final pass
This change is