Skip to content

Commit 65fde63

Browse files
fix vuid
1 parent f455e45 commit 65fde63

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

Sources/ODP/OdpEventManager.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ open class OdpEventManager {
5858
data: [:])
5959
}
6060

61-
func identifyUser(vuid: String?, userId: String?) {
62-
var identifiers = [String: String]()
63-
if let _vuid = vuid, VuidManager.isVuid(_vuid) {
64-
identifiers[Constants.ODP.keyForVuid] = _vuid
65-
}
61+
func identifyUser(vuid: String, userId: String?) {
62+
var identifiers = [Constants.ODP.keyForVuid: vuid]
6663
if let userId = userId {
6764
identifiers[Constants.ODP.keyForUserId] = userId
6865
}
@@ -72,7 +69,7 @@ open class OdpEventManager {
7269
identifiers: identifiers,
7370
data: [:])
7471
}
75-
72+
7673
func sendEvent(type: String, action: String, identifiers: [String: String], data: [String: Any?]) {
7774
let event = OdpEvent(type: type,
7875
action: action,

Sources/ODP/OdpManager.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ public class OdpManager {
9191
logger.d("ODP identify event is not dispatched (ODP not integrated).")
9292
return
9393
}
94-
94+
95+
var vuid = VuidManager.shared.vuid
96+
var fsUserId: String? = userId
9597
if VuidManager.isVuid(userId) {
9698
// overwrite if userId is vuid (when userContext is created with vuid)
97-
eventManager.identifyUser(vuid: userId, userId: nil)
98-
} else {
99-
eventManager.identifyUser(vuid: self.vuid, userId: userId)
99+
vuid = userId
100+
fsUserId = nil
100101
}
101102

103+
eventManager.identifyUser(vuid: vuid, userId: fsUserId)
102104
}
103105

104106
/// Send an event to the ODP server.

Sources/Optimizely+Decide/OptimizelyClient+Decide.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ extension OptimizelyClient {
3636
/// - Parameter attributes: A map of attribute names to current user attribute values.
3737
/// - Returns: An OptimizelyUserContext associated with this OptimizelyClient
3838
public func createUserContext(attributes: [String: Any]? = nil) -> OptimizelyUserContext? {
39-
// guard enableVuid else {
40-
// logger.e("Vuid is not enabled or invalid VUID. User context not created.")
41-
// return nil
42-
// }
39+
guard let vuid = self.vuid else {
40+
logger.e("Vuid is not enabled or invalid VUID. User context not created.")
41+
return nil
42+
}
4343
return OptimizelyUserContext(optimizely: self, userId: vuid, attributes: attributes)
4444
}
4545

Sources/Optimizely/OptimizelyClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ open class OptimizelyClient: NSObject {
118118
self.decisionService = HandlerRegistryService.shared.injectDecisionService(sdkKey: self.sdkKey)
119119
self.notificationCenter = HandlerRegistryService.shared.injectNotificationCenter(sdkKey: self.sdkKey)
120120

121-
if self.enableVuid {
121+
if vuidManager.enable {
122122
try? sendOdpEvent(type: Constants.ODP.eventType,
123123
action: "client_initialized",
124124
identifiers: [
125-
Constants.ODP.keyForVuid: self.vuid
125+
Constants.ODP.keyForVuid: vuidManager.vuid
126126
],
127127
data: [:])
128128

@@ -984,7 +984,7 @@ extension OptimizelyClient {
984984
}
985985

986986
/// the device vuid (read only)
987-
public var vuid: String {
987+
public var vuid: String? {
988988
return self.vuidManager.vuid
989989
}
990990

0 commit comments

Comments
 (0)