Skip to content

Commit 62bcf4d

Browse files
authored
feat: merge custom events into main for GA + tests (#1636)
* Add custom events feature * [nits] improve string description of OneSignalClientError Motivation: - previously it would log like this: "request failed with error: <OneSignalClientError: 0x600000cd49c0> - now it will log like this: "request failed with error: <OneSignalClientError code: 202, message: Error parsing JSON, response: (null), underlyingError: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0., NSJSONSerializationErrorIndex=0} >" * [nits] privatize internal methods * No need to be on protocol nor exposed * Create executor to handle custom events * [dev app] Add custom events examples * Add 2 buttons at the bottom of Dev App called "Track Named Event" for making a named event yourself and the other button "Track Preset Custom Events" sends a misc collection of events with different payloads * Add example custom events in Objective-C and Swift * update the endpoint used for events * Update endpoint used for custom events * Don't batch custom events * tests: add tests for custom events
1 parent 05c95b5 commit 62bcf4d

18 files changed

Lines changed: 1495 additions & 278 deletions

iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard

Lines changed: 288 additions & 246 deletions
Large diffs are not rendered by default.

iOS_SDK/OneSignalDevApp/OneSignalDevApp/SwiftTest.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,43 @@ class SwiftTest: NSObject, OSLogListener {
3939
OneSignal.Debug.addLogListener(self)
4040
OneSignal.Debug.removeLogListener(self)
4141
}
42+
43+
/**
44+
Track multiple events with different properties.
45+
Properties must pass `JSONSerialization.isValidJSONObject` to be accepted.
46+
*/
47+
@objc
48+
static func trackCustomEvents() {
49+
print("Dev App: track an event with nil properties")
50+
OneSignal.User.trackEvent(name: "null properties", properties: nil)
51+
52+
print("Dev App: track an event with empty properties")
53+
OneSignal.User.trackEvent(name: "empty properties", properties: [:])
54+
55+
let formatter = DateFormatter()
56+
formatter.dateStyle = .short
57+
58+
let mixedTypes = [
59+
"string": "somestring",
60+
"number": 5,
61+
"bool": false,
62+
"dateStr": formatter.string(from: Date())
63+
] as [String: Any]
64+
65+
let nestedDict = [
66+
"someDict": mixedTypes,
67+
"anotherDict": [
68+
"foo": "bar",
69+
"booleanVal": true,
70+
"float": Float("3.14")!
71+
]
72+
]
73+
let invalidProperties = ["date": Date()]
74+
75+
print("Dev App: track an event with a valid nested dictionary")
76+
OneSignal.User.trackEvent(name: "nested dictionary", properties: nestedDict)
77+
78+
print("Dev App: track an event with invalid dictionary types")
79+
OneSignal.User.trackEvent(name: "invalid dictionary", properties: invalidProperties)
80+
}
4281
}

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
@property (weak, nonatomic) IBOutlet UITextField *activityId;
7979

8080
@property (weak, nonatomic) IBOutlet UITextField *languageTextField;
81+
@property (weak, nonatomic) IBOutlet UITextField *customEventsTextField;
8182

8283
@end
8384

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,21 @@ - (IBAction)dontRequireConsent:(id)sender {
281281
[OneSignal setConsentRequired:false];
282282
}
283283

