1

I have an iOS app in which I play YouTube videos using the YouTube iframe API.

Inside YouTube, when looking in the analytics panel->Traffic sources I'm seeing the hits classified as "Other YouTube features"->"Unknown"

Is there a parameter I can pass that would identify the hits as coming from my app?

I can see that most apps playing YouTube videos are registered under "External" and then the name of the app (E.g. WhatsApp, embedly.com etc.)

I'm using the UIWebView to load an HTML that's using the YouTube iframe API like this:

<iframe id='playerId' type='text/html' width='100%%' height=100%%' src='https://www.youtube.com/embed/<videoId>enablejsapi=1&rel=0&playsinline=0&autoplay=1' frameborder='0'>
JAL
  • 41,701
  • 23
  • 172
  • 300
Boaz Saragossi
  • 958
  • 10
  • 32

1 Answers1

0

It's possible the the analytics are using the origin parameter of the iFrame API.

You might be able to get analytics information by adding &origin=http://com.example.yourApp or some other valid URL to your player parameters.

Autoplay seems to work for me like so:

<iframe id='playerId' type='text/html' width='100%%' height=100%%' src='https://www.youtube.com/embed/jCHE0Tjw6MA?enablejsapi=1&rel=0&playsinline=0&autoplay=1&origin=http://com.example.yourApp' frameborder='0'>

Swift implementation:

let webView = UIWebView(...)
webView.allowsInlineMediaPlayback = true
webView.mediaPlaybackRequiresUserAction = false

let videoID = "zN-GGeNPQEg"

let embededHTML = "<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){a.target.playVideo();}</script><iframe id='playerId' type='text/html' width='\(self.view.frame.size.width)' height='\(self.view.frame.size.height)' src='http://www.youtube.com/embed/\(videoID)?enablejsapi=1&rel=0&playsinline=1&autoplay=1&origin='http://com.example.myApp/'' frameborder='0'></body></html>"

webView.loadHTMLString(embededHTML, baseURL: nil)
JAL
  • 41,701
  • 23
  • 172
  • 300
  • Do you have an idea why the origin param cancels the autoplay ? I'm passing enablejsapi=1&rel=0&playsinline=0&autoplay=1 and it autoplays but when im adding the origin it stops autoplaying. – Boaz Saragossi Feb 10 '16 at 08:35
  • @BoazSaragossi edited my answer to include an iFrame with `origin` that autoplays for me. – JAL Feb 10 '16 at 14:59
  • @BoazSaragossi added an example in Swift where adding `origin` doesn't break autoplay in a `UIWebView`. – JAL Feb 10 '16 at 16:51
  • @BoazSaragossi did my update help you? Do you have any other questions? – JAL Feb 11 '16 at 04:09
  • Yes it works now! the ' ' around the origin value is what i forgot. Thank you! – Boaz Saragossi Feb 11 '16 at 07:27