brave / brave-ios

Brave iOS Browser
https://brave.com
Mozilla Public License 2.0
1.7k stars 441 forks source link

Fix #8521: ASA Custom Onboarding Feature Linkage #8591

Closed soner-yuksel closed 8 months ago

soner-yuksel commented 9 months ago

Summary of Changes

This pull request fixes #8521

Check the issue and details on goole doc about the desired feature behaviour.

Privacy Security Issue

https://github.com/brave/reviews/issues/1459

But what is done can be stated as

  1. Handling first ping app launch with user referral program

  2. Refactored DAU logic functions outside scene delegate

  3. Handle daily user ping with logic when p3a consent triggers ad attribution data
  4. Checking how to trigger loading at last stage of onboarding on button consent

  5. Refactor data call to use growth target so it can be used in Onboarding
  6. Write and execute new API calls for Reports API
  7. Write logic for Report API result depend on Attribution API and attribution failure will lead cancelation for logic and total time out logic for both of the calls
  8. Handle Report API logic and parse keywords for VPN table
and Playlist
  9. Handle Search Ad API Logic with no retry and shorter timeout
  10. Open VPN Buy Screen with VPN action or Playlist with action

Submitter Checklist:

Test Plan - Screenshots:

All Scenarios have same plan

Scenario 1: Error at the first step adCampaignLookup

Fetching attribution token or retrieving campaign attribution from ad services for fetched attribution token Loading should appear

Scenario 2: User disabled p3a on onboarding

https://github.com/brave/brave-ios/assets/6643505/fb7ec4c7-fc39-429f-b6ac-262e68976c3b

Scenario 3: adCampaignLookup succeeds

17 2

And if success scenario happens and the campaignID can match with of the features (vpn/playlist), the presentation logic should be executed.

Reviewer Checklist:

github-actions[bot] commented 8 months ago

[puLL-Merge] - brave/brave-ios@8591

Description

This PR makes adjustments across AppDelegate, SceneDelegate, and various BrowserViewController extension files in the brave-ios repository. The motivation is to handle daily user pings awaiting user consent (for onboarding) and reworking the app delegates and scene delegate's handling and initialization of UserReferralProgram and install attribution.

Changes ### Changes #### `App/iOS/Delegates/AppDelegate.swift` - Added a new preference flag `Preferences.AppState.dailyUserPingAwaitingUserConsent` that gets set during the first launch. - Simplified the user referral program checks by removing checks for `UserReferralProgram.shared` initialization and directly setting `Preferences.URP.referralLookupOutstanding` and `shouldHandleUrpLookup` for lookup processing. - Removed explicit setting of `Preferences.URP.installAttributionLookupOutstanding` and its associated checks. This is now directly managed in the `SceneDelegate`. #### `App/iOS/Delegates/SceneDelegate.swift` - Introduced an `AttributionManager` initialized with the `dau` (daily active users tracker) and `urp` (user referral program) parameters. - Handled referral lookup set by the previous flow with a new method `attributionManager.handleReferralLookup`. - Transferred the responsibility of checking and sending install attribution API requests to `AttributionManager`. The condition of P3A being enabled or not is now checked before sending API methods. - Added new conditions to set `Preferences.URP.referralLookupOutstanding` and `Preferences.URP.installAttributionLookupOutstanding` for install attribution fetch. #### Various `BrowserViewController` extensions - Renamed multiple `BrowserViewController` extensions to follow the BVC+ convention. - Updated `BrowserViewController+Callout` to inject the `AttributionManager`. - Integrated `AttributionManager` within the `BrowserViewController` by binding to `adFeatureLinkageCancelable` for `adFeatureLinkage`. #### `Sources/Brave/Frontend/ClientPreferences.swift` - Removed the unused preference `Preferences.NewTabPage.superReferrerThemeRetryDeadline`. #### `Sources/Brave/Frontend/Settings/Debug/RetentionPreferencesDebugMenuViewController.swift` and `Sources/Brave/Frontend/Settings/SettingsViewController.swift` - Added `AttributionManager` to dependency injection for initializing these view controllers. #### `Sources/BraveShared/Extensions/URLSessionExtensions.swift` - Added a `timeout` parameter to the URLSession extension methods for request building and API requests. This allows for configuring network timeouts. #### `Sources/BraveStrings/BraveStrings.swift` - Removed an unused string key `Strings.playlistMenuItem`. #### `Sources/Growth/DAU.swift`, `Sources/Growth/URP/AdAttributionData.swift`, `Sources/Growth/URP/AttributionManager.swift`, `Sources/Growth/URP/UrpService.swift` and `Sources/Growth/URP/UserReferralProgram.swift` - Refactored the `DAU` class to privatize `sendPingToServerInternal`. - Renamed `AdAttributionData` to `AdAttributionReportData` and added new properties and initializers. - Added new `AttributionManager` class to encapsulate handling of user referral and ad attribution logic. - Updated UrpService for ad campaign and ad group reporting with appropriate API request methods. - Made `UserReferralProgram` adjustments to fetch attribution tokens and conduct reporting with the new `AttributionManager`.

Security Hotspots

No explicit security hotspots are identified within the PR changes. However, since these changes involve handling sensitive user data and network requests, careful review of the handling of tokens, user consent flags, and network communications should be done to ensure user privacy is maintained.