284+
- (IBAction)trackCustomEvents:(id)sender {
285+
NSLog(@"Dev App: tracking some preset custom events");
286+
[OneSignal.User trackEventWithName:@"simple event" properties:@{@"foobarbaz": @"foobarbaz"}];
287+
NSMutableDictionary *dict = [NSMutableDictionary new];
288+
dict[@"dict"] = @{@"abc" : @"def"};
289+
dict[@"false"] = false;
290+
dict[@"int"] = @99;
291+
[OneSignal.User trackEventWithName:@"complex event" properties:dict];
292+
[SwiftTest trackCustomEvents];
293+
}
294+
295+
- (IBAction)trackNamedCustomEvent:(id)sender {
296+
NSString *name = self.customEventsTextField.text;
297+
NSLog(@"Dev App: Tracking custom event with name: %@", name);
298+
[OneSignal.User trackEventWithName:name properties:nil];
299+
}
300+
284301
@end

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
3C6299AB2BEEA4C000649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C6299AA2BEEA4C000649187 /* PrivacyInfo.xcprivacy */; };
104104
3C64C3322F1066D700693230 /* LiveActivitiesManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C64C3312F1066D700693230 /* LiveActivitiesManagerTests.swift */; };
105105
3C67F77A2BEB2B710085A0F0 /* SwitchUserIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C67F7792BEB2B710085A0F0 /* SwitchUserIntegrationTests.swift */; };
106+
3C68EFE52D93195E00F0896B /* OSCustomEventsExecutor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C68EFE42D93195E00F0896B /* OSCustomEventsExecutor.swift */; };
107+
3C68EFE72D931BA600F0896B /* OSRequestCustomEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C68EFE62D931BA600F0896B /* OSRequestCustomEvents.swift */; };
106108
3C7021E32ECF0821001768C6 /* OneSignalFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E2400381D4FFC31008BDE70 /* OneSignalFramework.framework */; };
107109
3C7021E42ECF0821001768C6 /* OneSignalFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3E2400381D4FFC31008BDE70 /* OneSignalFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
108110
3C7021E92ECF0CF4001768C6 /* IAMIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C7021E82ECF0CF4001768C6 /* IAMIntegrationTests.swift */; };
@@ -155,6 +157,8 @@
155157
3CA8B8822BEC2FCB0010ADA1 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C7A39D42B7C18EE0082665E /* XCTest.framework */; };
156158
3CA8B8832BEC2FCB0010ADA1 /* XCTest.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3C7A39D42B7C18EE0082665E /* XCTest.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
157159
3CAA4BB72F0BAFBA00A16682 /* TriggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CAA4BB62F0BAFBA00A16682 /* TriggerTests.swift */; };
160+
3CB331682F281679000E1801 /* CustomEventsIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB331672F281679000E1801 /* CustomEventsIntegrationTests.swift */; };
161+
3CB3316A2F281692000E1801 /* OSCustomEventsExecutorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB331692F281692000E1801 /* OSCustomEventsExecutorTests.swift */; };
158162
3CB35FCB2F0FA20B000E6E0F /* OSMessagingControllerUserStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB35FCA2F0FA20B000E6E0F /* OSMessagingControllerUserStateTests.swift */; };
159163
3CBB6C262ED59CCC000FEB02 /* ConsistencyManagerTestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CBB6C252ED59CCC000FEB02 /* ConsistencyManagerTestHelpers.swift */; };
160164
3CC063942B6D6B6B002BB07F /* OneSignalCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CC063932B6D6B6B002BB07F /* OneSignalCore.m */; };
@@ -1332,6 +1336,8 @@
13321336
3C6299AA2BEEA4C000649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
13331337
3C64C3312F1066D700693230 /* LiveActivitiesManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveActivitiesManagerTests.swift; sourceTree = "<group>"; };
13341338
3C67F7792BEB2B710085A0F0 /* SwitchUserIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchUserIntegrationTests.swift; sourceTree = "<group>"; };
1339+
3C68EFE42D93195E00F0896B /* OSCustomEventsExecutor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSCustomEventsExecutor.swift; sourceTree = "<group>"; };
1340+
3C68EFE62D931BA600F0896B /* OSRequestCustomEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSRequestCustomEvents.swift; sourceTree = "<group>"; };
13351341
3C7021E72ECF0CF3001768C6 /* OneSignalInAppMessagesTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OneSignalInAppMessagesTests-Bridging-Header.h"; sourceTree = "<group>"; };
13361342
3C7021E82ECF0CF4001768C6 /* IAMIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAMIntegrationTests.swift; sourceTree = "<group>"; };
13371343
3C70221C2ECF124B001768C6 /* OneSignalInAppMessagesMocks.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OneSignalInAppMessagesMocks.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1365,6 +1371,8 @@
13651371
3C9AD6D22B228BB000BC1540 /* OSRequestUpdateProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSRequestUpdateProperties.swift; sourceTree = "<group>"; };
13661372
3CA6CE0928E4F19B00CA0585 /* OSUserRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSUserRequest.swift; sourceTree = "<group>"; };
13671373
3CAA4BB62F0BAFBA00A16682 /* TriggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerTests.swift; sourceTree = "<group>"; };
1374+
3CB331672F281679000E1801 /* CustomEventsIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomEventsIntegrationTests.swift; sourceTree = "<group>"; };
1375+
3CB331692F281692000E1801 /* OSCustomEventsExecutorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSCustomEventsExecutorTests.swift; sourceTree = "<group>"; };
13681376
3CB35FCA2F0FA20B000E6E0F /* OSMessagingControllerUserStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSMessagingControllerUserStateTests.swift; sourceTree = "<group>"; };
13691377
3CBB6C252ED59CCC000FEB02 /* ConsistencyManagerTestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsistencyManagerTestHelpers.swift; sourceTree = "<group>"; };
13701378
3CC063932B6D6B6B002BB07F /* OneSignalCore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalCore.m; sourceTree = "<group>"; };
@@ -2243,6 +2251,7 @@
22432251
isa = PBXGroup;
22442252
children = (
22452253
3C8E6E0028AC0BA10031E48A /* OSIdentityOperationExecutor.swift */,
2254+
3C68EFE42D93195E00F0896B /* OSCustomEventsExecutor.swift */,
22462255
3C8E6DFE28AB09AE0031E48A /* OSPropertyOperationExecutor.swift */,
22472256
3CE795FA28DBDCE700736BD4 /* OSSubscriptionOperationExecutor.swift */,
22482257
3C9AD6BB2B2285FB00BC1540 /* OSUserExecutor.swift */,
@@ -2265,6 +2274,7 @@
22652274
3C9AD6C62B228A9800BC1540 /* OSRequestTransferSubscription.swift */,
22662275
3C9AD6C02B22886600BC1540 /* OSRequestUpdateSubscription.swift */,
22672276
3C9AD6C42B228A7300BC1540 /* OSRequestDeleteSubscription.swift */,
2277+
3C68EFE62D931BA600F0896B /* OSRequestCustomEvents.swift */,
22682278
);
22692279
path = Requests;
22702280
sourceTree = "<group>";
@@ -2310,6 +2320,7 @@
23102320
3CF11E3E2C6D61AC002856F5 /* Executors */,
23112321
3CC063ED2B6D7FE8002BB07F /* OneSignalUserTests.swift */,
23122322
3CC890342C5BF9A7002CB4CC /* UserConcurrencyTests.swift */,
2323+
3CB331672F281679000E1801 /* CustomEventsIntegrationTests.swift */,
23132324
3C67F7792BEB2B710085A0F0 /* SwitchUserIntegrationTests.swift */,
23142325
3CDE664B2BFC2A56006DA114 /* OneSignalUserObjcTests.m */,
23152326
);
@@ -2328,6 +2339,7 @@
23282339
isa = PBXGroup;
23292340
children = (
23302341
3CF11E3C2C6D6155002856F5 /* UserExecutorTests.swift */,
2342+
3CB331692F281692000E1801 /* OSCustomEventsExecutorTests.swift */,
23312343
);
23322344
path = Executors;
23332345
sourceTree = "<group>";
@@ -4406,10 +4418,12 @@
44064418
isa = PBXSourcesBuildPhase;
44074419
buildActionMask = 2147483647;
44084420
files = (
4421+
3CB331682F281679000E1801 /* CustomEventsIntegrationTests.swift in Sources */,
44094422
3CF11E3D2C6D6155002856F5 /* UserExecutorTests.swift in Sources */,
44104423
3C67F77A2BEB2B710085A0F0 /* SwitchUserIntegrationTests.swift in Sources */,
44114424
3CC063EE2B6D7FE8002BB07F /* OneSignalUserTests.swift in Sources */,
44124425
3CC890352C5BF9A7002CB4CC /* UserConcurrencyTests.swift in Sources */,
4426+
3CB3316A2F281692000E1801 /* OSCustomEventsExecutorTests.swift in Sources */,
44134427
3CDE664C2BFC2A56006DA114 /* OneSignalUserObjcTests.m in Sources */,
44144428
);
44154429
runOnlyForDeploymentPostprocessing = 0;
@@ -4580,8 +4594,10 @@
45804594
3C277D7E2BD76E0000857606 /* OSIdentityModelRepo.swift in Sources */,
45814595
3CEE90A72BFE6ABD00B0FB5B /* OSPropertiesSupportedProperty.swift in Sources */,
45824596
3C9AD6C12B22886600BC1540 /* OSRequestUpdateSubscription.swift in Sources */,
4597+
3C68EFE72D931BA600F0896B /* OSRequestCustomEvents.swift in Sources */,
45834598
3C0EF49E28A1DBCB00E5434B /* OSUserInternalImpl.swift in Sources */,
45844599
3C8E6DFF28AB09AE0031E48A /* OSPropertyOperationExecutor.swift in Sources */,
4600+
3C68EFE52D93195E00F0896B /* OSCustomEventsExecutor.swift in Sources */,
45854601
3C9AD6CB2B228B5200BC1540 /* OSRequestIdentifyUser.swift in Sources */,
45864602
3C9AD6BC2B2285FB00BC1540 /* OSUserExecutor.swift in Sources */,
45874603
3C9AD6C32B22887700BC1540 /* OSRequestCreateUser.swift in Sources */,

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClientError.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ - (instancetype)initWithCode:(NSInteger)code message:(NSString* _Nonnull)message
4646
return self;
4747
}
4848

