-
Notifications
You must be signed in to change notification settings - Fork 4
Report THEOads interstitial errors as failed ads to Conviva #128
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
Open
tvanlaerhoven
wants to merge
3
commits into
main
Choose a base branch
from
feature/conviva/interstitialerror
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
35511cf
Report THEOads interstitial errors as failed ads to Conviva
devin-ai-integration[bot] 6311f77
Refactor interstitial error reporting per review, align with web
tvanlaerhoven 565e48a
Ignore interstitial errors for ad breaks in the past
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
Code/Conviva/Source/THEOads/Events/ConvivaHandlers/AdHandler+THEOads.swift
This file contains hidden or 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,48 @@ | ||
| // | ||
| // AdHandler+THEOads.swift | ||
| // | ||
|
|
||
| import ConvivaSDK | ||
| import THEOplayerSDK | ||
|
|
||
| #if canImport(THEOplayerTHEOadsIntegration) | ||
| import THEOplayerTHEOadsIntegration | ||
|
|
||
| extension AdHandler { | ||
| /// A THEOads (SGAI) ad break can fail before any ad is available, for example when the ad server | ||
| /// returns an empty VAST response. No ad break or ad events are dispatched in that case, so report | ||
| /// the attempted ad break as a failed ad to keep Conviva's ad attempt and fill rate metrics correct. | ||
| func interstitialError(event: THEOplayerTHEOadsIntegration.InterstitialErrorEvent, currentTime: Double) { | ||
| let interstitial = event.interstitial | ||
| guard interstitial.type == .adbreak, !Self.isPast(interstitial: interstitial, currentTime: currentTime) else { return } | ||
| self.reportFailedAdBreak( | ||
| message: event.message ?? "No ad available", | ||
| podDuration: interstitial.duration, | ||
| podPosition: Self.calculateInterstitialAdBreakPosition(startTime: interstitial.startTime) | ||
| ) | ||
| } | ||
|
|
||
| /// The position of a THEOads interstitial based on its start time. | ||
| static func calculateInterstitialAdBreakPosition(startTime: Double) -> String { | ||
| if startTime == 0 { | ||
| return "Pre-roll" | ||
| } else if startTime < 0 || !startTime.isFinite { | ||
| return "Post-roll" | ||
| } else { | ||
| return "Mid-roll" | ||
| } | ||
| } | ||
|
|
||
| /// Whether the interstitial's ad break lies entirely behind the current time, for example a break in the | ||
| /// DVR window of a live stream when tuning in. Such breaks can report an error without ever having been | ||
| /// an actual ad attempt, so they should not be reported as failed ads. | ||
| static func isPast(interstitial: THEOplayerTHEOadsIntegration.Interstitial, currentTime: Double) -> Bool { | ||
| let startTime = interstitial.startTime | ||
| guard startTime >= 0, startTime.isFinite else { | ||
| // A post-roll is never in the past. | ||
| return false | ||
| } | ||
| return startTime + (interstitial.duration ?? 0) < currentTime | ||
| } | ||
| } | ||
| #endif | ||
39 changes: 39 additions & 0 deletions
39
Code/Conviva/Source/THEOads/Events/Observers/THEOadsEventForwarder.swift
This file contains hidden or 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 @@ | ||
| // | ||
| // THEOadsEventForwarder.swift | ||
| // | ||
|
|
||
| import THEOplayerSDK | ||
| import THEOplayerConnectorUtilities | ||
| #if canImport(THEOplayerTHEOadsIntegration) | ||
| import THEOplayerTHEOadsIntegration | ||
|
|
||
| /// A handle that registers THEOads listeners on a theoplayer and removes them on deinit | ||
| class THEOadsEventForwarder { | ||
| private let theoadsObserver: DispatchObserver? | ||
|
|
||
| init(player: THEOplayer, handler: AdHandler) { | ||
| if let theoads = player.theoads { | ||
| self.theoadsObserver = .init( | ||
| dispatcher: theoads, | ||
| eventListeners: Self.forwardEvents(from: theoads, to: handler) { [weak player] in | ||
| player?.currentTime ?? 0 | ||
| } | ||
| ) | ||
| } else { | ||
| self.theoadsObserver = nil | ||
| } | ||
| } | ||
|
|
||
| static func forwardEvents<Dispatcher: EventDispatcherProtocol>( | ||
| from theoads: Dispatcher, | ||
| to handler: AdHandler, | ||
| currentTime: @escaping () -> Double | ||
| ) -> [RemovableEventListenerProtocol] { | ||
| [ | ||
| theoads.addRemovableEventListener(type: THEOadsEventTypes.INTERSTITIAL_ERROR) { event in | ||
| handler.interstitialError(event: event, currentTime: currentTime()) | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is enough to determine an interstitial as a preroll. Some live streams don't start at
0, and some interstitials will still behave as prerolls when presented upon joining a live stream. In that case startTime can be > 0.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think pre-roll is a "concept" for a live stream tbh with THEOads.
@tvanlaerhoven how was this concluded for web?