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

Commit

Permalink
Fix #1938: Initialize P3A service and add P3A pref in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson authored and soner-yuksel committed Oct 31, 2022
1 parent ef62c32 commit 7ef5134
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
9 changes: 9 additions & 0 deletions App/iOS/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
.didFinishLaunching(options: launchOptions ?? [:])
)

// DAU may not have pinged on the first launch so weekOfInstallation pref may not be set yet
if let weekOfInstall = Preferences.DAU.weekOfInstallation.value ??
Preferences.DAU.installationDate.value?.mondayOfCurrentWeekFormatted {
braveCore.initializeP3AService(
forChannel: AppConstants.buildChannel.serverChannelParam,
weekOfInstall: weekOfInstall
)
}

return shouldPerformAdditionalDelegateHandling
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ extension BrowserViewController: TopToolbarDelegate {
profile: self.profile,
tabManager: self.tabManager,
feedDataSource: self.feedDataSource,
historyAPI: self.braveCore.historyAPI
historyAPI: self.braveCore.historyAPI,
p3aUtilities: self.braveCore.p3aUtils
)
let container = SettingsNavigationController(rootViewController: shieldsAndPrivacy)
container.isModalInPresentation = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
let tabManager: TabManager
let feedDataSource: FeedDataSource
let historyAPI: BraveHistoryAPI

init(profile: Profile, tabManager: TabManager, feedDataSource: FeedDataSource, historyAPI: BraveHistoryAPI) {
let p3aUtilities: BraveP3AUtils

init(
profile: Profile,
tabManager: TabManager,
feedDataSource: FeedDataSource,
historyAPI: BraveHistoryAPI,
p3aUtilities: BraveP3AUtils
) {
self.profile = profile
self.tabManager = tabManager
self.feedDataSource = feedDataSource
self.historyAPI = historyAPI
self.p3aUtilities = p3aUtilities
super.init(style: .insetGrouped)
}

Expand Down Expand Up @@ -222,6 +230,16 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
}()

private lazy var otherSettingsSection: Section = {
let p3aRow = Row.boolRow(
title: Strings.P3A.settingTitle,
detailText: Strings.P3A.settingSubtitle,
toggleValue: p3aUtilities.isP3AEnabled,
valueChange: { [unowned self] isOn in
p3aUtilities.isP3AEnabled = isOn
},
cellReuseId: "p3a"
)

var section = Section(
header: .title(Strings.otherPrivacySettingsSection),
rows: [
Expand All @@ -247,6 +265,7 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
)
)
}
section.rows.append(p3aRow)

return section
}()
Expand Down
6 changes: 5 additions & 1 deletion Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SettingsViewController: TableViewController {
private let passwordAPI: BravePasswordAPI
private let syncAPI: BraveSyncAPI
private let syncProfileServices: BraveSyncProfileServiceIOS
private let p3aUtilities: BraveP3AUtils
private let keyringStore: KeyringStore?
private let cryptoStore: CryptoStore?
private let windowProtection: WindowProtection?
Expand Down Expand Up @@ -73,6 +74,7 @@ class SettingsViewController: TableViewController {
self.passwordAPI = braveCore.passwordAPI
self.syncAPI = braveCore.syncAPI
self.syncProfileServices = braveCore.syncProfileService
self.p3aUtilities = braveCore.p3aUtils
self.keyringStore = keyringStore
self.cryptoStore = cryptoStore

Expand Down Expand Up @@ -204,7 +206,9 @@ class SettingsViewController: TableViewController {
profile: self.profile,
tabManager: self.tabManager,
feedDataSource: self.feedDataSource,
historyAPI: self.historyAPI)
historyAPI: self.historyAPI,
p3aUtilities: self.p3aUtilities
)
self.navigationController?.pushViewController(controller, animated: true)
}, image: UIImage(named: "settings-shields", in: .module, compatibleWith: nil)!, accessory: .disclosureIndicator)
],
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveShared/Analytics/DAU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public class DAU {

extension Date {
/// Returns date of current week's monday in YYYY-MM-DD formatted String
var mondayOfCurrentWeekFormatted: String? {
public var mondayOfCurrentWeekFormatted: String? {
// We look for a previous monday because Sunday is considered a beggining of a new week using default gregorian calendar.
// For example if today is Sunday, the next Monday using Calendar would be the day after Sunday which is wrong.
// That's why backward search may sound counter intuitive.
Expand Down
15 changes: 14 additions & 1 deletion Sources/BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ extension Strings {
public static let HTTPSEverywhere = NSLocalizedString("HTTPSEverywhere", tableName: "BraveShared", bundle: .module, value: "Upgrade Connections to HTTPS", comment: "")
public static let HTTPSEverywhereDescription = NSLocalizedString("HTTPSEverywhereDescription", tableName: "BraveShared", bundle: .module, value: "Opens sites using secure HTTPS instead of HTTP when possible.", comment: "")
public static let blockPhishingAndMalware = NSLocalizedString("BlockPhishingAndMalware", tableName: "BraveShared", bundle: .module, value: "Block Phishing and Malware", comment: "")
public static let googleSafeBrowsing = NSLocalizedString("GoogleSafeBrowsing", tableName: "BraveShared", bundle: .module, value: "Block dangerous sites", comment: "")
public static let googleSafeBrowsing = NSLocalizedString("GoogleSafeBrowsing", tableName: "BraveShared", bundle: .module, value: "Block Dangerous Sites", comment: "")
public static let googleSafeBrowsingUsingWebKitDescription = NSLocalizedString("GoogleSafeBrowsingUsingWebKitDescription", tableName: "BraveShared", bundle: .module, value: "Sends obfuscated URLs of some pages you visit to the Google Safe Browsing service, when your security is at risk.", comment: "")
public static let contentFiltering = NSLocalizedString("ContentFiltering", tableName: "BraveShared", bundle: .module, value: "Content Filtering", comment: "A title to the content filtering page under global shield settings and the title on the Content filtering page")
public static let blockMobileAnnoyances = NSLocalizedString("blockMobileAnnoyances", tableName: "BraveShared", bundle: .module, value: "Block 'Switch to App' Notices", comment: "A title for setting which blocks 'switch to app' popups")
Expand Down Expand Up @@ -4093,6 +4093,19 @@ extension Strings {
}
}

// P3A
extension Strings {
public struct P3A {
public static let settingTitle = NSLocalizedString("p3a.settingTitle", tableName: "BraveShared", bundle: .module,
value: "Allow Privacy-Preserving Product Analytics (P3A)",
comment: "The title for the setting that will allow a user to toggle sending privacy preserving analytics to Brave. P3A is the name of a Brave Product")

public static let settingSubtitle = NSLocalizedString("p3a.settingSubtitle", tableName: "BraveShared", bundle: .module,
value: "Anonymized P3A info helps Brave estimate overall usage and ensure we're improving popular features",
comment: "A subtitle shown on the setting that toggles analytics on Brave. P3A is the name of a Brave Product")
}
}

// Page Zoom
extension Strings {
public struct PageZoom {
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveShared/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Preferences {
extension Preferences {
public final class DAU {
public static let lastLaunchInfo = Option<[Int?]?>(key: "dau.last-launch-info", default: nil)
static let weekOfInstallation = Option<String?>(key: "dau.week-of-installation", default: nil)
public static let weekOfInstallation = Option<String?>(key: "dau.week-of-installation", default: nil)
// On old codebase we checked existence of `dau_stat` to determine whether it's first server ping.
// We need to translate that to use the new `firstPingParam` preference.
static let firstPingParam: Option<Bool> =
Expand Down

0 comments on commit 7ef5134

Please sign in to comment.