49+
- (NSString *)description {
50+
return [NSString stringWithFormat:@"<OneSignalClientError code: %ld, message: %@, response: %@, underlyingError: %@ >", (long)_code, _message, _response, _underlyingError];
51+
}
52+
4953
@end

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ typedef enum {ATTRIBUTED, NOT_ATTRIBUTED} FocusAttributionState;
205205
#define IDENTITY_EXECUTOR_BACKGROUND_TASK @"IDENTITY_EXECUTOR_BACKGROUND_TASK_"
206206
#define PROPERTIES_EXECUTOR_BACKGROUND_TASK @"PROPERTIES_EXECUTOR_BACKGROUND_TASK_"
207207
#define SUBSCRIPTION_EXECUTOR_BACKGROUND_TASK @"SUBSCRIPTION_EXECUTOR_BACKGROUND_TASK_"
208+
#define CUSTOM_EVENTS_EXECUTOR_BACKGROUND_TASK @"CUSTOM_EVENTS_EXECUTOR_BACKGROUND_TASK_"
208209

209210
// OneSignal constants
210211
#define OS_PUSH @"push"
@@ -339,6 +340,8 @@ typedef enum {GET, POST, HEAD, PUT, DELETE, OPTIONS, CONNECT, TRACE, PATCH} HTTP
339340
#define OS_REMOVE_SUBSCRIPTION_DELTA @"OS_REMOVE_SUBSCRIPTION_DELTA"
340341
#define OS_UPDATE_SUBSCRIPTION_DELTA @"OS_UPDATE_SUBSCRIPTION_DELTA"
341342

