File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed
Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,10 @@ extension Keychain {
66 get { self [ WooConstants . keychainAppleIDKey] }
77 set { self [ WooConstants . keychainAppleIDKey] = newValue }
88 }
9+
10+ /// The anonymous ID used to identify a logged-out user potentially across installs in analytics and A/B experiments.
11+ var anonymousID : String ? {
12+ get { self [ WooConstants . anonymousIDKey] }
13+ set { self [ WooConstants . anonymousIDKey] = newValue }
14+ }
915}
Original file line number Diff line number Diff line change @@ -119,14 +119,16 @@ final class SessionManager: SessionManagerProtocol {
119119 /// Anonymous UserID.
120120 ///
121121 var anonymousUserID : String ? {
122- get {
123- if let anonID = defaults [ . defaultAnonymousID] as? String , !anonID. isEmpty {
124- return anonID
125- } else {
126- let newValue = UUID ( ) . uuidString
127- defaults [ . defaultAnonymousID] = newValue
128- return newValue
129- }
122+ if let anonID = defaults [ . defaultAnonymousID] as? String , !anonID. isEmpty {
123+ return anonID
124+ } else if let keychainAnonID = keychain. anonymousID, !keychainAnonID. isEmpty {
125+ defaults [ . defaultAnonymousID] = keychainAnonID
126+ return keychainAnonID
127+ } else {
128+ let newValue = UUID ( ) . uuidString
129+ defaults [ . defaultAnonymousID] = newValue
130+ keychain. anonymousID = newValue
131+ return newValue
130132 }
131133 }
132134
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ enum WooConstants {
2121 ///
2222 static let keychainAppleIDKey = " AppleID "
2323
24+ /// Keychain Access's Key for anonymous ID
25+ ///
26+ static let anonymousIDKey = " anonymousID "
27+
2428 /// Push Notifications ApplicationID
2529 ///
2630#if DEBUG
You can’t perform that action at this time.
0 commit comments