Getting started with OptiView Ads on React Native
This guide will get you started with OptiView Ads in your THEOplayer React Native SDK: configure the license, update dependencies and set the source description.
Prerequisites
-
You need to have a THEOplayer license which is compatible with OptiView Ads. This can be done through the player portal.
-
You need a correctly deployed OptiView Ads signaling service.
-
Enable the OptiView Ads integration based on the target platform:
- Android & Android TV
- iOS & tvOS
- Web
The Android SDK is modular-based, so to enable OptiView Ads, simply include the extension by setting this flag in your gradle.properties:
# Enable THEOplayer Extensions (default: disabled)
THEOplayer_extensionTHEOads = trueTo enable OptiView Ads you can add the "THEOADS" feature flag to react-native-theoplayer.json (or theoplayer-config.json)
Add a dependency to a OptiView ads-enabled THEOplayer package:
$ npm i theoplayer@npm:@theoplayer/theoadsIn addition, since OptiView Ads integrates with Google DAI Pod Serving, it is required to load the Google DAI script on your page:
<script src="https://imasdk.googleapis.com/js/sdkloader/ima3_dai.js"></script>
Integration
This guide assumes you know how to set up React Native with THEOplayer. For more information regarding this check out the THEOplayer getting started.
Player configuration
To make use of the OptiView Ads integration, only a specific source needs to be set:
player.source = {
sources: {
src: 'PATH-TO-SIGNALING-SERVER/hls/MANIFEST-URI',
type: 'application/x-mpegurl',
hlsDateRange: true,
},
ads: [
{
integration: 'theoads',
networkCode: 'NETWORK-CODE',
customAssetKey: 'CUSTOM-ASSET-KEY',
},
],
};
- Notice that the
srcis different as usual. For OptiView Ads, a signaling server needs to be set up which acts as a proxy to parse the given manifest and insert the ad interstitials. More information can be found here. - The
hlsDateRangeflag needs to be set totrueas the ad markers are done usingEXT-X-DATERANGEtags. - The
adsobject needs to have its integration set totheoads. Furthermore, thenetworkCodeandcustomAssetKeyneeds to be set according to your configured Google account.