title: How to track events on mediaelement.js with Google Analytics
body: <p>I'm using mediaelement.js for my audio player and I've been trying to track events in Analytics for weeks now to no avail. I know it comes with a plugin for Analytics but I haven't been able to get it to work.</p>
  
  <p>Here's my html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link type="text/css" href="http://icd10monitor.com/js/mediaelementplayer.min.css"     rel="stylesheet" /&gt;
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://icd10monitor.com/js/mediaelement-and-player.min.js"&gt;&lt;/script&gt;
  &lt;style type="text/css"&gt;
  #article-index,.pagenavcounter {display:none;}
  &lt;/style&gt;
  &lt;script&gt;
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
      ga('create', 'UA-32808206-2', 'icd10monitor.com');
      ga('send', 'pageview');
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;audio width="300" height="32" src="podcasts-ttt/TTT-03-25-14.mp3" type="audio/mp3"  controls="controls"&gt;&lt;/audio&gt;
      &lt;script&gt;
          $('audio').mediaelementplayer({
              features:   ['playpause','progress','current','duration','tracks','volume','fullscreen','googleanalytics']
          });
      &lt;/script&gt;
      &lt;script type="text/javascript" src="mep-feature-googleanalytics.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the JavaScript for the Analytics plugin</p>
  
  <pre><code>(function($) {
  
  $.extend(mejs.MepDefaults, {
  googleAnalyticsTitle: 'Podcast',
  googleAnalyticsCategory: 'Audio',
  googleAnalyticsEventPlay: 'Play',
  googleAnalyticsEventPause: 'Pause',
  googleAnalyticsEventEnded: 'Ended',
  googleAnalyticsEventTime: 'Time'
  });
  
  
  $.extend(MediaElementPlayer.prototype, {
  buildgoogleanalytics: function(player, controls, layers, media) {
  
      media.addEventListener('play', function() {
          if (typeof _gaq != 'undefined') {
              _gaq.push(['_trackEvent', 
                  player.options.googleAnalyticsCategory, 
                  player.options.googleAnalyticsEventPlay, 
                  (player.options.googleAnalyticsTitle === '') ?   player.currentSrc : player.options.googleAnalyticsTitle
              ]);
          }
      }, false);
  
      media.addEventListener('pause', function() {
          if (typeof _gaq != 'undefined') {
              _gaq.push(['_trackEvent', 
                  player.options.googleAnalyticsCategory, 
                  player.options.googleAnalyticsEventPause, 
                  (player.options.googleAnalyticsTitle === '') ? player.currentSrc : player.options.googleAnalyticsTitle
              ]);
          }
      }, false);  
  
      media.addEventListener('ended', function() {
          if (typeof _gaq != 'undefined') {
              _gaq.push(['_trackEvent', 
                  player.options.googleAnalyticsCategory, 
                  player.options.googleAnalyticsEventEnded, 
                  (player.options.googleAnalyticsTitle === '') ? player.currentSrc : player.options.googleAnalyticsTitle
              ]);
          }
      }, false);
  
  
      media.addEventListener('timeupdate', function() {
          if (typeof _gaq != 'undefined') {
              _gaq.push(['_trackEvent', 
                  player.options.googleAnalyticsCategory, 
                  player.options.googleAnalyticsEventEnded, 
                  player.options.googleAnalyticsTime,
                  (player.options.googleAnalyticsTitle === '') ? player.currentSrc : player.options.googleAnalyticsTitle,
                  player.currentTime
              ]);
          }
      }, true);
  
  }
  });
  
  })(mejs.$);
  </code></pre>
  
  <p>Any ideas what I might be doing wrong?</p>