diff --git a/ApphudSDK.podspec b/ApphudSDK.podspec index 4f46902..6de320d 100644 --- a/ApphudSDK.podspec +++ b/ApphudSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ApphudSDK' - s.version = '3.5.5' + s.version = '3.5.6' s.summary = 'Build and Measure In-App Subscriptions on iOS.' s.description = 'Apphud covers every aspect when it comes to In-App Subscriptions from integration to analytics on iOS and Android.' s.homepage = 'https://github.com/apphud/ApphudSDK' diff --git a/Sources/Internal/ApphudInternal+Attribution.swift b/Sources/Internal/ApphudInternal+Attribution.swift index a63509a..3f6364b 100644 --- a/Sources/Internal/ApphudInternal+Attribution.swift +++ b/Sources/Internal/ApphudInternal+Attribution.swift @@ -220,21 +220,38 @@ extension ApphudInternal { @MainActor internal func tryWebAttribution(attributionData: [AnyHashable: Any], completion: @escaping (Bool, ApphudUser?) -> Void) { - let userId = attributionData["aph_user_id"] ?? attributionData["apphud_user_id"] - if let userId = userId as? String, !userId.isEmpty { - - if (currentUser?.userId == userId) { - apphudLog("Already web2web user, skipping") - completion(true, currentUser) - return - } - - apphudLog("Found a match from web click, updating User ID to \(userId)", forceDisplay: true) - self.updateUser(fields: ["user_id": userId, "from_web2web": true]) { (result, _, data, _, _, _, attempts) in + + let userId = (attributionData["aph_user_id"] ?? attributionData["apphud_user_id"]) as? String ?? "" + let email = (attributionData["email"] ?? attributionData["apphud_user_email"]) as? String ?? "" + + if userId.isEmpty && email.isEmpty { + completion(false, currentUser) + return + } + + if (email.isEmpty && currentUser?.userId == userId) { + apphudLog("Already web2web user, skipping") + completion(true, currentUser) + return + } + + var params: [String: Any] = ["from_web2web": true] + if !userId.isEmpty { + params["user_id"] = userId + } + if !email.isEmpty { + params["email"] = email + } + + apphudLog("Found a match from web click, updating User ID to \(userId)", forceDisplay: true) + self.performWhenUserRegistered { + self.updateUser(fields: params) { (result, _, data, _, _, _, attempts) in if result { Task { - await self.parseUser(data: data) + let changes = await self.parseUser(data: data) + Task { @MainActor in + self.notifyAboutUpdates(changes) completion(true, self.currentUser) } } @@ -242,8 +259,6 @@ extension ApphudInternal { completion(false, self.currentUser) } } - } else { - completion(false, currentUser) } } } diff --git a/Sources/Public/Apphud.swift b/Sources/Public/Apphud.swift index 188099f..45f397c 100644 --- a/Sources/Public/Apphud.swift +++ b/Sources/Public/Apphud.swift @@ -14,7 +14,7 @@ import Foundation import UserNotifications import SwiftUI -internal let apphud_sdk_version = "3.5.5" +internal let apphud_sdk_version = "3.5.6" // MARK: - Initialization @@ -791,10 +791,12 @@ final public class Apphud: NSObject { /** Web-to-Web flow only. Attempts to attribute the user with the provided attribution data. - If the `data` parameter contains either `aph_user_id` or `apphud_user_id`, the SDK will submit this information to the Apphud server. - The server will return a premium web user if found; otherwise, the callback will return `false`. + If the `data` parameter contains either `aph_user_id`, `apphud_user_id`, `email` or `apphud_user_email`, the SDK will submit this information to the Apphud server. + The server will return a restored web user if found; otherwise, the callback will return `false`. + + __Important:__ If the callback returns `true`, it doesn't mean the user has premium access, you should still call `Apphud.hasPremiumAccess()`. - Additionally, the delegate methods `apphudSubscriptionsUpdated` and `apphudDidChangeUserID` will be called. + Additionally, the delegate methods `apphudSubscriptionsUpdated` and `apphudDidChangeUserID` may be called. The callback returns `true` if the user is successfully attributed via the web and includes the updated `ApphudUser` object. After this callback, you can check the `Apphud.hasPremiumAccess()` method, which should return `true` if the user has premium access.