Skip to content
Open
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
30 changes: 30 additions & 0 deletions app/assets/js/video-ad-policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export interface PauseAdEligibility {
isAdActive: boolean
isContentEnded: boolean
isProgrammatic: boolean
isRequestPending: boolean
isVisible: boolean
wasShown: boolean
}

export function getVideoAdSchedule(videoCount: number) {
return {
pauseRoll: videoCount > 0 && videoCount % 2 === 0,
preRoll: videoCount > 3 && videoCount % 3 === 0
}
}

export function shouldLoadVideoAds(isPremium: boolean, schedule: ReturnType<typeof getVideoAdSchedule>) {
return !isPremium && (schedule.pauseRoll || schedule.preRoll)
}

export function isEligiblePauseAd({
isAdActive,
isContentEnded,
isProgrammatic,
isRequestPending,
isVisible,
wasShown
}: PauseAdEligibility) {
return !isAdActive && !isContentEnded && !isProgrammatic && !isRequestPending && isVisible && !wasShown
}
Loading