Skip to content

Commit 3d6bc72

Browse files
authored
Merge branch 'feature/itbl_track_anon_user' into evan/MOB-9560-identity-resolution
2 parents 9df309c + b82b8e6 commit 3d6bc72

8 files changed

+520
-25
lines changed

swift-sdk.xcodeproj/project.pbxproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
00B6FACE210E88ED007535CF /* prod-1.mobileprovision in Resources */ = {isa = PBXBuildFile; fileRef = 00B6FACD210E874D007535CF /* prod-1.mobileprovision */; };
1212
00B6FAD1210E8D90007535CF /* dev-1.mobileprovision in Resources */ = {isa = PBXBuildFile; fileRef = 00B6FAD0210E8D90007535CF /* dev-1.mobileprovision */; };
1313
00CB31B621096129004ACDEC /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00CB31B4210960C4004ACDEC /* TestUtils.swift */; };
14-
181063DF2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */; };
14+
181063DB2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DA2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift */; };
15+
181063DD2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DC2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift */; };
16+
181063DF2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */; };
1517
182A2A152C661C9A002FF058 /* DataTypeComparatorSearchQueryCriteria.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182A2A142C661C9A002FF058 /* DataTypeComparatorSearchQueryCriteria.swift */; };
1618
1881A21B2C7602F80020C64D /* ComparatorDataTypeWithArrayInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1881A21A2C7602F80020C64D /* ComparatorDataTypeWithArrayInput.swift */; };
1719
18A3520A2C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18A352092C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift */; };
@@ -566,7 +568,9 @@
566568
00B6FACD210E874D007535CF /* prod-1.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = "prod-1.mobileprovision"; sourceTree = "<group>"; };
567569
00B6FAD0210E8D90007535CF /* dev-1.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dev-1.mobileprovision"; sourceTree = "<group>"; };
568570
00CB31B4210960C4004ACDEC /* TestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
569-
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidateStoredEventCheckUnknownToKnownUserTest.swift; sourceTree = "<group>"; };
571+
181063DA2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomEventUserUpdateTestCaseTests.swift; sourceTree = "<group>"; };
572+
181063DC2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidateCustomEventUserUpdateAPITest.swift; sourceTree = "<group>"; };
573+
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidateStoredEventCheckUnknownToKnownUserTest.swift; sourceTree = "<group>"; };
570574
182A2A142C661C9A002FF058 /* DataTypeComparatorSearchQueryCriteria.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTypeComparatorSearchQueryCriteria.swift; sourceTree = "<group>"; };
571575
1881A21A2C7602F80020C64D /* ComparatorDataTypeWithArrayInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparatorDataTypeWithArrayInput.swift; sourceTree = "<group>"; };
572576
18A352092C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NestedFieldSupportForArrayData.swift; sourceTree = "<group>"; };
@@ -1691,7 +1695,9 @@
16911695
18E23ADF2C6CDE97002B2D92 /* CombinationLogicEventTypeCriteria.swift */,
16921696
18A352092C7DC51C007FED53 /* NestedFieldSupportForArrayData.swift */,
16931697
18A3520B2C85BAF0007FED53 /* IsOneOfInNotOneOfCriteareaTest.swift */,
1694-
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */,
1698+
181063DA2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift */,
1699+
181063DC2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift */,
1700+
181063DE2C9D51000078E0ED /* ValidateStoredEventCheckUnknownToKnownUserTest.swift */,
16951701
);
16961702
name = "anonymous-tracking-tests";
16971703
sourceTree = "<group>";
@@ -2330,6 +2336,7 @@
23302336
55AEA95925F05B7D00B38CED /* InAppMessageProcessorTests.swift in Sources */,
23312337
ACC362B824D17005002C67BA /* IterableRequestTests.swift in Sources */,
23322338
AC2C668720D3435700D46CC9 /* ActionRunnerTests.swift in Sources */,
2339+
181063DB2C9841460078E0ED /* CustomEventUserUpdateTestCaseTests.swift in Sources */,
23332340
00CB31B621096129004ACDEC /* TestUtils.swift in Sources */,
23342341
AC89661E2124FBCE0051A6CD /* AutoRegistrationTests.swift in Sources */,
23352342
9FF05EAF2AFEA5FA005311F7 /* MockAuthManager.swift in Sources */,
@@ -2395,6 +2402,7 @@
23952402
55B5498423973B5C00243E87 /* InboxSessionManagerTests.swift in Sources */,
23962403
ACB37AB0240268A60093A8EA /* SampleInboxViewDelegateImplementations.swift in Sources */,
23972404
5588DF7928C04463000697D7 /* MockNotificationResponse.swift in Sources */,
2405+
181063DD2C994FA40078E0ED /* ValidateCustomEventUserUpdateAPITest.swift in Sources */,
23982406
AC3A2FF0262EDD4C00425435 /* InAppPriorityTests.swift in Sources */,
23992407
ACD6116E21080564003E7F6B /* IterableAPITests.swift in Sources */,
24002408
5588DF8928C044BE000697D7 /* MockCustomActionDelegate.swift in Sources */,

