Nielsen DCR Module for AMP iOS

Document created by Herberth Alvarado Employee on May 15, 2017Last modified by Herberth Alvarado Employee on May 15, 2017
Version 2Show Document
  • View in full screen mode

Maintainers: David Cortes Saenz & Miguel Lopez Valenciano

 

 

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

 

Installation

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 AmpNielsenDCR

 

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

var ampPlayer: AmpPlayer!
var ampNielsen:AmpNielsenDCRManager!

 

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

// Instantiate player

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

 

// Register yourself as an observer if required
self.ampPlayer.registerObserver(self)

 

// Instantiate the Nielsen Manager
self.ampNielsen = AmpNielsenDCRManager(player: self.ampPlayer)

 

// Afterwards, let's ask our `ampPlayer` to handle our stream
self.ampPlayer.handleUrl(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
   self.ampPlayer.pause()

 

   // 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
      self.webView.loadRequest(request)
   }

 

   public override func viewDidAppear(animated: Bool) {
      self.webView.center = self.view.center
   }

 

   @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.

Attachments

    Outcomes