Skip to content

Commit

Permalink
Add logic to record Brave.Shields.AdBlockSetting & Brave.Shields.Fing…
Browse files Browse the repository at this point in the history
…erprintBlockSetting initial P3A values (in addition to when value changes).
  • Loading branch information
StephenHeaps committed Sep 16, 2024
1 parent cf16fb5 commit 5f1d5e5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
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

0 comments on commit 5f1d5e5

Please sign in to comment.