Register friendly obstructions (iOS)
Register custom controls as friendly obstructions when using OMID with Google IMA or IMA DAI ads in your iOS app.
If you use the IAB Open Measurement Interface Definition (OMID) and run Google IMA ads or Google IMA DAI ads, all custom video controls that overlay the media element must be registered as friendly obstructions. Friendly obstructions are views -- such as video controls -- that are essential to the user’s experience but do not impact viewability.
The JWAdvertisingConfig class enables you to register fully transparent overlays or small buttons. Once registered, your custom video controls are excluded from the ad viewability measurements that the Open Measurement SDK calculates.
The following table lists the views that can and cannot be registered.
| Permitted | Not Permitted |
|---|---|
| • Transparent overlay used to capture user taps • Transient buttons such as the following: ◦ Pause ◦ Play ◦ Fullscreen ◦ Cast/AirPlay ◦ Collapse ◦ Progress/Seek ◦ Other playback-related actions | • Watermarks • Pop-ups • Dialogs • Non-transient buttons • Other obscuring views |
Register a custom control
Use the following steps and code sample to register a custom video control as a friendly ad obstruction:
- Create a
JWFriendlyObstructionobject, passing a reference to the view that you want to mark as a friendly obstruction. - Use the created
JWFriendlyObstructionobject to create aJWFriendlyObstructionsContainer. - Set the friendly obstruction container using
friendlyObstructionsContainer(_:)on the builder for your ad client:JWImaAdvertisingConfigBuilderfor Google IMA orJWImaDaiAdvertisingConfigBuilderfor IMA DAI. - Call
build()on the advertising configuration builder.
// Have a reference to the view you want to register as a friendly obstruction.
@IBOutlet weak var fullScreenButton: UIButton!
// Create a JWFriendlyObstruction object using the view you
// want to register.
let friendlyObstruction = JWFriendlyObstruction(view: fullScreenButton, purpose: .mediaControls)
// Create a JWFriendlyObstructionsContainer using the
// created JWFriendlyObstruction
let friendlyObstructionContainer = JWFriendlyObstructionsContainer(obstructions: [friendlyObstruction])
// Create a JWImaAdvertisingConfigBuilder and set the JWFriendlyObstructionsContainer.
let builder = JWImaAdvertisingConfigBuilder()
.tag(URL(string: <#Tag URL#>)!)
.friendlyObstructionsContainer(friendlyObstructionContainer)
// Create a JWAdvertisingConfig using the builder.
do {
let config = try builder.build()
// Use the config to create a JWPlayerConfiguration
} catch is JWError {
// Handle the error
}// Have a reference to the view you want to register as a friendly
// obstruction.
UIButton *fullScreenButton = [[UIButton alloc] initWithFrame:CGRectZero];
// Create a JWFriendlyObstruction object using the view you
// want to register.
JWFriendlyObstruction *obstruction = [[JWFriendlyObstruction alloc] initWithView:fullScreenButton purpose:JWFriendlyObstructionPurposeMediaControls reason:@"Reason"];
// Create a JWFriendlyObstructionsContainer using the
// created JWFriendlyObstruction
JWFriendlyObstructionsContainer *container = [[JWFriendlyObstructionsContainer alloc] initWithObstructions:@[obstruction]];
// Create a JWImaAdvertisingConfigBuilder and set the JWFriendlyObstructionsContainer.
NSError *error = nil;
JWImaAdvertisingConfigBuilder *builder = [[JWImaAdvertisingConfigBuilder alloc] init];
[builder tag:[NSURL URLWithString:@"http://testurl.com"]];
[builder friendlyObstructionsContainer:container];
JWAdvertisingConfig *adConfig = [builder buildAndReturnError:&error];Updated 2 days ago
