Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-10093] final cleanup #857

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions swift-sdk/Internal/InternalIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
}
let merge = identityResolution?.mergeOnAnonymousToKnown ?? config.identityResolution.mergeOnAnonymousToKnown
let replay = identityResolution?.replayOnVisitorToKnown ?? config.identityResolution.replayOnVisitorToKnown
if config.enableAnonTracking, let email = email {
if config.enableAnonActivation, let email = email {
self?.attemptAndProcessMerge(
merge: merge ?? true,
replay: replay ?? true,
Expand Down Expand Up @@ -192,7 +192,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
guard let config = self?.config else {
return
}
if config.enableAnonTracking {
if config.enableAnonActivation {
if let userId = userId, userId != (self?.localStorage.userIdAnnon ?? "") {
let merge = identityResolution?.mergeOnAnonymousToKnown ?? config.identityResolution.mergeOnAnonymousToKnown
let replay = identityResolution?.replayOnVisitorToKnown ?? config.identityResolution.replayOnVisitorToKnown
Expand Down Expand Up @@ -242,7 +242,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
self.localStorage.anonymousUserUpdate = nil
self.localStorage.userIdAnnon = nil

if isVisitorUsageTracked && config.enableAnonTracking {
if isVisitorUsageTracked && config.enableAnonActivation {
ITBInfo("CONSENT GIVEN and ANON TRACKING ENABLED - Criteria fetched")
self.anonymousUserManager.getAnonCriteria()
self.anonymousUserManager.updateAnonSession()
Expand All @@ -268,7 +268,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
}

if !isEitherUserIdOrEmailSet() && localStorage.userIdAnnon == nil {
if config.enableAnonTracking {
if config.enableAnonActivation {
anonymousUserManager.trackAnonTokenRegistration(token: token.hexString())
}
onFailure?("Iterable SDK must be initialized with an API key and user email/userId before calling SDK methods", nil)
Expand Down Expand Up @@ -330,7 +330,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() && localStorage.userIdAnnon == nil {
if config.enableAnonTracking {
if config.enableAnonActivation {
ITBInfo("AUT ENABLED - anon update user")
anonymousUserManager.trackAnonUpdateUser(dataFields)
}
Expand Down Expand Up @@ -362,7 +362,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() && localStorage.userIdAnnon == nil {
if config.enableAnonTracking {
if config.enableAnonActivation {
ITBInfo("AUT ENABLED - anon update cart")
anonymousUserManager.trackAnonUpdateCart(items: items)
}
Expand Down Expand Up @@ -395,7 +395,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() {
if config.enableAnonTracking {
if config.enableAnonActivation {
ITBInfo("AUT ENABLED - anon track purchase")
anonymousUserManager.trackAnonPurchaseEvent(total: total, items: items, dataFields: dataFields)
}
Expand Down Expand Up @@ -469,7 +469,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() && localStorage.userIdAnnon == nil {
if config.enableAnonTracking {
if config.enableAnonActivation {
ITBInfo("AUT ENABLED - anon track custom event")
anonymousUserManager.trackAnonEvent(name: eventName, dataFields: dataFields)
}
Expand Down
2 changes: 1 addition & 1 deletion swift-sdk/IterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ import UIKit
callback?(false)
}

if let implementation, config.enableAnonTracking, !implementation.isSDKInitialized(), implementation.getVisitorUsageTracked() {
if let implementation, config.enableAnonActivation, !implementation.isSDKInitialized(), implementation.getVisitorUsageTracked() {
ITBInfo("AUT ENABLED AND CONSENT GIVEN - Criteria fetched")
implementation.anonymousUserManager.getAnonCriteria()
implementation.anonymousUserManager.updateAnonSession()
Expand Down
2 changes: 1 addition & 1 deletion swift-sdk/IterableConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class IterableConfig: NSObject {
public var dataRegion: String = IterableDataRegion.US

/// When set to `true`, IterableSDK will track all events when users are not logged into the application.
public var enableAnonTracking = true
public var enableAnonActivation = true
/// Allows for fetching embedded messages.
public var enableEmbeddedMessaging = false

Expand Down
88 changes: 64 additions & 24 deletions tests/unit-tests/DataTypeComparatorSearchQueryCriteria.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataEqualSuccess() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 19.99, "eventTimeStamp": 3,
"likes_boba": true,
"country":"Chaina"]]]
"dataFields":[
"savings": 19.99,
"eventTimeStamp": 3,
"likes_boba": true,
"country":"Chaina"]
]]

let expectedCriteriaId = "285"

Expand All @@ -98,9 +101,12 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
//let eventItems: [[AnyHashable: Any]] = [["dataType":"user","savings": 10.1]]

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 10.99, "eventTimeStamp": 30,
"likes_boba": false,
"country":"Taiwan"]]]
"dataFields":[
"savings": 10.99,
"eventTimeStamp": 30,
"likes_boba": false,
"country":"Taiwan"]
]]

let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
Expand Down Expand Up @@ -164,8 +170,10 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataDoesNotEqualSuccess() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 11.2, "eventTimeStamp": 30,
"likes_boba": false]
"dataFields":[
"savings": 11.2,
"eventTimeStamp": 30,
"likes_boba": false]
]]
let expectedCriteriaId = "285"

Expand All @@ -176,8 +184,11 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataDoesNotEqualFailed() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 19.99, "eventTimeStamp": 30,
"likes_boba": true]]]
"dataFields":[
"savings": 19.99,
"eventTimeStamp": 30,
"likes_boba": true]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataDoesNotEquals)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}
Expand Down Expand Up @@ -271,7 +282,9 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataLessThanSuccess() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 10, "eventTimeStamp": 14]
"dataFields":[
"savings": 10,
"eventTimeStamp": 14]
]]
let expectedCriteriaId = "289"

