diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b1f3a290..6dd35ea82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The changelog for `SuperwallKit`. Also see the [releases](https://github.com/superwall-me/Superwall-iOS/releases) on GitHub. +## 3.2.1 + +### Fixes + +- Fixes `user_attributes` being fired on every app launch when it wasn't necessary. + ## 3.2.0 ### Enhancements diff --git a/Sources/SuperwallKit/Identity/IdentityManager.swift b/Sources/SuperwallKit/Identity/IdentityManager.swift index a282bc34a..ff5ef5587 100644 --- a/Sources/SuperwallKit/Identity/IdentityManager.swift +++ b/Sources/SuperwallKit/Identity/IdentityManager.swift @@ -109,9 +109,29 @@ class IdentityManager { self.storage = storage self.configManager = configManager self._appUserId = storage.get(AppUserId.self) - self._aliasId = storage.get(AliasId.self) ?? IdentityLogic.generateAlias() - self._seed = storage.get(Seed.self) ?? IdentityLogic.generateSeed() + + var extraAttributes: [String: Any] = [:] + + if let aliasId = storage.get(AliasId.self) { + self._aliasId = aliasId + } else { + self._aliasId = IdentityLogic.generateAlias() + storage.save(_aliasId, forType: AliasId.self) + extraAttributes["aliasId"] = self._aliasId + } + + if let seed = storage.get(Seed.self) { + self._seed = seed + } else { + self._seed = IdentityLogic.generateSeed() + storage.save(_seed, forType: Seed.self) + extraAttributes["seed"] = self._seed + } self._userAttributes = storage.get(UserAttributes.self) ?? [:] + + if !extraAttributes.isEmpty { + mergeUserAttributes(extraAttributes, shouldTrackMerge: false) + } } /// Checks for static config upgrade before setting identity. @@ -127,7 +147,7 @@ class IdentityManager { ) { try? await configManager.getAssignments() } - saveIds() + group.leave() didSetIdentity() @@ -219,6 +239,7 @@ class IdentityManager { storage.save(appUserId, forType: AppUserId.self) } + // Save incase these have also changed. storage.save(_aliasId, forType: AliasId.self) storage.save(_seed, forType: Seed.self) @@ -269,26 +290,39 @@ extension IdentityManager { // MARK: - User Attributes extension IdentityManager { /// Merges the attributes on an async queue - func mergeUserAttributes(_ newUserAttributes: [String: Any?]) { + func mergeUserAttributes( + _ newUserAttributes: [String: Any?], + shouldTrackMerge: Bool = true + ) { queue.async { [weak self] in - self?._mergeUserAttributes(newUserAttributes) + self?._mergeUserAttributes( + newUserAttributes, + shouldTrackMerge: shouldTrackMerge + ) } } /// Merges the provided user attributes with existing attributes then saves them. - private func _mergeUserAttributes(_ newUserAttributes: [String: Any?]) { + /// + /// - Parameter shouldTrackMerge: A boolean indicated whether the merge should be tracked in analytics. + private func _mergeUserAttributes( + _ newUserAttributes: [String: Any?], + shouldTrackMerge: Bool = true + ) { let mergedAttributes = IdentityLogic.mergeAttributes( newUserAttributes, with: _userAttributes, appInstalledAtString: deviceHelper.appInstalledAtString ) - Task { - let trackableEvent = InternalSuperwallEvent.Attributes( - appInstalledAtString: deviceHelper.appInstalledAtString, - customParameters: mergedAttributes - ) - await Superwall.shared.track(trackableEvent) + if shouldTrackMerge { + Task { + let trackableEvent = InternalSuperwallEvent.Attributes( + appInstalledAtString: deviceHelper.appInstalledAtString, + customParameters: mergedAttributes + ) + await Superwall.shared.track(trackableEvent) + } } storage.save(mergedAttributes, forType: UserAttributes.self) diff --git a/Sources/SuperwallKit/Misc/Constants.swift b/Sources/SuperwallKit/Misc/Constants.swift index 3738c287b..84efdedf6 100644 --- a/Sources/SuperwallKit/Misc/Constants.swift +++ b/Sources/SuperwallKit/Misc/Constants.swift @@ -18,5 +18,5 @@ let sdkVersion = """ */ let sdkVersion = """ -3.2.0 +3.2.1 """ diff --git a/SuperwallKit.podspec b/SuperwallKit.podspec index 5e0c04cd7..dc4398b53 100644 --- a/SuperwallKit.podspec +++ b/SuperwallKit.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SuperwallKit" - s.version = "3.2.0" + s.version = "3.2.1" s.summary = "Superwall: In-App Paywalls Made Easy" s.description = "Paywall infrastructure for mobile apps :) we make things like editing your paywall and running price tests as easy as clicking a few buttons. superwall.com" diff --git a/SuperwallKit.xcodeproj/project.pbxproj b/SuperwallKit.xcodeproj/project.pbxproj index aa4a16d47..60c20ef1a 100644 --- a/SuperwallKit.xcodeproj/project.pbxproj +++ b/SuperwallKit.xcodeproj/project.pbxproj @@ -66,6 +66,7 @@ 2BEA0C3FED992CB3BBD2F5CC /* SK1StoreProductDiscount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C064AE76E6545B9595305D7 /* SK1StoreProductDiscount.swift */; }; 2C1CC812D17087B1CE54161A /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = F98F66F7AA2F9F3E96849D8A /* Config.swift */; }; 2C7867867DDAD83E5856ECC9 /* ASN1Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8087A8CD8F4FC7C745010428 /* ASN1Types.swift */; }; + 2CC98A7FC5577F9B8B0C9AD2 /* Error+SafeLocalizedDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A7FFEA64AF7F4E09F052FCD /* Error+SafeLocalizedDescription.swift */; }; 2D751F5C2F463DEEF0A49B42 /* PaywallCloseReason.swift in Sources */ = {isa = PBXBuildFile; fileRef = C36308E59620C724F701B803 /* PaywallCloseReason.swift */; }; 2EBE499C9918DE5823659CD0 /* InAppReceiptPayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 072886BB8C0E08DF414D9162 /* InAppReceiptPayload.swift */; }; 2EC1D279019CD3FB64E4674A /* TriggerResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25515131DF0AE67E26BFF462 /* TriggerResult.swift */; }; @@ -643,6 +644,7 @@ 98D3CEEDCBBDB85C54FDC128 /* PresentPaywall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentPaywall.swift; sourceTree = ""; }; 990461F7A9B2F3ED62B3A628 /* PaywallViewControllerDelegateAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallViewControllerDelegateAdapter.swift; sourceTree = ""; }; 991415992A1EA3C9E6DB7D25 /* TriggerSessionTrigger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerSessionTrigger.swift; sourceTree = ""; }; + 9A7FFEA64AF7F4E09F052FCD /* Error+SafeLocalizedDescription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Error+SafeLocalizedDescription.swift"; sourceTree = ""; }; 9B75209DF76859131941CA0F /* Variables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Variables.swift; sourceTree = ""; }; 9C2580C3CD6A8BF0C5258665 /* SWWebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SWWebView.swift; sourceTree = ""; }; 9DC4D23D1EDDA249C928930D /* PaddingListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingListener.swift; sourceTree = ""; }; @@ -1127,6 +1129,7 @@ 51407421A3CBF7AF0FC76E60 /* Bundle+Helpers.swift */, A9A3C997FDC1550AF477CA1D /* Decimal+Rounding.swift */, B2E6016BF483A4C47FF7A7C0 /* Encodable+Dictionary.swift */, + 9A7FFEA64AF7F4E09F052FCD /* Error+SafeLocalizedDescription.swift */, 8DE36D141F461F6E945823FA /* Future+Async.swift */, E2243C6BF6BE477794F568ED /* GCControllerElement+buttonName.swift */, FD778E66506BA51BEB5EE89C /* JSONEncoder+Superwall.swift */, @@ -2215,7 +2218,7 @@ path = Assignment; sourceTree = ""; }; - "TEMP_89BC623C-3735-4CC4-AA1A-3C36C0A6D055" /* Events */ = { + "TEMP_ECE821B9-9409-4D69-BD4B-9789D2EF963D" /* Events */ = { isa = PBXGroup; children = ( ); @@ -2454,6 +2457,7 @@ 9EAE577E60052F5E1C7B9657 /* EmptyResponse.swift in Sources */, CB1E11FB74879A29DD1C9EB1 /* Encodable+Dictionary.swift in Sources */, 11477D1EB60D1FDA32F5099A /* Endpoint.swift in Sources */, + 2CC98A7FC5577F9B8B0C9AD2 /* Error+SafeLocalizedDescription.swift in Sources */, B2842C329F0F9AAFC2040C35 /* EvaluateRules.swift in Sources */, 35597883CB038DBEE63E162B /* EventData.swift in Sources */, 211B94C3D7CEE3DEF10E5C79 /* EventsQueue.swift in Sources */, diff --git a/SuperwallKit.xcodeproj/xcshareddata/xcschemes/SuperwallKit.xcscheme b/SuperwallKit.xcodeproj/xcshareddata/xcschemes/SuperwallKit.xcscheme index 092f92ad0..233d92776 100644 --- a/SuperwallKit.xcodeproj/xcshareddata/xcschemes/SuperwallKit.xcscheme +++ b/SuperwallKit.xcodeproj/xcshareddata/xcschemes/SuperwallKit.xcscheme @@ -31,7 +31,8 @@ shouldUseLaunchSchemeArgsEnv = "NO"> + skipped = "NO" + parallelizable = "YES">