diff --git a/Sources/Growth/URP/AttributionManager.swift b/Sources/Growth/URP/AttributionManager.swift index 144d0b291c1..1d83cb0cc2d 100644 --- a/Sources/Growth/URP/AttributionManager.swift +++ b/Sources/Growth/URP/AttributionManager.swift @@ -84,8 +84,9 @@ public class AttributionManager { @MainActor public func handleSearchAdsFeatureLinkage() async throws -> FeatureLinkageType { do { - let attributionData = try await handleSearchAdsInstallAttribution() - + let attributionData = try await urp.adCampaignLookup(isRetryEnabled: false, timeout: 30) + generateReferralCodeAndPingServer(with: attributionData) + return fetchFeatureTypes(for: attributionData.campaignId) } catch { throw error diff --git a/Sources/Growth/URP/UrpService.swift b/Sources/Growth/URP/UrpService.swift index 20a55d63b9d..fb519d61248 100644 --- a/Sources/Growth/URP/UrpService.swift +++ b/Sources/Growth/URP/UrpService.swift @@ -80,7 +80,7 @@ struct UrpService { } } - @MainActor func adCampaignTokenLookupQueue(adAttributionToken: String, isRetryEnabled: Bool = true) async throws -> AdAttributionData { + @MainActor func adCampaignTokenLookupQueue(adAttributionToken: String, isRetryEnabled: Bool = true, timeout: TimeInterval) async throws -> AdAttributionData { guard let endPoint = URL(string: adServicesURL) else { Logger.module.error("AdServicesURLString can not be resolved: \(adServicesURL)") throw URLError(.badURL) @@ -89,7 +89,11 @@ struct UrpService { let attributionDataToken = adAttributionToken.data(using: .utf8) do { - let (result, _) = try await sessionManager.adServicesAttributionApiRequest(endPoint: endPoint, rawData: attributionDataToken, isRetryEnabled: isRetryEnabled) + let (result, _) = try await sessionManager.adServicesAttributionApiRequest( + endPoint: endPoint, + rawData: attributionDataToken, + isRetryEnabled: isRetryEnabled, + timeout: timeout) UrpLog.log("Ad Attribution response: \(result)") if let resultData = result as? Data { @@ -167,7 +171,7 @@ extension URLSession { } // Apple ad service attricution request requires plain text encoding with post method and passing token as rawdata - func adServicesAttributionApiRequest(endPoint: URL, rawData: Data?, isRetryEnabled: Bool) async throws -> (Any, URLResponse) { + func adServicesAttributionApiRequest(endPoint: URL, rawData: Data?, isRetryEnabled: Bool, timeout: TimeInterval) async throws -> (Any, URLResponse) { // Re-try logic will not be enabled while onboarding happening on first launch if isRetryEnabled { // According to attributiontoken API docs @@ -177,7 +181,7 @@ extension URLSession { return try await self.request(endPoint, method: .post, rawData: rawData, encoding: .textPlain) }.value } else { - return try await self.request(endPoint, method: .post, rawData: rawData, encoding: .textPlain) + return try await self.request(endPoint, method: .post, rawData: rawData, encoding: .textPlain, timeout: timeout) } } diff --git a/Sources/Growth/URP/UserReferralProgram.swift b/Sources/Growth/URP/UserReferralProgram.swift index c4427c90fe0..48cc74dd8e8 100644 --- a/Sources/Growth/URP/UserReferralProgram.swift +++ b/Sources/Growth/URP/UserReferralProgram.swift @@ -115,14 +115,16 @@ public class UserReferralProgram { service.referralCodeLookup(refCode: refCode, completion: referralBlock) } - @MainActor public func adCampaignLookup(isRetryEnabled: Bool = true) async throws -> AdAttributionData { + @MainActor public func adCampaignLookup(isRetryEnabled: Bool = true, timeout: TimeInterval = 60) async throws -> AdAttributionData { // Fetching ad attibution token do { let adAttributionToken = try AAAttribution.attributionToken() do { - return try await service.adCampaignTokenLookupQueue(adAttributionToken: adAttributionToken) - + return try await service.adCampaignTokenLookupQueue( + adAttributionToken: adAttributionToken, + isRetryEnabled: isRetryEnabled, + timeout: timeout) } catch { Logger.module.info("Could not retrieve ad campaign attibution from ad services") throw error