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

Commit d31c473

Browse files
Fix #1855, Ref #1825: Ads now display on first launch and generate landings (#1912)
1 parent 0910207 commit d31c473

11 files changed

+45
-20
lines changed
Binary file not shown.

BraveRewards/BraveRewards.framework/Headers/BATBraveAds.h

+19-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ NS_SWIFT_NAME(BraveAds)
4141

4242
#pragma mark - Global
4343

44-
/// Whether or not a given region is supported. The region should be a standard
44+
/// Whether or not a given locale is supported. The locale should be a standard
4545
/// locale identifier, i.e. "en_US"
46-
+ (BOOL)isSupportedRegion:(NSString *)region;
46+
+ (BOOL)isSupportedLocale:(NSString *)locale;
4747

48-
/// Whether or not the users current region (by `NSLocale`) is supported
49-
+ (BOOL)isCurrentRegionSupported;
48+
/// Whether or not a given locale is newly supported. The locale should be a
49+
/// standard locale identifier, i.e. "en_US"
50+
+ (BOOL)isNewlySupportedLocale:(NSString *)locale;
51+
52+
/// Whether or not the users current locale (by `NSLocale`) is supported
53+
+ (BOOL)isCurrentLocaleSupported;
5054

5155
/// Whether or not to use staging servers. Defaults to false
5256
@property (nonatomic, class, getter=isDebug) BOOL debug;
@@ -56,6 +60,17 @@ NS_SWIFT_NAME(BraveAds)
5660
/// Marks if this is being ran in a test environment. Defaults to false
5761
@property (nonatomic, class, getter=isTesting) BOOL testing;
5862

63+
#pragma mark - Initialization / Shutdown
64+
65+
/// Initializes the ads service if ads is enabled
66+
- (void)initializeIfAdsEnabled;
67+
68+
/// Shuts down the ads service if its running
69+
- (void)shutdown;
70+
71+
/// Whether or not the ads service is running
72+
- (BOOL)isAdsServiceRunning;
73+
5974
#pragma mark - Configuration
6075

6176
/// Whether or not Brave Ads is enabled
1 Byte
Binary file not shown.

BraveRewardsUI/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ A UI framework for consuming Brave Rewards. The core logic around BraveRewards r
55
The latest BraveRewards.framework was built on:
66

77
```
8-
brave-browser/5d5f18be463abaf9b5f23d5b7ec14be51f7fd412
9-
brave-core/c4ddbe240f2b580f0c1c77e86d3b020b6988ae09
8+
brave-browser/c9404a71bb301d1303df1fcd2c24f7f614174fe9
9+
brave-core/888b808f99981e008bbac6c58123440eba64f230
1010
```