343+
#define OS_CUSTOM_EVENT_DELTA @"OS_CUSTOM_EVENT_DELTA"
344+
342345
// Operation Repo
343346
#define OS_OPERATION_REPO_DELTA_QUEUE_KEY @"OS_OPERATION_REPO_DELTA_QUEUE_KEY"
344347

@@ -361,6 +364,10 @@ typedef enum {GET, POST, HEAD, PUT, DELETE, OPTIONS, CONNECT, TRACE, PATCH} HTTP
361364
#define OS_SUBSCRIPTION_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY @"OS_SUBSCRIPTION_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY"
362365
#define OS_SUBSCRIPTION_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY @"OS_SUBSCRIPTION_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY"
363366

367+
// Custom Events Executor
368+
#define OS_CUSTOM_EVENTS_EXECUTOR_DELTA_QUEUE_KEY @"OS_CUSTOM_EVENTS_EXECUTOR_DELTA_QUEUE_KEY"
369+
#define OS_CUSTOM_EVENTS_EXECUTOR_REQUEST_QUEUE_KEY @"OS_CUSTOM_EVENTS_EXECUTOR_REQUEST_QUEUE_KEY"
370+
364371
// Live Activies Executor
365372
#define OS_LIVE_ACTIVITIES_EXECUTOR_UPDATE_TOKENS_KEY @"OS_LIVE_ACTIVITIES_EXECUTOR_UPDATE_TOKENS_KEY"
366373
#define OS_LIVE_ACTIVITIES_EXECUTOR_START_TOKENS_KEY @"OS_LIVE_ACTIVITIES_EXECUTOR_START_TOKENS_KEY"

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationExecutor.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ import OneSignalCore
3232
*/
3333
public protocol OSOperationExecutor {
3434
var supportedDeltas: [String] { get }
35-
var deltaQueue: [OSDelta] { get }
3635

3736
func enqueueDelta(_ delta: OSDelta)
3837
func cacheDeltaQueue()
3938
func processDeltaQueue(inBackground: Bool)
40-
41-
func processRequestQueue(inBackground: Bool)
4239
}

0 commit comments

Comments
 (0)