Skip to content

Commit 0dc55fe

Browse files
committed
Refactor outcomes and add IAM tracking
* Add OutcomesEventsFactory to decide which repository to use * Add new outcome models given the new feature IAM v2 Outcomes * Add concepts of channels and influence * Add IAM tracking for indirect and direct influence * Add ability for future channels * Decouple influence tracking module to new package * Several changes for decouple code * Add testing to new functionality * Add testing for IAM tracking * Add testing for session ending * Add testing for V2 measure
1 parent c161fdf commit 0dc55fe

File tree

88 files changed

+6935
-1318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+6935
-1318
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 303 additions & 67 deletions
Large diffs are not rendered by default.

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/xcshareddata/xcschemes/UnitTests.xcscheme

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,11 @@
1010
buildConfiguration = "Debug"
1111
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1212
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13-
language = ""
1413
shouldUseLaunchSchemeArgsEnv = "NO">
15-
<Testables>
16-
<TestableReference
17-
skipped = "NO">
18-
<BuildableReference
19-
BuildableIdentifier = "primary"
20-
BlueprintIdentifier = "911E2CB91E398AB3003112A4"
21-
BuildableName = "UnitTests.xctest"
22-
BlueprintName = "UnitTests"
23-
ReferencedContainer = "container:OneSignal.xcodeproj">
24-
</BuildableReference>
25-
</TestableReference>
26-
</Testables>
2714
<EnvironmentVariables>
2815
<EnvironmentVariable
2916
key = "OS_ACTIVITY_MODE"
17+
value = ""
3018
isEnabled = "YES">
3119
</EnvironmentVariable>
3220
</EnvironmentVariables>
@@ -37,12 +25,23 @@
3725
isEnabled = "YES">
3826
</AdditionalOption>
3927
</AdditionalOptions>
28+
<Testables>
29+
<TestableReference
30+
skipped = "NO">
31+
<BuildableReference
32+
BuildableIdentifier = "primary"
33+
BlueprintIdentifier = "911E2CB91E398AB3003112A4"
34+
BuildableName = "UnitTests.xctest"
35+
BlueprintName = "UnitTests"
36+
ReferencedContainer = "container:OneSignal.xcodeproj">
37+
</BuildableReference>
38+
</TestableReference>
39+
</Testables>
4040
</TestAction>
4141
<LaunchAction
4242
buildConfiguration = "Debug"
4343
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4444
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
45-
language = ""
4645
launchStyle = "0"
4746
useCustomWorkingDirectory = "NO"
4847
ignoresPersistentStateOnLaunch = "NO"
@@ -56,8 +55,6 @@
5655
isEnabled = "YES">
5756
</EnvironmentVariable>
5857
</EnvironmentVariables>
59-
<AdditionalOptions>
60-
</AdditionalOptions>
6158
</LaunchAction>
6259
<ProfileAction
6360
buildConfiguration = "Release"

iOS_SDK/OneSignalSDK/Source/OSAttributedFocusTimeProcessor.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ - (void)sendBackgroundAttributedFocusPingWithParams:(OSFocusCallParams*)params w
113113

114114
let requests = [NSMutableDictionary new];
115115

116-
requests[@"push"] = [OSRequestOnFocus withUserId:params.userId appId:params.appId activeTime:totalTimeActive netType:params.netType emailAuthToken:nil deviceType:@(DEVICE_TYPE_PUSH) directSession:params.direct notificationIds:params.notificationIds];
116+
requests[@"push"] = [OSRequestOnFocus withUserId:params.userId appId:params.appId activeTime:totalTimeActive netType:params.netType emailAuthToken:nil deviceType:@(DEVICE_TYPE_PUSH) influenceParams:params.influenceParams];
117117

118118
// For email we omit additionalFieldsToAddToOnFocusPayload as we don't want to add
119-
// outcome fields which would double report the session time
119+
// outcome fields which would double report the influence time
120120
if (params.emailUserId)
121121
requests[@"email"] = [OSRequestOnFocus withUserId:params.emailUserId appId:params.appId activeTime:totalTimeActive netType:params.netType emailAuthToken:params.emailAuthToken deviceType:@(DEVICE_TYPE_EMAIL)];
122122

iOS_SDK/OneSignalSDK/Source/OSBaseFocusTimeProcessor.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727

2828
#import "OneSignal.h"
29-
#import "OSSessionResult.h"
29+
#import "OSInfluence.h"
3030
#import "OSBaseFocusTimeProcessor.h"
3131
#import "OneSignalUserDefaults.h"
3232
#import "OneSignalCommonDefines.h"

iOS_SDK/OneSignalSDK/Source/OSUniqueOutcomeNotification.h renamed to iOS_SDK/OneSignalSDK/Source/OSCachedUniqueOutcome.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
THE SOFTWARE.
2626
*/
2727

28-
@interface OSUniqueOutcomeNotification : NSObject
28+
#import "OneSignal.h"
29+
30+
@interface OSCachedUniqueOutcome : NSObject
2931

3032
@property (nonatomic, readonly) NSString *name;
31-
@property (nonatomic, readonly) NSString *notificationId;
33+
@property (nonatomic, readonly) NSString *uniqueId;
3234
@property (nonatomic, readonly) NSNumber *timestamp; // seconds
35+
@property (nonatomic, readonly) OSInfluenceChannel channel;
3336

