Logging errors in google analytics
ga('send', 'event', 'jserror', 'click', msg, {'transport': 'beacon'});


Yup, that's how I would do events in Google Analytics. However, the API also provides a special call for errors. It's found under Exception Tracking.

ga('send', 'exception', {
  'exDescription': msg,
  'exFatal': false
});


Another is that you're wrapping an addEventListener call into a try-catch. Not sure why this is required. The callback is fired asynchronously, thus the try-catch will make no sense (unless somehow, window or addEventListener doesn't exist)

if(typeof ga=="function") {


The snippet (and not the script that it loads) creates the global ga function for you, which means the global ga should be present when the snippet is present. It's seen in the snippet as this portion:

i[r]=i[r]||function(){...}


But I see that it's possible that you're not loading it when debugging. So this can be ignored I suppose.

Lastly, rename e to error. This makes the variable tell what it is more.