Skip to content

Commit

Permalink
Merge branch 'feature/itbl_track_anon_user' into aut_demo
Browse files Browse the repository at this point in the history
  • Loading branch information
evantk91 authored May 26, 2024
2 parents 8ef9b22 + d86a75b commit 8892e1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
24 changes: 15 additions & 9 deletions swift-sdk/Internal/InternalIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
}

func setEmail(_ email: String?, authToken: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
anonymousUserMerge.mergeUserUsingEmail(destinationUserId: _userId ?? "", destinationEmail: email ?? "", sourceEmail: _email ?? "")

if config.enableAnonTracking {
anonymousUserMerge.mergeUserUsingEmail(destinationUserId: _userId ?? "", destinationEmail: email ?? "", sourceEmail: _email ?? "")
}
ITBInfo()

if email == nil {
if email == nil && config.enableAnonTracking {
anonymousUserManager.logout()
}

Expand All @@ -155,10 +158,13 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
}

func setUserId(_ userId: String?, authToken: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
anonymousUserMerge.mergeUserUsingUserId(destinationUserId: userId ?? "", sourceUserId: _userId ?? "", destinationEmail: _email ?? "")

if config.enableAnonTracking {
anonymousUserMerge.mergeUserUsingUserId(destinationUserId: userId ?? "", sourceUserId: _userId ?? "", destinationEmail: _email ?? "")
}
ITBInfo()

if userId == nil {
if userId == nil && config.enableAnonTracking {
anonymousUserManager.logout()
}

Expand Down Expand Up @@ -206,7 +212,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
return
}

if !isEitherUserIdOrEmailSet() {
if !isEitherUserIdOrEmailSet() && config.enableAnonTracking {
anonymousUserManager.trackAnonTokenRegistration(token: token.hexString())
}

Expand Down Expand Up @@ -264,7 +270,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
mergeNestedObjects: Bool,
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() {
if !isEitherUserIdOrEmailSet() && config.enableAnonTracking {
anonymousUserManager.trackAnonUpdateUser(dataFields)
}
return requestHandler.updateUser(dataFields, mergeNestedObjects: mergeNestedObjects, onSuccess: onSuccess, onFailure: onFailure)
Expand Down Expand Up @@ -292,7 +298,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
func updateCart(items: [CommerceItem],
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() {
if !isEitherUserIdOrEmailSet() && config.enableAnonTracking {
anonymousUserManager.trackAnonUpdateCart(items: items)
}
return requestHandler.updateCart(items: items, onSuccess: onSuccess, onFailure: onFailure)
Expand All @@ -315,7 +321,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
templateId: NSNumber? = nil,
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() {
if !isEitherUserIdOrEmailSet() && config.enableAnonTracking {
anonymousUserManager.trackAnonPurchaseEvent(total: total, items: items, dataFields: dataFields)
}
return requestHandler.trackPurchase(total,
Expand Down Expand Up @@ -387,7 +393,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
dataFields: [AnyHashable: Any]? = nil,
onSuccess: OnSuccessHandler? = nil,
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
if !isEitherUserIdOrEmailSet() {
if !isEitherUserIdOrEmailSet() && config.enableAnonTracking {
anonymousUserManager.trackAnonEvent(name: eventName, dataFields: dataFields)
}
return requestHandler.track(event: eventName, dataFields: dataFields, onSuccess: onSuccess, onFailure: onFailure)
Expand Down
16 changes: 9 additions & 7 deletions swift-sdk/IterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ import UIKit
callback?(false)
}

if let _implementation = implementation {
if _implementation.isEitherUserIdOrEmailSet() {
_implementation.anonymousUserManager.syncNonSyncedEvents()
} else {
// call this to fetch anon criteria from API and save it into userdefaults
_implementation.anonymousUserManager.getAnonCriteria()
_implementation.anonymousUserManager.updateAnonSession()
if(config.enableAnonTracking) {
if let _implementation = implementation {
if _implementation.isEitherUserIdOrEmailSet() {
_implementation.anonymousUserManager.syncNonSyncedEvents()
} else {
// call this to fetch anon criteria from API and save it into userdefaults
_implementation.anonymousUserManager.getAnonCriteria()
_implementation.anonymousUserManager.updateAnonSession()
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions swift-sdk/IterableConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ public class IterableConfig: NSObject {

/// Sets data region which determines data center and endpoints used by the SDK
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 = false
}

0 comments on commit 8892e1d

Please sign in to comment.