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

Move FE Overlay Pixel to the Native layer #3550

Merged
merged 4 commits into from
Nov 14, 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
32 changes: 32 additions & 0 deletions DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ final class DuckPlayerTabExtension {
}
}

private func fireOverlayShownPixelIfNeeded(url: URL) {

guard duckPlayer.isAvailable,
duckPlayer.mode == .alwaysAsk,
url.isYoutubeWatch else {
return
}

// Static variable for debounce logic
let debounceInterval: TimeInterval = 1.0
let now = Date()

struct Debounce {
static var lastFireTime: Date?
}

// Check debounce condition and update timestamp if firing
guard Debounce.lastFireTime == nil || now.timeIntervalSince(Debounce.lastFireTime!) >= debounceInterval else {
return
}

Debounce.lastFireTime = now
PixelKit.fire(GeneralPixel.duckPlayerOverlayYoutubeImpressions)
}
}

extension DuckPlayerTabExtension: YoutubeOverlayUserScriptDelegate {
Expand Down Expand Up @@ -191,6 +215,11 @@ extension DuckPlayerTabExtension: NavigationResponder {
return decidePolicyWithDisabledDuckPlayer(for: navigationAction)
}

// Fires the Overlay Shown Pixel if not coming from DuckPlayer's Watch in Youtube
if !navigationAction.sourceFrame.url.isDuckPlayer {
fireOverlayShownPixelIfNeeded(url: navigationAction.url)
}

// session restoration will try to load real www.youtube-nocookie.com url
// we need to redirect it to custom duck:// scheme handler which will load
// www.youtube-nocookie.com as a simulated request
Expand Down Expand Up @@ -288,6 +317,9 @@ extension DuckPlayerTabExtension: NavigationResponder {
webView.load(URLRequest(url: .duckPlayer(videoID, timestamp: timestamp)))
}

// Fire Overlay Shown Pixels
fireOverlayShownPixelIfNeeded(url: navigation.url)

// Fire DuckPlayer Overlay Temporary Pixels
if let url = navigation.request.url {
duckPlayerOverlayUsagePixels.handleNavigationAndFirePixels(url: url, duckPlayerMode: duckPlayer.mode)
Expand Down
7 changes: 5 additions & 2 deletions DuckDuckGo/YoutubePlayer/YoutubeOverlayUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ extension YoutubeOverlayUserScript {
case "play.do_not_use":
duckPlayerPreferences.youtubeOverlayAnyButtonPressed = true
PixelKit.fire(GeneralPixel.duckPlayerOverlayYoutubeWatchHere)
case "overlay":
PixelKit.fire(GeneralPixel.duckPlayerOverlayYoutubeImpressions)

// Moved to DuckPlayerTabExtension
// See :https://app.asana.com/0/1203249713006009/1208754606104659/f
// case "overlay":
// PixelKit.fire(GeneralPixel.duckPlayerOverlayYoutubeImpressions)
default:
break
}
Expand Down
Loading