Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(privacy): Add logic to record initial AdBlockSetting & FingerprintBlockSetting values #25582

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,14 @@ extension BrowserViewController {
}

@MainActor func maybeRecordInitialShieldsP3A() {
if Preferences.Shields.initialP3AStateReported.value { return }
defer { Preferences.Shields.initialP3AStateReported.value = true }
// Increment this version if metrics in this function change
// so that all metrics can be re-reported after update.
let kCurrentReportRevision = 1
guard kCurrentReportRevision > Preferences.Shields.initialP3AStateReportedRevision.value else {
return
}
recordGlobalAdBlockShieldsP3A()
recordGlobalFingerprintingShieldsP3A()
let buckets: [Bucket] = [
0,
.r(1...5),
Expand All @@ -146,6 +152,8 @@ extension BrowserViewController {
]
recordShieldsLevelUpdateP3A(buckets: buckets)
recordFinterprintProtectionP3A(buckets: buckets)

Preferences.Shields.initialP3AStateReportedRevision.value = kCurrentReportRevision
}

@MainActor private func recordShieldsLevelUpdateP3A(buckets: [Bucket]) {
Expand Down Expand Up @@ -184,6 +192,36 @@ extension BrowserViewController {
)
}

func recordGlobalAdBlockShieldsP3A() {
// Q46 What is the global ad blocking shields setting?
enum Answer: Int, CaseIterable {
case disabled = 0
case standard = 1
case aggressive = 2
}

let answer = { () -> Answer in
switch ShieldPreferences.blockAdsAndTrackingLevel {
case .disabled: return .disabled
case .standard: return .standard
case .aggressive: return .aggressive
}
}()

UmaHistogramEnumeration("Brave.Shields.AdBlockSetting", sample: answer)
}

func recordGlobalFingerprintingShieldsP3A() {
// Q47 What is the global fingerprinting shields setting?
enum Answer: Int, CaseIterable {
case disabled = 0
case standard = 1
case aggressive = 2
}
let answer: Answer = Preferences.Shields.fingerprintingProtection.value ? .standard : .disabled
UmaHistogramEnumeration("Brave.Shields.FingerprintBlockSetting", sample: answer)
}

func recordDataSavedP3A(change: Int) {
var dataSavedStorage = P3ATimedStorage<Int>.dataSavedStorage
dataSavedStorage.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3283,12 +3283,16 @@ extension BrowserViewController: PreferencesObserver {
tabManager.reloadSelectedTab()
case Preferences.General.enablePullToRefresh.key:
tabManager.selectedTab?.updatePullToRefreshVisibility()
case ShieldPreferences.blockAdsAndTrackingLevelRaw.key,
Preferences.Shields.blockScripts.key,
case Preferences.Shields.blockScripts.key,
Preferences.Shields.blockImages.key,
Preferences.Shields.fingerprintingProtection.key,
Preferences.Shields.useRegionAdBlock.key:
tabManager.reloadSelectedTab()
case ShieldPreferences.blockAdsAndTrackingLevelRaw.key:
tabManager.reloadSelectedTab()
recordGlobalAdBlockShieldsP3A()
case Preferences.Shields.fingerprintingProtection.key:
tabManager.reloadSelectedTab()
recordGlobalFingerprintingShieldsP3A()
case Preferences.General.defaultPageZoomLevel.key:
tabManager.allTabs.forEach({
guard let url = $0.webView?.url else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ import os
@Published var adBlockAndTrackingPreventionLevel: ShieldLevel {
didSet {
ShieldPreferences.blockAdsAndTrackingLevel = adBlockAndTrackingPreventionLevel
if adBlockAndTrackingPreventionLevel != oldValue {
recordGlobalAdBlockShieldsP3A()
}
}
}
@Published var httpsUpgradeLevel: HTTPSUpgradeLevel {
Expand Down Expand Up @@ -278,43 +275,5 @@ import os
}
}
.store(in: &subscriptions)

Preferences.Shields.fingerprintingProtection.$value
.sink { [weak self] _ in
self?.recordGlobalFingerprintingShieldsP3A()
}
.store(in: &subscriptions)
}

// MARK: - P3A

private func recordGlobalAdBlockShieldsP3A() {
// Q46 What is the global ad blocking shields setting?
enum Answer: Int, CaseIterable {
case disabled = 0
case standard = 1
case aggressive = 2
}

let answer = { () -> Answer in
switch ShieldPreferences.blockAdsAndTrackingLevel {
case .disabled: return .disabled
case .standard: return .standard
case .aggressive: return .aggressive
}
}()

UmaHistogramEnumeration("Brave.Shields.AdBlockSetting", sample: answer)
}

private func recordGlobalFingerprintingShieldsP3A() {
// Q47 What is the global fingerprinting shields setting?
enum Answer: Int, CaseIterable {
case disabled = 0
case standard = 1
case aggressive = 2
}
let answer: Answer = Preferences.Shields.fingerprintingProtection.value ? .standard : .disabled
UmaHistogramEnumeration("Brave.Shields.FingerprintBlockSetting", sample: answer)
}
}
6 changes: 3 additions & 3 deletions ios/brave-ios/Sources/Preferences/GlobalPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ extension Preferences {
default: false
)
/// Whether or not we've reported the initial state of shields for p3a
public static let initialP3AStateReported = Option<Bool>(
key: "shields.initial-p3a-state-reported",
default: false
public static let initialP3AStateReportedRevision = Option<Int>(
key: "shields.initial-p3a-state-reported-revision",
default: 0
)
}

Expand Down
Loading