AMP player

Nielsen DCR

Ease of integration and Nielsen certification is this module’s goal, as well as reducing boilerplate code to achieve the integration.


Just import the AmpNielsenDCR.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 AmpNielsen

Then, let’s add the related variables in our UIViewController:

var ampPlayer: AmpPlayer!
var ampNielsen: AmpNielsenManager!

And it’s time to instantiate them now, in your viewDidLoad function:

// Instantiate player

self.ampPlayer = AmpPlayer(parentView: self.view)
self.ampPlayer.autoplay = true

// Register yourself as an observer if required

// Instantiate the Nielsen Manager
self.ampNielsen = AmpNielsenManager(player: self.ampPlayer!, appInfo: appInfo)

// Afterwards, let's ask our `ampPlayer` to handle our stream YOUR_VIDEO_URL)

If you want to show a WebView with the Nielsen’s opt-out URL, you can add the following code:

@IBAction func showOptOutWebsite(sender: AnyObject) {
   // Assuming we have a view controller, with an identifier of `webView`, and named `WebViewController`
   let webView = self.storyboard?.instantiateViewControllerWithIdentifier("webView") as! WebViewController

   // We assign the view controller's properties
   webView.url = self.ampNielsen.getOptOutURL()
   webView.nielsen = self.ampNielsen 

   // Pause the player while we present the view controller

   // Present the view controller,
   self.presentViewController(webView, animated: true, completion: nil)

Now, for reference, see an example of a WebViewController:

import UIKit
import AmpNielsenDCR

public class WebViewController: UIViewController, UIWebViewDelegate {

    public var url:String?
    public var nielsen:AmpNielsenDCRManager?

    @IBOutlet weak var webView: UIWebView!

    override public func viewDidLoad() {
        let nURL = NSURL(string: url!)
        let request = NSURLRequest(URL: nURL!)

        self.webView.scalesPageToFit = true
        self.webView.delegate = self

    public override func viewDidAppear(animated: Bool) { =

    @IBAction func close(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)

// MARK: Web View Delegate

    public func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        let command:String = "\(request.URL!)"

        if command == kNielsenWebClose {
            self.dismissViewControllerAnimated(true, completion: nil)
            return false

        if let nielsenDCR = self.nielsen {
            return !nielsenDCR.userOptOut(command)
        }else {
            return false

And that’s basically it, with just those few steps, you have a working integration between AMP and Nielsen DCR.