-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pixels for Privacy Stats on HTML NTP (#3659)
Task/Issue URL: https://app.asana.com/0/69071770703008/1208936504720914/f Description: This change adds 2 new messages to track actions in the Privacy Stats widget and implements usage and debug pixels for Privacy Stats.
- Loading branch information
Showing
18 changed files
with
541 additions
and
79 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
DuckDuckGo/NewTabPage/NewTabPagePrivacyStatsEventHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// NewTabPagePrivacyStatsEventHandler.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Common | ||
import PixelKit | ||
import NewTabPage | ||
|
||
final class NewTabPagePrivacyStatsEventHandler: EventMapping<NewTabPagePrivacyStatsEvent> { | ||
|
||
init() { | ||
super.init { event, _, _, _ in | ||
switch event { | ||
case .showLess: | ||
PixelKit.fire(NewTabPagePixel.blockedTrackingAttemptsShowLess, frequency: .dailyAndCount) | ||
case .showMore: | ||
PixelKit.fire(NewTabPagePixel.blockedTrackingAttemptsShowMore, frequency: .dailyAndCount) | ||
} | ||
} | ||
} | ||
|
||
override init(mapping: @escaping EventMapping<NewTabPagePrivacyStatsEvent>.Mapping) { | ||
fatalError("Use init()") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PrivacyStatsErrorHandler.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Common | ||
import PixelKit | ||
import PrivacyStats | ||
|
||
final class PrivacyStatsErrorHandler: EventMapping<PrivacyStatsError> { | ||
|
||
init() { | ||
super.init { event, _, _, _ in | ||
PixelKit.fire(DebugEvent(NewTabPagePixel.privacyStatsDatabaseError, error: event), frequency: .dailyAndCount) | ||
} | ||
} | ||
|
||
override init(mapping: @escaping EventMapping<PrivacyStatsError>.Mapping) { | ||
fatalError("Use init()") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// NewTabPagePixel.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import PixelKit | ||
|
||
/** | ||
* This enum keeps pixels related to HTML New Tab Page. | ||
* | ||
* > Related links: | ||
* [Privacy Triage](https://app.asana.com/0/69071770703008/1208146890364172/f) | ||
* [Detailed Pixels description](https://app.asana.com/0/1201621708115095/1207983904350396/f) | ||
*/ | ||
enum NewTabPagePixel: PixelKitEventV2 { | ||
|
||
/** | ||
* Event Trigger: "Show Less" button is clicked in Privacy Stats table on the New Tab Page, to collapse the table. | ||
* | ||
* > Note: This isn't the section collapse setting (like for Favorites or Next Steps), but the sub-setting | ||
* to control whether the view should contain 5 most frequently blocked top companies or all top companies. | ||
* | ||
* Anomaly Investigation: | ||
* - This pixel is fired from `NewTabPagePrivacyStatsModel` in response to a message sent by the user script. | ||
* - In case of anomalies, check if the subscription between the user script and the model isn't causing the pixel | ||
* to be fired more than once per interaction. | ||
*/ | ||
case blockedTrackingAttemptsShowLess | ||
|
||
/** | ||
* Event Trigger: "Show More" button is clicked in Privacy Stats table on the New Tab Page, to expand the table. | ||
* | ||
* > Note: This isn't the section collapse setting (like for Favorites or Next Steps), but the sub-setting | ||
* to control whether the view should contain 5 most frequently blocked top companies or all top companies. | ||
* | ||
* Anomaly Investigation: | ||
* - This pixel is fired from `NewTabPagePrivacyStatsModel` in response to a message sent by the user script. | ||
* - In case of anomalies, check if the subscription between the user script and the model isn't causing the pixel | ||
* to be fired more than once per interaction. | ||
*/ | ||
case blockedTrackingAttemptsShowMore | ||
|
||
// MARK: - Debug | ||
|
||
/** | ||
* Event Trigger: Privacy Stats database fails to be initialized. Firing this pixel is followed by an app crash with a `fatalError`. | ||
* This pixel can be fired when there's no space on disk, when database migration fails or when database was tampered with. | ||
* This is a debug (health) pixel. | ||
* | ||
* Anomaly Investigation: | ||
* - If this spikes in production it may mean we've released a new PriacyStats database model version | ||
* and didn't handle migration correctly in which case we need a hotfix. | ||
* - Otherwise it may happen occasionally for users with not space left on device. | ||
*/ | ||
case privacyStatsCouldNotLoadDatabase | ||
|
||
/** | ||
* Event Trigger: Privacy Stats reports a database error when fetching, storing or clearing data, | ||
* as outlined by `PrivacyStatsError`. This is a debug (health) pixel. | ||
* | ||
* Anomaly Investigation: | ||
* - The errors here are all Core Data errors. The error code identifies the specific enum case of `PrivacyStatsError`. | ||
* - Check `PrivacyStats` for places where the error is thrown. | ||
*/ | ||
case privacyStatsDatabaseError | ||
|
||
var name: String { | ||
switch self { | ||
case .blockedTrackingAttemptsShowLess: return "m_mac_new-tab-page_blocked-tracking-attempts_show-less" | ||
case .blockedTrackingAttemptsShowMore: return "m_mac_new-tab-page_blocked-tracking-attempts_show-more" | ||
case .privacyStatsCouldNotLoadDatabase: return "new-tab-page_privacy-stats_could-not-load-database" | ||
case .privacyStatsDatabaseError: return "new-tab-page_privacy-stats_database_error" | ||
} | ||
} | ||
|
||
var parameters: [String: String]? { | ||
nil | ||
} | ||
|
||
var error: (any Error)? { | ||
nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.