Ad Frequency Control
Ad frequency control (AFC) limits how often viewers see ads. With AFC, you set a simple rule: after a viewer has watched an ad break, no more ads play until they've watched a set amount of content.
Why use AFC
AFC helps you balance ad revenue with viewer experience. Use it when you want to:
- Avoid showing back-to-back ad breaks to the same viewer.
- Give viewers an ad-free stretch of content after they've seen ads.
- Tune ad pressure with a few settings, without changing your ad schedule.
AFC applies to Google IMA (CSAI & SSAI) and AWS MediaTailor.
Configure AFC
The AdFrequencyControlConfiguration object enables AFC and defines its
thresholds. The following table lists the default values. Set enabled to
true to enforce AFC.
| Property | Default | Description |
|---|---|---|
enabled | false | Enables AFC enforcement. |
minimumContentConsumptionInMS | 180000 (3 minutes) | Minimum amount of content, in milliseconds, the user must watch after an exposed ad break before the next ad break is allowed to play. |
adBreakExposureThreshold | 0.66 | Minimum fraction of an ad break the user must watch for it to count as sufficiently exposed. A value of 0.66 represents 66% exposure. |
allowFirstOpportunity | true | Always allows the first ad opportunity (for example, the preroll) to play, even when AFC is enabled. |
persistAcrossAppRestarts | false | Keeps the AFC state across app restarts. See Keep AFC state across app restarts. |
AFC integration with Ad Players
Create a configuration and pass it to the ads player builder. The examples in the following sections use this configuration.
const adFrequencyControlConfiguration: AdFrequencyControlConfiguration = {
enabled: true,
minimumContentConsumptionInMS: 180000, // User must watch 3 minutes of content
adBreakExposureThreshold: 0.66, // Ad break counts as exposed after 66% is watched
allowFirstOpportunity: true, // Always play the first ad, such as the preroll
};
Keep AFC state across app restarts
By default, AFC keeps its state in sessionStorage, so the suppression window
resets when the user closes and relaunches the app. Set
persistAcrossAppRestarts to true to keep the state in localStorage
instead. A suppression window that started before a restart then still applies
after it. The SDK manages the storage, so your app doesn't write any storage
code.
const adFrequencyControl: AdFrequencyControlConfiguration = {
enabled: true,
minimumContentConsumptionInMS: 180000,
adBreakExposureThreshold: 0.66,
allowFirstOpportunity: true,
persistAcrossAppRestarts: true, // Keep the ad-free window after a relaunch
};
If localStorage isn't available, for example because the platform blocks it,
AFC falls back to sessionStorage. Leave the option unset, or set it to
false, to keep the existing behavior.
Use AFC with IMA CSAI
Pass AdFrequencyControlConfiguration to the IMA CSAI player builder when you
want the client to suppress ad opportunities until the playback thresholds are
met.
const adPlayer = createImaPlayerBuilder()
.ima(window.google.ima)
.adRequest({ adTagUrl: adTagUrl, slotWidth: 1080, slotHeight: 720 })
.contentPlayer(contentPlayer)
.contentVideoElement(videoElement)
.contentContainerElement(videoWrapper)
.adFrequencyControl(adFrequencyControl)
.build();
Use AFC with IMA DAI
Configure AFC on the DAI ad player builder when you use the Google IMA DAI stream manager. This keeps the ad opportunity gating logic in the player layer while the DAI session handles stream creation.
const adsPlayer = createImaPlayerBuilder()
.ima(window.google.ima)
.imaDaiManager(daiMetadata.streamManager)
.contentPlayer(contentPlayer)
.contentVideoElement(videoElement)
.contentContainerElement(videoWrapper)
.adFrequencyControl(adFrequencyControl)
.build();
Use AFC with MediaTailor
For MediaTailor, gate preroll session creation in your app before you initialize the MediaTailor session and create the ad player. When AFC blocks the opportunity, skip session initialization and continue with content playback.
const mediatailorSession = createMediatailorSession();
const mediatailorMetadata = await mediatailorSession.initialize(
mediatailorInitializationData,
palConfiguration,
);
const contentPlayer = playerBuilder
.mediaElement(videoElement)
.mediaUrl(mediatailorMetadata.manifestUrl)
.mediaType(MediaType.HLS)
.build();
const adsPlayer = mediatailorSession.createMediatailorPlayer(
contentPlayer,
mediatailorMetadata,
adPlaybackPolicy,
logger,
videoElement,
adFrequencyControl,
);
Evaluate an ad opportunity in your app
Call getAdfrequencyController().evaluateOpportunity() to ask AFC whether an ad
opportunity is currently allowed, for example before you request an ad session.
It returns true if the opportunity is allowed or false if AFC suppresses it.
When AFC is disabled, it returns true.
Use the result for whatever your app needs. For example, you can skip a preroll request, tag the session, or write a log entry.
if (getAdfrequencyController().evaluateOpportunity()) {
// The opportunity is allowed. For example, request the preroll.
}
Ad Suppression Event
When AFC blocks an ad opportunity, the player emits the adskip_afc_policy event. Applications can use this event to identify when an ad is skipped due to AFC policy and report it to analytics for tracking and downstream analysis.
adsPlayer.subscribe('adskip_afc_policy', (event) => {
// Report this event to analytics for tracking.
});
Enable logs in AFC
Application / Ad players consuming AFC can able to enable log by configuring logger levels.
getAdfrequencyController().evaluateOpportunity().setLoggerLevel(LoggerLevel.DEBUG)
AFC at a glance
The following example uses the default settings:
- A viewer starts a video. AFC allows the first ad opportunity, so the preroll plays.
- The viewer watches at least 66% of the ad break. AFC counts this as a qualified ad impression.
- For the next 3 minutes of content, AFC skips any scheduled ad break. The viewer watches without interruption.
- After the viewer has watched 3 minutes of content, the next ad break plays.
If the viewer leaves or skips an ad break before reaching 66%, AFC doesn't count it as seen. The next ad break plays as scheduled.
How AFC applies to each playback type
AFC remembers what a viewer has watched, and it keeps that memory when the viewer moves from one video to the next. For example, a viewer who finishes an ad break at the end of one episode doesn't get another ad right at the start of the next episode. AFC does this by keeping a single, shared record of ad exposure and content watched across playback sessions.
How AFC uses that record depends on the playback type:
| Playback type | What AFC does |
|---|---|
| VOD | Tracks viewing and decides. AFC allows or suppresses each ad break based on the viewer's history. |
| LIVE | Tracks viewing only. Ads are stitched into the stream dynamically, so AFC doesn't suppress them. |
The tracked data from all types feeds the same record. For example, an ad break that plays through LIVE still counts toward the viewer's exposure. A later VOD uses that record to decide whether to play ad or not.