From cc33904026bdd1e4cbc24d1a3e0c1814c553e676 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Mon, 5 Jun 2023 12:57:27 -0500 Subject: [PATCH] Fix bug where New Tab Page ad viewed events fail on iOS --- .../New Tab Page/NewTabPageViewController.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift b/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift index 9ac95f0ce9e..addfbc6f07f 100644 --- a/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift +++ b/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift @@ -315,7 +315,17 @@ class NewTabPageViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - reportSponsoredImageBackgroundEvent(.viewed) + reportSponsoredImageBackgroundEvent(.served) + + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + // As a temporary fix until 1.53.x, we trigger the .viewed event after 1 second to + // give time for the .served event to be triggered; otherwise, the sponsored image + // viewed event will fail because it needs a corresponding served event. In 1.53.x + // and above we should trigger the .served event and in the completion block if + // successful we should trigger a .viewed event. + self.reportSponsoredImageBackgroundEvent(.viewed) + } + presentNotification() DispatchQueue.main.asyncAfter(deadline: .now() + 0.50) {