BraveRewardsUI/Settings/SettingsViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SettingsViewController: UIViewController {
5454
let dollarString = state.ledger.dollarStringForBATAmount(state.ledger.balance?.total ?? 0) ?? ""
5555
$0.walletSection.setWalletBalance(state.ledger.balanceString, crypto: Strings.WalletBalanceType, dollarValue: dollarString)
5656

57-
if !BraveAds.isCurrentRegionSupported() {
57+
if !BraveAds.isCurrentLocaleSupported() {
5858
$0.adsSection.status = .unsupportedRegion
5959
}
6060
$0.adsSection.toggleSwitch.isOn = state.ads.isEnabled

Client/Frontend/Browser/BrowserViewController.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class BrowserViewController: UIViewController {
284284
guard let rewards = rewards, rewards.ledger.isEnabled && rewards.ads.isEnabled else { return }
285285
if Preferences.Rewards.myFirstAdShown.value { return }
286286
// Check if ads are eligible
287-
if BraveAds.isCurrentRegionSupported() {
287+
if BraveAds.isCurrentLocaleSupported() {
288288
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
289289
if Preferences.Rewards.myFirstAdShown.value { return }
290290
Preferences.Rewards.myFirstAdShown.value = true
@@ -708,14 +708,14 @@ class BrowserViewController: UIViewController {
708708
// 2. User already completed onboarding.
709709
if Preferences.General.basicOnboardingCompleted.value == OnboardingState.completed.rawValue {
710710
// The user has ads in their region and they completed all onboarding.
711-
if BraveAds.isCurrentRegionSupported()
711+
if BraveAds.isCurrentLocaleSupported()
712712
&&
713713
Preferences.General.basicOnboardingProgress.value == OnboardingProgress.ads.rawValue {
714714
return
715715
}
716716

717717
// The user doesn't have ads in their region and they've completed rewards.
718-
if !BraveAds.isCurrentRegionSupported()
718+
if !BraveAds.isCurrentLocaleSupported()
719719
&&
720720
Preferences.General.basicOnboardingProgress.value == OnboardingProgress.rewards.rawValue {
721721
return
@@ -791,7 +791,7 @@ class BrowserViewController: UIViewController {
791791
// 1. Rewards are on/off (existing user)
792792
// 2. Ads are now available
793793
// 3. User hasn't seen the ads part of onboarding yet
794-
if BraveAds.isCurrentRegionSupported()
794+
if BraveAds.isCurrentLocaleSupported()
795795
&&
796796
(Preferences.General.basicOnboardingCompleted.value == OnboardingState.completed.rawValue)
797797
&&
@@ -3384,19 +3384,19 @@ extension BrowserViewController: OnboardingControllerDelegate {
33843384
#else
33853385
switch onboardingController.onboardingType {
33863386
case .newUser:
3387-
if BraveAds.isCurrentRegionSupported() {
3387+
if BraveAds.isCurrentLocaleSupported() {
33883388
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.ads.rawValue
33893389
} else {
33903390
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.rewards.rawValue
33913391
}
33923392

33933393
case .existingUserRewardsOff:
3394-
if BraveAds.isCurrentRegionSupported() {
3394+
if BraveAds.isCurrentLocaleSupported() {
33953395
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.ads.rawValue
33963396
}
33973397

33983398
case .existingUserRewardsOn:
3399-
if BraveAds.isCurrentRegionSupported() {
3399+
if BraveAds.isCurrentLocaleSupported() {
34003400
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.ads.rawValue
34013401
}
34023402

Client/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift

+10
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ extension BrowserViewController: WKNavigationDelegate {
374374
if let tab = tabManager[webView] {
375375
navigateInTab(tab: tab, to: navigation)
376376
if let rewards = rewards {
377+
if let url = tab.url, tab.shouldClassifyLoadsForAds {
378+
let faviconURL = URL(string: tab.displayFavicon?.url ?? "")
379+
rewards.reportTabUpdated(
380+
Int(tab.rewardsId),
381+
url: url,
382+
faviconURL: faviconURL,
383+
isSelected: tabManager.selectedTab == tab,
384+
isPrivate: PrivateBrowsingManager.shared.isPrivateBrowsing
385+
)
386+
}
377387
tab.reportPageLoad(to: rewards)
378388
}
379389
if webView.url?.isLocal == false {

Client/Frontend/Browser/Onboarding/OnboardingAdsCountdownViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class OnboardingAdsCountdownViewController: OnboardingViewController, UNUserNoti
7272
extension OnboardingAdsCountdownViewController {
7373

7474
private func displayMyFirstAdIfAvailable(_ completion: ((AdsNotificationHandler.Action) -> Void)? = nil) {
75-
if BraveAds.isCurrentRegionSupported() {
75+
if BraveAds.isCurrentLocaleSupported() {
7676
Preferences.Rewards.myFirstAdShown.value = true
7777
AdsViewController.displayFirstAd(on: self) { [weak self] action, url in
7878
if action == .opened {

Client/Frontend/Browser/Onboarding/OnboardingNavigationController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class OnboardingNavigationController: UINavigationController {
5555
}
5656
#else
5757
switch self {
58-
case .newUser: return BraveAds.isCurrentRegionSupported() ? [.searchEnginePicker, .shieldsInfo, .rewardsAgreement, .adsCountdown] : [.searchEnginePicker, .shieldsInfo, .rewardsAgreement]
59-
case .existingUserRewardsOff: return BraveAds.isCurrentRegionSupported() ? [.rewardsAgreement, .adsCountdown] : [.rewardsAgreement]
60-
case .existingUserRewardsOn: return BraveAds.isCurrentRegionSupported() ? [.existingRewardsTurnOnAds, .adsCountdown] : []
58+
case .newUser: return BraveAds.isCurrentLocaleSupported() ? [.searchEnginePicker, .shieldsInfo, .rewardsAgreement, .adsCountdown] : [.searchEnginePicker, .shieldsInfo, .rewardsAgreement]
59+
case .existingUserRewardsOff: return BraveAds.isCurrentLocaleSupported() ? [.rewardsAgreement, .adsCountdown] : [.rewardsAgreement]
60+
case .existingUserRewardsOn: return BraveAds.isCurrentLocaleSupported() ? [.existingRewardsTurnOnAds, .adsCountdown] : []
6161
}
6262
#endif
6363
}

Client/Frontend/Browser/Onboarding/OnboardingRewardsAgreementView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension OnboardingRewardsAgreementViewController {
6161

6262
private let subtitleLabel = CommonViews.secondaryText("").then {
6363
let adSupportedRegionText = Locale.current.isJapan ? Strings.OBRewardsDetailInAdRegionJapan : Strings.OBRewardsDetailInAdRegion
64-
$0.attributedText = BraveAds.isCurrentRegionSupported() ? adSupportedRegionText.boldWords(with: $0.font, amount: 2) : Strings.OBRewardsDetailOutsideAdRegion.boldWords(with: $0.font, amount: 1)
64+
$0.attributedText = BraveAds.isCurrentLocaleSupported() ? adSupportedRegionText.boldWords(with: $0.font, amount: 2) : Strings.OBRewardsDetailOutsideAdRegion.boldWords(with: $0.font, amount: 1)
6565
}
6666

6767
private lazy var descriptionLabel = UITextView().then {

Client/Frontend/Browser/Onboarding/OnboardingRewardsAgreementViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class OnboardingRewardsAgreementViewController: OnboardingViewController {
2020
override func viewDidLoad() {
2121
super.viewDidLoad()
2222

23-
let isAdsRegionSupported = BraveAds.isCurrentRegionSupported()
23+
let isAdsRegionSupported = BraveAds.isCurrentLocaleSupported()
2424

2525
let adSupportedRegionText = Locale.current.isJapan ? Strings.OBRewardsDetailInAdRegionJapan : Strings.OBRewardsDetailInAdRegion
2626
contentView.updateSubtitleText(isAdsRegionSupported ? adSupportedRegionText : Strings.OBRewardsDetailOutsideAdRegion, boldWords: isAdsRegionSupported ? 2 : 1)

0 commit comments

Comments
 (0)