Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Adding linage and showing proper feature handle screen
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Jan 2, 2024
1 parent b54736e commit cc1dcab
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extension BrowserViewController {
}
}

private func presentPlaylistController() {
public func presentPlaylistController() {
if PlaylistCarplayManager.shared.isPlaylistControllerPresented {
let alert = UIAlertController(title: Strings.PlayList.playlistAlreadyShowingTitle,
message: Strings.PlayList.playlistAlreadyShowingBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,14 @@ public class BrowserViewController: UIViewController {
.removeDuplicates()
.sink(receiveValue: { [weak self] featureLinkageType in
guard let self = self else { return }
switch featureLinkageType {
case .playlist:
self.presentPlaylistController()
case .vpn:
self.navigationHelper.openVPNBuyScreen(iapObserver: self.iapObserver)
default:
return
}

print("Feature is linked \(featureLinkageType)")
})
Expand Down
1 change: 0 additions & 1 deletion Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,6 @@ extension Strings {
public static let requestCaptureDevicePermissionAllowButtonTitle = NSLocalizedString("requestCaptureDevicePermissionAllowButtonTitle", tableName: "BraveShared", bundle: .module, value: "Allow", comment: "A button shown in a permission dialog that will grant the website the ability to use the device's camera or microphone")
public static let downloadsMenuItem = NSLocalizedString("DownloadsMenuItem", tableName: "BraveShared", bundle: .module, value: "Downloads", comment: "Title for downloads menu item")
public static let downloadsPanelEmptyStateTitle = NSLocalizedString("DownloadsPanelEmptyStateTitle", tableName: "BraveShared", bundle: .module, value: "Downloaded files will show up here.", comment: "Title for when a user has nothing downloaded onto their device, and the list is empty.")
public static let playlistMenuItem = NSLocalizedString("PlaylistMenuItem", tableName: "BraveShared", bundle: .module, value: "Playlist", comment: "Playlist menu item")

// MARK: - Themes

Expand Down
34 changes: 27 additions & 7 deletions Sources/Growth/URP/AttributionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ import Preferences
import Combine
import Shared

public enum FeatureLinkageType {
case undefined, vpn, playlist
public enum FeatureLinkageType: CaseIterable {
case notdefined, vpn, playlist, leoAI

var adKeywords: [String] {
switch self {
case .vpn:
return ["vpn, 1.1.1.1"]
case .playlist:
return ["youtube", "video player", "playlist"]
default:
return [] // Return nil for any other case
}
}
}

public enum FeatureLinkageError: Error {
Expand All @@ -24,7 +35,7 @@ public class AttributionManager {
/// The default Install Referral Code
private let organicInstallReferralCode = "BRV001"

@Published public var adFeatureLinkage: FeatureLinkageType = .undefined
@Published public var adFeatureLinkage: FeatureLinkageType = .notdefined

public init(dau: DAU, urp: UserReferralProgram) {
self.dau = dau
Expand All @@ -51,7 +62,7 @@ public class AttributionManager {
}
}

@MainActor public func handleAdsReportingFeatureLinkage() async throws -> (keyword: String, attributionData: AdAttributionData) {
@MainActor public func handleAdsReportingFeatureLinkage() async throws -> (featureType: FeatureLinkageType, attributionData: AdAttributionData) {
// This function should run multiple tasks first adCampaignLookup
// and adReportsKeywordLookup depending on adCampaignLookup result.
// There is maximum threshold of 5 sec for all the tasks to be completed
Expand All @@ -73,11 +84,13 @@ public class AttributionManager {

let task2Timeout = DispatchTime.now() + .seconds(Int(remainingTime))

let keywordResult = try await withCheckedThrowingContinuation { continuation in
let featureTypeResult = try await withCheckedThrowingContinuation { continuation in
Task.detached {
do {
self.generateReferralCodeAndPingServer(with: attributionData)
let keyword = try await self.urp.adReportsKeywordLookup(attributionData: attributionData)
continuation.resume(returning: keyword)
let featureLinkageType = self.fetchFeatureTypes(for: keyword)
continuation.resume(returning: featureLinkageType)
} catch {
continuation.resume(throwing: SearchAdError.successfulCampaignFailedKeywordLookup(attributionData))
}
Expand All @@ -87,12 +100,19 @@ public class AttributionManager {
continuation.resume(throwing: FeatureLinkageError.executionTimeout(attributionData))
}
}
return (keywordResult, attributionData)
return (featureTypeResult, attributionData)
} catch {
throw error
}
}

private func fetchFeatureTypes(for keyword: String) -> FeatureLinkageType {
for linkageType in FeatureLinkageType.allCases where linkageType.adKeywords.contains(keyword) {
return linkageType
}
return .notdefined
}

public func setupReferralCodeAndPingServer(refCode: String? = nil) {
let refCode = refCode ?? organicInstallReferralCode

Expand Down
4 changes: 2 additions & 2 deletions Sources/Onboarding/Welcome/WelcomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ public class WelcomeViewController: UIViewController {
Task { @MainActor in
do {
// Handle API calls and send linkage type
let featureType = try await controller.attributionManager.handleAdsReportingFeatureLinkage()
// controller.attributionManager.adFeatureLinkage = featureType!
let reportLink = try await controller.attributionManager.handleAdsReportingFeatureLinkage()
controller.attributionManager.adFeatureLinkage = reportLink.featureType

controller.calloutView.isLoading = false
self?.close()
Expand Down

0 comments on commit cc1dcab

Please sign in to comment.