Send feedback
Class AdsLoader
Stay organized with collections
Save and categorize content based on your preferences.
outlined_flag
AdsLoader allows requesting ads from ad servers, requiring registration for the AdsManagerLoadedEvent.
It includes methods for managing events like addEventListener
and removeEventListener
, allowing the addition and removal of event listeners.
The contentComplete
method signals the SDK that the content has finished, enabling the playback of post-roll ads.
AdsLoader
can clean up its internal state with the destroy
method and provide access to SDK version and settings with the getVersion
and getSettings
methods respectively.
requestAds
is used to request ads from a server, and it requires an AdsRequest
instance along with an optional user context object.
Note: This reference page follows TypeScript documentation structure. If you have
suggestions for or see issues with the reference documentation, open a thread with your
feedback on the IMA technical forum .
AdsLoader allows clients to request ads from ad servers. To do so, users must register for
the AdsManagerLoadedEvent event and then request ads.
Methods
addEventListener
addEventListener ( type : ADS_MANAGER_LOADED , listener : ( ( event : AdsManagerLoadedEvent ) => void ) ,
optCapture ?: boolean ,
optHandlerScope ?: object ) : void
Adds a listener for ads manager loaded events.
Parameters
type :
ADS_MANAGER_LOADED
The type of event to listen for.
listener : ( ( event : AdsManagerLoadedEvent ) => void )
A function called each time an event of this type occurs.
Optional
optCapture : boolean
Deprecated and a no-op; retained for backward compatibility.
Optional
optHandlerScope : object
Deprecated: Listener scope object. Use arrow functions or bind listener instead.
addEventListener ( type : google . ima . AdEvent . Type , listener : ( ( event : AdEvent ) => void ) ,
optCapture ?: boolean ,
optHandlerScope ?: object ) : void
Adds a listener for ad events.
Parameters
type :
google . ima . AdEvent . Type
The type of event to listen for.
listener : ( ( event : AdEvent ) => void )
A function called each time an event of this type occurs.
Optional
optCapture : boolean
Deprecated and a no-op; retained for backward compatibility.
Optional
optHandlerScope : object
Deprecated: Listener scope object. Use arrow functions or bind listener instead.
addEventListener ( type : AD_ERROR , listener : ( ( event : AdErrorEvent ) => void ) ,
optCapture ?: boolean ,
optHandlerScope ?: object ) : void
Adds a listener for ad error events.
Parameters
type :
AD_ERROR
The type of event to listen for.
listener : ( ( event : AdErrorEvent ) => void )
A function called each time an event of this type occurs.
Optional
optCapture : boolean
Deprecated and a no-op; retained for backward compatibility.
Optional
optHandlerScope : object
Deprecated: Listener scope object. Use arrow functions or bind listener instead.
contentComplete
contentComplete ( ) : void
Signals to the SDK that the content is finished. This will allow the SDK to play
post-roll ads, if any are loaded through ad rules.
destroy
destroy ( ) : void
Cleans up the internal state.
getSettings
getSettings ( ) : ImaSdkSettings
Returns the IMA SDK settings instance. To change the settings, just call the methods
on the instance. The changes will apply for all the ad requests made with this ads
loader.
getVersion
getVersion ( ) : string
Returns the version of the current SDK.
removeEventListener
removeEventListener ( type : ADS_MANAGER_LOADED , listener : ( ( event : AdsManagerLoadedEvent ) => void ) ,
optCapture ?: boolean ,
optHandlerScope ?: object ) : void
Removes a listener for ads manager loaded events. The listener must be equal by
reference to the one previously passed to
addEventListener
.
Parameters
type :
ADS_MANAGER_LOADED
The type of event for which to remove the listener.
listener : ( ( event : AdsManagerLoadedEvent ) => void )
The function to remove as a listener.
Optional
optCapture : boolean
Deprecated and a no-op; retained for backward compatibility.
Optional
optHandlerScope : object
Deprecated: Listener scope object. Use arrow functions or bind listener instead.
removeEventListener ( type : google . ima . AdEvent . Type , listener : ( ( event : AdEvent ) => void ) ,
optCapture ?: boolean ,
optHandlerScope ?: object ) : void
Removes a listener for ad events. The listener must be equal by reference to the one
previously passed to
addEventListener
.
Parameters
type :
google . ima . AdEvent . Type
The type of event for which to remove the listener.
listener : ( ( event : AdEvent ) => void )
The function to remove as a listener.
Optional
optCapture : boolean
Deprecated and a no-op; retained for backward compatibility.
Optional
optHandlerScope : object
Deprecated: Listener scope object. Use arrow functions or bind listener instead.
removeEventListener ( type : AD_ERROR , listener : ( ( event : AdErrorEvent ) => void ) ,
optCapture ?: boolean ,
optHandlerScope ?: object ) : void
Removes a listener for ad error events. The listener function must be equal by
reference to the one previously passed to
addEventListener
.
Parameters
type :
AD_ERROR
The type of event for which to remove the listener.
listener : ( ( event : AdErrorEvent ) => void )
The function to remove as a listener.
Optional
optCapture : boolean
Deprecated and a no-op; retained for backward compatibility.
Optional
optHandlerScope : object
Deprecated: Listener scope object. Use arrow functions or bind listener instead.
requestAds
requestAds ( adsRequest : AdsRequest , userRequestContext ?: object ) : void
Request ads from a server.
Parameters
adsRequest :
AdsRequest
AdsRequest instance containing data for the ads request.
Optional
userRequestContext :
object
User-provided object that is associated with the ads request. It can be
retrieved when the ads are loaded.
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-26 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-26 UTC."],[],[]]