Google IMA Module for AMP iOS
This module’s goal is to ease the integration of Google Interactive Media Ads and the Akamai AMP Player for iOS. With just some simple steps a few steps we can achieve this integration, let’s see how.
Installation
Just import the AmpIMA.framework in your project. For more information check out the AmpCore’s documentation.
*Note: Make sure to add the frameworks as Embedded Binaries
or you’ll get an error about a missing image. *
How to Use
Let’s first import the required frameworks:
import AmpCore
import AmpIMA
Then, let’s add the related variables in our UIViewController
:
var ampPlayer: AmpPlayer!
var imaManager: AmpIMAManager!
And it’s time to instantiate them now, in your viewDidLoad
function:
// Instantiate player
self.ampPlayer = AmpPlayer(parentView: self.view)
// Register yourself as an observer if required
self.ampPlayer.registerObserver(self)
self.ampPlayer.setLicense(license)
self.ampPlayer.handleUrl(url)
// Instantiate the IMA Manager after our player is created
self.imaManager = AmpIMAManager(ampPlayer: self.ampPlayer, videoView: self.ampPlayer.PlayerView!)
To request ads, we need to be notified of an event from AmpPlayer
, so let’s add an extension with the PlayerEventObserver
protocol below our class definition:
extension ViewController : PlayerEventObserver {
func onAVPlayerCreation(_ ampPlayer: AmpPlayer) {
self.imaManager.requestAds(adsUrl: imaPreMidPost)
}
}
We listen to the onAVPlayerCreation
event, which is called when then AVPlayer is created internally, this means it is now safe to request ads and play them.
And that’s basically it, with just those few steps, you have a working integration between AMP and Google IMA.
Need help?
If you need help trying to integrate the player on your project, or you want to report issues or problems you can send a email to amp-sdk-support@akamai.com