Package com.iab.omid.library.adsession
Class JavaScriptSessionService
java.lang.Object
com.iab.omid.library.adsession.JavaScriptSessionService
Service supporting ad sessions managed (started/finished) via JavaScript Session Client APIs
by providing native-layer measurement signals.
If the JS Session Client is running in a web view, an instance of this service must be
initialized with the web view before starting or finishing ad sessions using JS APIs.
Only one instance of this service may be initialized at a time for a given web view; to reuse a
web view the current instance must be torn down (see `tearDown`).
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFriendlyObstruction
(View friendlyObstructionView, FriendlyObstructionPurpose purpose, String detailedReason) Add a friendly obstruction which should then be excluded from all ad session viewability calculations.static JavaScriptSessionService
Create and initialize an instance of the JavaScriptSessionService.void
Remove all registered friendly obstructions from any currently running and future ad sessions measured by this instance of JavaScriptSessionService.void
removeFriendlyObstruction
(View friendlyObstructionView) Remove a registered friendly obstruction from any currently running and future ad sessions measured by this instance of JavaScriptSessionService.void
setAdView
(View adView) Sets the native view that contains the ad and is used for viewability tracking.void
tearDown
(JavaScriptSessionService.TearDownHandler tearDownHandler) Tear down this instance of the service.
-
Method Details
-
create
public static JavaScriptSessionService create(Partner partner, WebView webView, boolean isHtmlAdView) Create and initialize an instance of the JavaScriptSessionService. Once this method is called, ad sessions can be started and finished from the JS Session Client in the web view.- Parameters:
partner
- Details of the integration partner responsible for ad sessions.webView
- The web view responsible for starting/finishing ad sessions via the JS Session Client.isHtmlAdView
- Whether the ad is rendered in HTML inside of the provided web view.- Throws:
UnsupportedOperationException
- if WebViewFeature.WEB_MESSAGE_LISTENER not supported; this should only happen for Android versions below 5.0 and can be handled by measuring the ad a different way.IllegalArgumentException
- if the supplied partner or web view is null.IllegalStateException
- if this method is called before the OM SDK has been activated.
-
tearDown
Tear down this instance of the service. Calling this method will cause OM SDK to begin a teardown process including finishing all currently active ad sessions measured by this service instance and tearing down communication with the OM SDK's JavaScript layer running in the web view. This may require up to one second, for example in order to allow verification scripts time to process the `sessionFinish` event. Once this process has completed, the web view may be torn down or reused for another instance of the service without any adverse effects. If there is no need to tear down or reuse the web view, this method is not required.- Parameters:
tearDownHandler
- Object whose onTearDown method is invoked by OM SDK after the teardown process has completed, or one second, whichever comes sooner.
-
setAdView
public void setAdView(View adView) Sets the native view that contains the ad and is used for viewability tracking. If `isHtmlAdView` was passed as true in the constructor, this method is not required since the ad view will be set to the web view by default.- Parameters:
adView
- The native view.
-
addFriendlyObstruction
public void addFriendlyObstruction(View friendlyObstructionView, FriendlyObstructionPurpose purpose, String detailedReason) Add a friendly obstruction which should then be excluded from all ad session viewability calculations. While this instance of JavaScriptSessionService is running, this friendly obstruction will be added to each ad session started by the integrator via the JS Session Client until the obstruction is removed by calling `removeFriendlyObstruction` or `removeAllFriendlyObstructions`.- Parameters:
friendlyObstructionView
- to be excluded from all ad session viewability calculations.purpose
- why this obstruction was necessarydetailedReason
- an explanation for why this obstruction is part of the ad experience if not already obvious from theFriendlyObstructionPurpose
selected. Must be 50 characters or less and only contain characters `A-z`,`0-9` or space.- Throws:
IllegalArgumentException
- if the supplied friendly obstruction is null.IllegalArgumentException
- if the detailedReason is over 50 characters or contains a character that is not in `A-z`,`0-9` or a space.
-
removeFriendlyObstruction
public void removeFriendlyObstruction(View friendlyObstructionView) Remove a registered friendly obstruction from any currently running and future ad sessions measured by this instance of JavaScriptSessionService.- Parameters:
friendlyObstructionView
- to be removed from the list of registered friendly obstructions.- Throws:
IllegalArgumentException
- if the supplied friendly obstruction is null.
-
removeAllFriendlyObstructions
public void removeAllFriendlyObstructions()Remove all registered friendly obstructions from any currently running and future ad sessions measured by this instance of JavaScriptSessionService.
-