swift-sdk/Internal/AnonymousUserManager+Functions.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,7 @@ struct CriteriaCompletionChecker {
389389
if let valueFromObj = getFieldValue(data: eventData, field: field), let comparatorType = query[JsonKey.CriteriaItem.comparatorType] as? String {
390390
return evaluateComparison(comparatorType: comparatorType, matchObj: valueFromObj, valueToCompare: query[JsonKey.CriteriaItem.value] ?? query[JsonKey.CriteriaItem.values])
391391
}
392-
}
393-
394-
395-
if doesKeyExist {
392+
} else if doesKeyExist {
396393
if let comparatorType = query[JsonKey.CriteriaItem.comparatorType] as? String, (evaluateComparison(comparatorType: comparatorType, matchObj: eventData[field] ?? "", valueToCompare: query[JsonKey.CriteriaItem.value] ?? query[JsonKey.CriteriaItem.values])) {
397394
return true
398395
}
@@ -402,14 +399,27 @@ struct CriteriaCompletionChecker {
402399
return matchResult
403400
}
404401

402+
405403
func getFieldValue(data: Any, field: String) -> Any? {
406-
let fields = field.split(separator: ".").map { String($0) }
407-
return fields.reduce(data) { (value, currentField) -> Any? in
408-
if let dictionary = value as? [String: Any], let fieldValue = dictionary[currentField] {
409-
return fieldValue
404+
var fields = field.split(separator: ".").map(String.init)
405+
if let dictionary = data as? [String: Any] ,let dataType = dictionary[JsonKey.eventType] as? String, dataType == EventType.customEvent, let firstField = fields.first, let eventName = dictionary[JsonKey.eventName] as? String, firstField == eventName {
406+
fields.removeFirst()
407+
}
408+
var currentValue: Any? = data
409+
for (index, currentField) in fields.enumerated() {
410+
if index == fields.count - 1 {
411+
if let currentDict = currentValue as? [String: Any] {
412+
return currentDict[currentField]
413+
}
414+
} else {
415+
if let currentDict = currentValue as? [String: Any], let nextValue = currentDict[currentField] {
416+
currentValue = nextValue
417+
} else {
418+
return nil
419+
}
410420
}
411-
return nil
412421
}
422+
return nil
413423
}
414424

415425

tests/unit-tests/AnonymousUserComplexCriteriaMatchTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
3838
"comparatorType": "Equals",
3939
"dataType": "customEvent",
4040
"id": 23,
41-
"value": "button.clicked"
41+
"value": "button-clicked"
4242
},
4343
{
4444
"field": "button-clicked.animal",
@@ -483,7 +483,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
483483

484484
func testCompareDataWithCriteria1Success() {
485485
let eventItems: [[AnyHashable: Any]] = [
486-
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button.clicked", "dataFields": ["button-clicked.animal": "giraffe"]
486+
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["animal": "giraffe"]
487487
], [
488488
"items": [["id": "12", "name": "keyboard", "price": 130, "quantity": 110]],
489489
"createdAt": 1699246745093,
@@ -496,7 +496,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
496496

497497
func testCompareDataWithCriteria1Failure() {
498498
let eventItems: [[AnyHashable: Any]] = [
499-
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button.clicked", "dataFields": ["button-clicked.animal": "giraffe22"]
499+
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["animal": "giraffe22"]
500500
], [
501501
"items": [["id": "12", "name": "keyboard", "price": 130, "quantity": 110]],
502502
"createdAt": 1699246745093,
@@ -508,7 +508,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
508508

509509
func testCompareDataWithCriteria2Success() {
510510
let eventItems: [[AnyHashable: Any]] = [
511-
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
511+
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "welcome page"]
512512
], ["dataType": "user", "createdAt": 1699246745093, "phone_number": "999999", "country": "USA", "dataFields": ["preferred_car_models": "Subaru"]
513513
]]
514514
let expectedCriteriaId = "51"
@@ -518,7 +518,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
518518

519519
func testCompareDataWithCriteria2Failure() {
520520
let eventItems: [[AnyHashable: Any]] = [
521-
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
521+
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "welcome page"]
522522
], ["dataType": "user", "createdAt": 1699246745093, "phone_number": "999999", "country": "USA", "dataFields": ["preferred_car_models": "Mazda"]
523523
]]
524524
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataForCriteria2)!, anonymousEvents: eventItems).getMatchedCriteria()
@@ -543,7 +543,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
543543
], [
544544
"dataType": "user", "createdAt": 1699246745093, "dataFields": [ "phone_number": "999999", "country": "USA", "preferred_car_models": "Subaru"]
545545
], [
546-
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
546+
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "welcome page"]
547547
], ]
548548