Expand All @@ -282,15 +295,21 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataLessThanFailed() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 18, "eventTimeStamp": 18]]]
"dataFields":[
"savings": 18,
"eventTimeStamp": 18]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataLessThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}

func testCompareDataLessThanOrEqualSuccess() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 17, "eventTimeStamp": 14]]]
"dataFields":[
"savings": 17,
"eventTimeStamp": 14]
]]
let expectedCriteriaId = "290"

let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataLessThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
Expand All @@ -300,7 +319,10 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataLessThanOrEqualFailed() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 18, "eventTimeStamp": 12]]]
"dataFields":[
"savings": 18,
"eventTimeStamp": 12]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataLessThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}
Expand Down Expand Up @@ -394,7 +416,10 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataGreaterThanSuccess() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 56, "eventTimeStamp": 51]]]
"dataFields":[
"savings": 56,
"eventTimeStamp": 51]
]]
let expectedCriteriaId = "290"

let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataGreaterThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
Expand All @@ -404,23 +429,32 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {
func testCompareDataGreaterThanFailed() {

let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 5, "eventTimeStamp": 3]]]
"dataFields":[
"savings": 5,
"eventTimeStamp": 3]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataGreaterThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}

func testCompareDataGreaterThanOrEqualSuccess() {

let eventItems: [[AnyHashable: Any]] = [["dataType": "user",
"dataFields":["savings": 20, "eventTimeStamp": 30]]]
"dataFields":[
"savings": 20,
"eventTimeStamp": 30]
]]
let expectedCriteriaId = "291"
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataGreaterThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, expectedCriteriaId)
}

func testCompareDataGreaterThanOrEqualFailed() {
let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 18, "eventTimeStamp":16]]]
"dataFields":[
"savings": 18,
"eventTimeStamp":16]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataGreaterThanOrEqual)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}
Expand Down Expand Up @@ -489,19 +523,25 @@ final class DataTypeComparatorSearchQueryCriteria: XCTestCase {

func testCompareDataIsSetySuccess() {
let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": 10, "eventTimeStamp":20,
"saved_cars":"10",
"country": "Taiwan"]]]
"dataFields":[
"savings": 10,
"eventTimeStamp":20,
"saved_cars":"10",
"country": "Taiwan"]
]]
let expectedCriteriaId = "285"
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataIsSet)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, expectedCriteriaId)
}

func testCompareDataIsSetFailure() {
let eventItems: [[AnyHashable: Any]] = [["dataType":"user",
"dataFields":["savings": "", "eventTimeStamp":"",
"saved_cars":"",
"country": ""]]]
"dataFields":[
"savings": "",
"eventTimeStamp":"",
"saved_cars":"",
"country": ""]
]]
let matchedCriteriaId = CriteriaCompletionChecker(anonymousCriteria: data(from: mockDataIsSet)!, anonymousEvents: eventItems).getMatchedCriteria()
XCTAssertEqual(matchedCriteriaId, nil)
}
Expand Down
Loading
Loading