Skip to content

Commit 394381e

Browse files
committed
Update Attributed Time Processor to use new methods
* The attributed time processor needs to send data to two separate places: session_time for Update User and session time for Outcomes. * Before sending data to outcomes, it needs to wait 30 seconds to see if the app re-opens in case the SDK will continue on the same session, this is for the outcomes endpoint to know session count for influences. * It will now send session_time to the user manager immediately as this does not need to wait for 30 seconds. The ordering will be correct when the app is backgrounded. This time is sent to the user manager who enqueues a delta with the session time. Then the Operation Repo will start its background task and flush deltas. * It will only send the elapsed time and does not need to handle unsent active time. This is because previous session times will be their own Delta instances that the operation repo / executor handles with retrying. These previous deltas already encompass the unsent active time. * The Attributed Time Processor still has a separate background task that handles sending the outcome, manages the 30 seconds wait time, and maintains a background task for it. It uses unsent active time and resets to 0 when the request is successful.
1 parent 58c8c79 commit 394381e

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ typedef enum {ATTRIBUTED, NOT_ATTRIBUTED} FocusAttributionState;
192192

193193
// OneSignal Background Task Identifiers
194194
#define ATTRIBUTED_FOCUS_TASK @"ATTRIBUTED_FOCUS_TASK"
195-
#define SEND_SESSION_TIME_TO_USER_TASK @"SEND_SESSION_TIME_TO_USER_TASK"
196195
#define OPERATION_REPO_BACKGROUND_TASK @"OPERATION_REPO_BACKGROUND_TASK"
197196
#define IDENTITY_EXECUTOR_BACKGROUND_TASK @"IDENTITY_EXECUTOR_BACKGROUND_TASK_"
198197
#define PROPERTIES_EXECUTOR_BACKGROUND_TASK @"PROPERTIES_EXECUTOR_BACKGROUND_TASK_"

iOS_SDK/OneSignalSDK/Source/OSAttributedFocusTimeProcessor.m

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ @implementation OSAttributedFocusTimeProcessor {
4444
- (instancetype)init {
4545
self = [super init];
4646
[OSBackgroundTaskManager setTaskInvalid:ATTRIBUTED_FOCUS_TASK];
47-
[OSBackgroundTaskManager setTaskInvalid:SEND_SESSION_TIME_TO_USER_TASK];
48-
4947
return self;
5048
}
5149

@@ -64,6 +62,10 @@ - (void)sendOnFocusCall:(OSFocusCallParams *)params {
6462
message:[NSString stringWithFormat:@"sendOnFocusCall attributed with totalTimeActive %f", totalTimeActive]];
6563

6664
[super saveUnsentActiveTime:totalTimeActive];
65+
66+
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"OSAttributedFocusTimeProcessor:sendSessionTime of %@", @(params.timeElapsed)]];
67+
[OneSignalUserManagerImpl.sharedInstance sendSessionTime:@(params.timeElapsed)];
68+
6769
[self sendOnFocusCallWithParams:params totalTimeActive:totalTimeActive];
6870
}
6971

@@ -83,7 +85,6 @@ - (void)sendOnFocusCallWithParams:(OSFocusCallParams *)params totalTimeActive:(N
8385
}
8486

8587
[OSBackgroundTaskManager beginBackgroundTask:ATTRIBUTED_FOCUS_TASK];
86-
[OSBackgroundTaskManager beginBackgroundTask:SEND_SESSION_TIME_TO_USER_TASK];
8788

8889
if (params.onSessionEnded) {
8990
[self sendBackgroundAttributedSessionTimeWithParams:params withTotalTimeActive:@(totalTimeActive)];
@@ -108,20 +109,10 @@ - (void)sendBackgroundAttributedSessionTimeWithNSTimer:(NSTimer*)timer {
108109
- (void)sendBackgroundAttributedSessionTimeWithParams:(OSFocusCallParams *)params withTotalTimeActive:(NSNumber*)totalTimeActive {
109110
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:@"OSAttributedFocusTimeProcessor:sendBackgroundAttributedSessionTimeWithParams start"];
110111

111-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
112-
[OneSignalUserManagerImpl.sharedInstance updateSessionWithSessionCount:nil sessionTime:totalTimeActive refreshDeviceMetadata:false sendImmediately:true onSuccess:^{
113-
[super saveUnsentActiveTime:0];
114-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:@"sendBackgroundAttributed session time succeed, saveUnsentActiveTime with 0"];
115-
[OSBackgroundTaskManager endBackgroundTask:SEND_SESSION_TIME_TO_USER_TASK];
116-
} onFailure:^{
117-
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"sendBackgroundAttributed session time failed, will retry on next open"];
118-
[OSBackgroundTaskManager endBackgroundTask:SEND_SESSION_TIME_TO_USER_TASK];
119-
}];
120-
});
121-
122112
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
123113
[OneSignal sendSessionEndOutcomes:totalTimeActive params:params onSuccess:^(NSDictionary *result) {
124114
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:@"sendBackgroundAttributed succeed"];
115+
[super saveUnsentActiveTime:0];
125116
[OSBackgroundTaskManager endBackgroundTask:ATTRIBUTED_FOCUS_TASK];
126117
} onFailure:^(NSError *error) {
127118
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"sendBackgroundAttributed failed, will retry on next open"];
@@ -137,8 +128,6 @@ - (void)cancelDelayedJob {
137128
[restCallTimer invalidate];
138129
restCallTimer = nil;
139130
[OSBackgroundTaskManager endBackgroundTask:ATTRIBUTED_FOCUS_TASK];
140-
[OSBackgroundTaskManager endBackgroundTask:SEND_SESSION_TIME_TO_USER_TASK];
141-
142131
}
143132

144133
@end

0 commit comments

Comments
 (0)