title: How to track multiple youtube videos in google analytics
body: <p>I've read carefully through all similar questions but couldn't find the answer.
  So I'll be really thankful for help:)</p>
  
  <p>There are two embed YouTube videos on my site (number of them will increase in future) and I need to track starts/plays, pauses and watching till the end for each of them. It would be great to track watching progress (25%, 50%, 75%) too, but my JS skills only let me implement the following script (which works only for one video)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> // This code loads the IFrame Player API code asynchronously
   var tag = document.createElement('script');
   tag.src = "http://www.youtube.com/iframe_api";
   var firstScriptTag = document.getElementsByTagName('script')[0];
   firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  
  
   // This code is called by the YouTube API to create the player object
   function onYouTubeIframeAPIReady(event) {
       player = new YT.Player('player', {
         events: {
           'onReady': onPlayerReady,
           'onStateChange': onPlayerStateChange
         }
       });
     }
     // This code is called by the YouTube API to create the player object
  
   function onYouTubeIframeAPIReady(event) {
     player2 = new YT.Player('player2', {
       events: {
         'onReady': onPlayerReady,
         'onStateChange': onPlayerStateChange
       }
     });
   }
  
   var pauseFlag = false;
  
   function onPlayerReady(event) {
     // do nothing, no tracking needed
   }
  
   function onPlayerStateChange(event) {
     // track when user clicks to Play
     if (event.data == YT.PlayerState.PLAYING) {
       ga('send', 'event', 'Video', 'Start', event.target.getVideoUrl());
       pauseFlag = true;
     }
     // track when user clicks to Pause
     if (event.data == YT.PlayerState.PAUSED &amp;&amp; pauseFlag) {
       ga('send', 'event', 'Video', 'Pause', event.target.getVideoUrl());
       pauseFlag = false;
     }
     // track when video ends
     if (event.data == YT.PlayerState.ENDED) {
       ga('send', 'event', 'Video', 'Complete', event.target.getVideoUrl());
     }
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And these are video iframes:</p>
  
  <p>Player</p>
  
  <pre><code>&lt;iframe id="player" width="414" height="233" class="bnr-01" src="https://www.youtube.com/embed/VideoID?enablejsapi=1&amp;origin=http://my.site.com" frameborder="0" allowfullscreen="" name="player"&gt; &lt;/iframe&gt;
  </code></pre>
  
  <p>Player 2</p>
  
  <pre><code>&lt;iframe id="player2" width="414" height="233" class="bnr-02" src="https://www.youtube.com/embed/VideoID?enablejsapi=1&amp;origin=http://my.site.com" frameborder="0" allowfullscreen="" name="player2"&gt; &lt;/iframe&gt;
  </code></pre>
  
  <p>Events are successfully sent only for Player2.
  What may be the problem?
  We use new google analytics (universal)</p>
  
  <p>Thank you in advance!</p>