Skip to content

Commit

Permalink
DuckPlayer contingency messages pixels (#3220)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1204167627774280/1208023423226059/f

**Description**:
Add pixels for contingency message on duck player
  • Loading branch information
Bunn authored Aug 9, 2024
1 parent d3bb651 commit 7cc31e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ extension Pixel {
case duckPlayerSettingNeverSettings
case duckPlayerSettingBackToDefault
case duckPlayerWatchOnYoutube
case duckPlayerContingencySettingsDisplayed
case duckPlayerContingencyLearnMoreClicked
}

}
Expand Down Expand Up @@ -1484,6 +1486,8 @@ extension Pixel.Event {
case .duckPlayerSettingNeverSettings: return "m_duck-player_setting_never_settings"
case .duckPlayerSettingBackToDefault: return "m_duck-player_setting_back-to-default"
case .duckPlayerWatchOnYoutube: return "m_duck-player_watch_on_youtube"
case .duckPlayerContingencySettingsDisplayed: return "duckplayer_ios_contingency_settings-displayed"
case .duckPlayerContingencyLearnMoreClicked: return "duckplayer_ios_contingency_learn-more-clicked"
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/SettingsDuckPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ import DuckUI
struct SettingsDuckPlayerView: View {
private static let learnMoreURL = URL(string: "https://duckduckgo.com/duckduckgo-help-pages/duck-player/")!

/// The ContingencyMessageView may be redrawn multiple times in the onAppear method if the user scrolls it outside the list bounds.
/// This property ensures that the associated action is only triggered once per viewing session, preventing redundant executions.
@State private var hasFiredSettingsDisplayedPixel = false

@EnvironmentObject var viewModel: SettingsViewModel
var body: some View {
List {
if viewModel.shouldDisplayDuckPlayerContingencyMessage {
Section {
ContingencyMessageView {
viewModel.openDuckPlayerContingencyMessageSite()
}.onAppear {
if !hasFiredSettingsDisplayedPixel {
Pixel.fire(pixel: .duckPlayerContingencySettingsDisplayed)
hasFiredSettingsDisplayedPixel = true
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ extension SettingsViewModel {

func openDuckPlayerContingencyMessageSite() {
guard let url = duckPlayerContingencyHandler.learnMoreURL else { return }
Pixel.fire(pixel: .duckPlayerContingencyLearnMoreClicked)
UIApplication.shared.open(url,
options: [:],
completionHandler: nil)
Expand Down

0 comments on commit 7cc31e9

Please sign in to comment.