549549
let expectedCriteriaId = "50"
@@ -555,7 +555,7 @@ class AnonymousUserComplexCriteriaMatchTests: XCTestCase {
555555
func testCompareDataWithCriteria3Failure() {
556556
let eventItems: [[AnyHashable: Any]] = [
557557
[
558-
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked2", "dataFields": ["button-clicked.lastPageViewed": "welcome page"]
558+
"dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked2", "dataFields": ["lastPageViewed": "welcome page"]
559559
], [
560560
"items": [["id": "12", "name": "keyboard", "price": 90, "quantity": 60]],
561561
"createdAt": 1699246745093,

tests/unit-tests/AnonymousUserCriteriaIsSetTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ class AnonymousUserCriteriaIsSetTests: XCTestCase {
296296

297297

298298
func testCompareDataIsSetCustomEventSuccess() {
299-
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"button-clicked", "dataFields": ["button-clicked":"cc", "button-clicked.animal": "aa", "button-clicked.clickCount": "1", "total": "10"]]]
299+
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"button-clicked", "dataFields": ["button-clicked":"cc", "animal": "aa", "clickCount": "1", "total": "10"]]]
300300
let expectedCriteriaId = "1"
301301
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataCustomEvent)!, anonymousEvents: eventItems).getMatchedCriteria()
302302
XCTAssertEqual(matchedCriteriaId, expectedCriteriaId)
303303
}
304304

305305
func testCompareDataIsSetCustomEventFailure() {
306-
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"vvv", "dataFields": ["button-clicked":"", "button-clicked.animal": "", "button-clicked.clickCount": "1", "total": "10"]]]
306+
let eventItems: [[AnyHashable: Any]] = [["dataType": "customEvent", "eventName":"vvv", "dataFields": ["button-clicked":"", "animal": "", "clickCount": "1", "total": "10"]]]
307307
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataCustomEvent)!, anonymousEvents: eventItems).getMatchedCriteria()
308308
XCTAssertEqual(matchedCriteriaId, nil)
309309
}

tests/unit-tests/AnonymousUserCriteriaMatchTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class AnonymousUserCriteriaMatchTests: XCTestCase {
250250

251251
func testCompareDataWithCustomEventCriteriaSuccess() {
252252
let eventItems: [[AnyHashable: Any]] = [
253-
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["button-clicked.lastPageViewed": "signup page"]
253+
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button-clicked", "dataFields": ["lastPageViewed": "signup page"]
254254
]]
255255
let expectedCriteriaId = "48"
256256
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockData)!, anonymousEvents: eventItems).getMatchedCriteria()
@@ -259,7 +259,7 @@ class AnonymousUserCriteriaMatchTests: XCTestCase {
259259

260260
func testCompareDataWithCustomEventCriteriaFailure() {
261261
let eventItems: [[AnyHashable: Any]] = [
262-
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button", "dataFields": ["button-clicked.lastPageViewed": "signup page"]
262+
["dataType": "customEvent", "createdAt": 1699246745093, "eventName": "button", "dataFields": ["lastPageViewed": "signup page"]
263263
]]
264264
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockData)!, anonymousEvents: eventItems).getMatchedCriteria()
265265
XCTAssertEqual(matchedCriteriaId, nil)

tests/unit-tests/ComparatorDataTypeWithArrayInput.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ final class ComparatorDataTypeWithArrayInput: XCTestCase {
675675
],
676676
[
677677
"dataType": "customEvent",
678-
"button-clicked.animal": ["zirraf", "horse"]
678+
"eventName": "button-clicked",
679+
"dataFields": ["animal": ["zirraf", "horse"]]
679680
],
680681
[
681682
"dataType": "purchase",
@@ -696,7 +697,9 @@ final class ComparatorDataTypeWithArrayInput: XCTestCase {
696697
],
697698
[
698699
"dataType": "customEvent",
699-
"button-clicked.animal": ["zirraf", "horse", "giraffe"]
700+
"eventName": "button-clicked",
701+
"dataFields": ["animal": ["zirraf", "horse", "giraffe"]]
702+
700703
],
701704
[
702705
"dataType": "purchase",

0 commit comments

Comments
 (0)