34-
- (id)initWithParamsNotificationId:(NSString *)name notificationId:(NSString *)notificationId timestamp:(NSNumber *)timestamp;
37+
- (id)initWithParamsName:(NSString *)name uniqueId:(NSString *)uniqueId channel:(OSInfluenceChannel)channel;
38+
- (id)initWithParamsName:(NSString *)name uniqueId:(NSString *)uniqueId timestamp:(NSNumber *)timestamp channel:(OSInfluenceChannel)channel;
3539

3640
@end
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
Modified MIT License
3+
4+
Copyright 2019 OneSignal
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
1. The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
2. All copies of substantial portions of the Software may only be used in connection
17+
with services provided by OneSignal.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
*/
27+
28+
#import <Foundation/Foundation.h>
29+
#import "OSCachedUniqueOutcome.h"
30+
#import "OneSignalCommonDefines.h"
31+
32+
@implementation OSCachedUniqueOutcome
33+
34+
- (id)initWithParamsName:(NSString *)name uniqueId:(NSString *)uniqueId channel:(OSInfluenceChannel)channel {
35+
self = [super init];
36+
if (self) {
37+
_name = name;
38+
_uniqueId = uniqueId;
39+
_channel = channel;
40+
_timestamp = @0;
41+
}
42+
return self;
43+
}
44+
45+
- (id)initWithParamsName:(NSString *)name uniqueId:(NSString *)uniqueId timestamp:(NSNumber *)timestamp channel:(OSInfluenceChannel)channel {
46+
self = [super init];
47+
if (self) {
48+
_name = name;
49+
_uniqueId = uniqueId;
50+
_channel = channel;
51+
_timestamp = timestamp;
52+
}
53+
return self;
54+
}
55+
56+
- (void)encodeWithCoder:(NSCoder *)encoder {
57+
[encoder encodeObject:_name forKey:@"name"];
58+
[encoder encodeObject:_uniqueId forKey:@"uniqueId"];
59+
[encoder encodeInteger:[_timestamp integerValue] forKey:@"timestamp"];
60+
[encoder encodeObject:OS_INFLUENCE_CHANNEL_TO_STRING(_channel) forKey:@"channel"];
61+
}
62+
63+
- (id)initWithCoder:(NSCoder *)decoder {
64+
if (self = [super init]) {
65+
_name = [decoder decodeObjectForKey:@"name"];
66+
id identifier = [decoder decodeObjectForKey:@"notificationId"];
67+
if (identifier)
68+
_uniqueId = identifier;
69+
else
70+
_uniqueId = [decoder decodeObjectForKey:@"uniqueId"];
71+
_timestamp = [NSNumber numberWithLong:[decoder decodeIntegerForKey:@"timestamp"]];
72+
id channel = [decoder decodeObjectForKey:@"channel"];
73+
if (channel)
74+
_channel = OS_INFLUENCE_CHANNEL_FROM_STRING(channel);
75+
else
76+
_channel = NOTIFICATION;
77+
}
78+
return self;
79+
}
80+
81+
- (NSString *)description {
82+
return [NSString stringWithFormat:@"Name: %@ Unique Id: %@ Timestamp: %@ Channel: %@", _name, _uniqueId, _timestamp, OS_INFLUENCE_CHANNEL_TO_STRING(_channel)];
83+
}
84+
85+
- (BOOL)isEqual:(OSCachedUniqueOutcome *)other {
86+
NSString *key = [NSString stringWithFormat:@"%@_%@_%@", _name, _uniqueId, OS_INFLUENCE_CHANNEL_TO_STRING(_channel)];
87+
NSString *otherKey = [NSString stringWithFormat:@"%@_%@_%@", other.name, other.uniqueId, OS_INFLUENCE_CHANNEL_TO_STRING(other.channel)];
88+
return [key isEqualToString:otherKey];
89+
}
90+
91+
- (NSUInteger)hash {
92+
NSUInteger result = [_name hash];
93+
result = 31 * result + [_uniqueId hash];
94+
result = 31 * result + [OS_INFLUENCE_CHANNEL_TO_STRING(_channel) hash];
95+
return result;
96+
}
97+
98+
@end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
Modified MIT License
3+
4+
Copyright 2020 OneSignal
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
1. The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
2. All copies of substantial portions of the Software may only be used in connection
17+
with services provided by OneSignal.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
*/
27+
28+
#import "OneSignal.h"
29+
#import "OSInfluenceDataRepository.h"
30+
31+
#ifndef OSChannelTracker_h
32+
#define OSChannelTracker_h
33+
34+
@interface OSChannelTracker : NSObject
35+
36+
@property (nonatomic, readwrite) Session influenceType;
37+
@property (strong, nonatomic, readwrite, nullable) NSString *directId;
38+
@property (strong, nonatomic, readwrite, nullable) NSArray *indirectIds;
39+
@property (strong, nonatomic, readonly, nonnull) OSInfluenceDataRepository *dataRepository;
40+
41+
- (id _Nonnull)initWithRepository:(OSInfluenceDataRepository * _Nonnull)dataRepository;
42+
43+
- (NSString * _Nonnull)idTag;
44+
45+
- (void)initInfluencedTypeFromCache;
46+
- (void)cacheState;
47+
- (void)resetAndInitInfluence;
48+
49+
- (NSArray * _Nonnull)lastReceivedIds;
50+
- (void)saveLastId:(NSString *_Nullable)lastId;
51+
52+
- (OSInfluence *_Nonnull)currentSessionInfluence;
53+
54+
@end
55+
56+
#endif /* OSChannelTracker_h */

0 commit comments

Comments
 (0)