javascript - How to track events on mediaelement.js using their plugin and universal Google Analytics -


i trying implement google analytics event tracking on mediaelement.js audio player. have succesfully managed track clicks on links on page, love track how many people listen audio (without offering download link , no audio player).

i believe have done right, apparantly have not, because it's not working. no events show in ga report. cannot find googling. found similar question on site (how track events on mediaelement.js google analytics), didn't me.

can see mistakes are? maybe i'm doing fundamentally wrong here.

here relevant html

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="xrefthemes/theme1/src/jquery.js"></script> <script type="text/javascript" src="xrefthemes/theme1/src/mediaelement-and-player.min.js"></script> <script type="text/javascript" src="xrefthemes/theme1/src/mep-feature-googleanalytics.js"></script> <link rel="stylesheet" href="xrefthemes/theme1/src/mediaelementplayer.css" /> <title> doknr 1383519 </title> </head> <body> <script>  (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-37025154-3', 'auto', {'name': 'mv', 'allowlinker': true});   ga('mv.require', 'linker');   ga('mv.linker:autolink', ['musikverket.se', 'musikverk.se', 'statensmusikverk.se', 'visarkiv.se', 'muslib.se', 'elektronmusikstudion.se', 'smus.se', 'dramawebben.se'] );   ga('mv.require', 'displayfeatures');   ga('mv.send', 'pageview');  </script>      <table>       <tr>         <td>anmärkningar</td>         <td>           <div><audio controls="controls" type="audio/mpeg" style="width: 500px" src="http://xref.musikverk.se/visarkivetserver/getfile.aspx?file=audio/svaba0001-0002.mp3"></audio><br><audio controls="controls" type="audio/mpeg" style="width: 500px" src="http://xref.musikverk.se/visarkivetserver/getfile.aspx?file=audio/svaba0003-0004.mp3"></audio></div>         </td>       </tr>     </table> <script>$('video,audio').mediaelementplayer();</script> </body> </html> 

and here js code (that found here: https://github.com/johndyer/mediaelement/blob/9d4ceefc75b9936cd32a1c17be761809bbbc0c16/src/js/mep-feature-universalgoogleanalytics.js) (thanks nyuen pointing out had missed mv before send! corrected.)

/* * analytics.js google analytics plugin * requires jquery */  (function($) {  $.extend(mejs.mepdefaults, {     googleanalyticstitle: 'test',     googleanalyticscategory: 'mediafiles',     googleanalyticseventplay: 'play',     googleanalyticseventpause: 'pause',     googleanalyticseventended: 'ended',     googleanalyticseventtime: 'time' });   $.extend(mediaelementplayer.prototype, {     builduniversalgoogleanalytics: function(player, controls, layers, media) {          media.addeventlistener('play', function() {             if (typeof ga != 'undefined') {                 ga('mv.send', 'event',                     player.options.googleanalyticscategory,                     player.options.googleanalyticseventplay,                     (player.options.googleanalyticstitle === '') ? player.media.currentsrc : player.options.googleanalyticstitle                 );             }         }, false);          media.addeventlistener('pause', function() {             if (typeof ga != 'undefined') {                 ga('mv.send', 'event',                     player.options.googleanalyticscategory,                     player.options.googleanalyticseventpause,                     (player.options.googleanalyticstitle === '') ? player.media.currentsrc : player.options.googleanalyticstitle                 );             }         }, false);          media.addeventlistener('ended', function() {             if (typeof ga != 'undefined') {                 ga('mv.send', 'event',                     player.options.googleanalyticscategory,                     player.options.googleanalyticseventended,                     (player.options.googleanalyticstitle === '') ? player.media.currentsrc : player.options.googleanalyticstitle                 );             }         }, false);          /*         media.addeventlistener('timeupdate', function() {             if (typeof ga != 'undefined') {                 ga('mv.send', 'event',                     player.options.googleanalyticscategory,                     player.options.googleanalyticseventended,                     player.options.googleanalyticstime,                     (player.options.googleanalyticstitle === '') ? player.media.currentsrc : player.options.googleanalyticstitle,                     player.currenttime                 );             }         }, true);         */     } });  })(mejs.$); 

when created tracking object, gave name 'mv', when send events, you'll have use there same name

ga('mv.send', 'event', ...) 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -