Never done it myself but for one i believe you can have views with filters in google Analytics. With the filters you should be able to filter on environment url:
https://support.google.com/analytics/answer/1034823?hl=en
You can modify the widget to read the uacode from the db to make it runtime programmable, the relevant part is
...
_setupGlobalTrackerId: function () {
...
//window.mxGoogleAnalytics = {trackerId: this.uaTrackCode}; ->
window.mxGoogleAnalytics = {trackerId: this._contextObj.get(this.attr_uacode)};
},
...