angular.module('Aggie')

.controller('ApplicationController', [
  '$scope',
  'FlashService',
  'Settings',
  function($scope, flash, settings) {
    $scope.flash = flash;

    // Set up Matomo analytics.
    settings.get('matomo', function success(data) {
      if (!data.matomo) {
        console.warn("Matomo is missing from Aggie's configuration.");
        return;
      }
      if (!data.matomo.enabled) {
        console.log("Matomo is disabled.");
        return;
      }

      // Pageview Tracking
      var _paq = window._paq = window._paq || [];
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      _paq.push(["setCookieDomain", data.matomo.cookie_domain]);
      _paq.push(['enableLinkTracking']);
      (function() {
        var u='https://' + data.matomo.dashboard_name + '.matomo.cloud/';
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', data.matomo.site_id]);
        var d=document, 
          g=d.createElement('script'), 
          s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; 
        g.async=true; 
        g.src='//cdn.matomo.cloud/' + data.matomo.dashboard_name + '.matomo.cloud/matomo.js'; 
        s.parentNode.insertBefore(g,s);
      })();

      // Tag Management
      var _mtm = window._mtm = window._mtm || [];
      _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
      var d=document, 
        g=d.createElement('script'), 
        s=d.getElementsByTagName('script')[0];
      g.type='text/javascript'; 
      g.async=true; 
      g.src='https://cdn.matomo.cloud/' + data.matomo.dashboard_name +'.matomo.cloud/container_' + data.matomo.container_id  + '.js'; 
      s.parentNode.insertBefore(g,s);

    }, function failure(e) {
      console.error("Couldn't set up Matomo:", e);
    });
  }
]);

@@ -101,16 +101,32 @@
 tings',%0A
+  '$rootScope',%0A
   functi
@@ -151,16 +151,27 @@
 settings
+,$rootScope
 ) %7B%0A    
@@ -996,33 +996,32 @@
  var d=document,
- 
 %0A          g=d.c
@@ -1035,33 +1035,32 @@
 ement('script'),
- 
 %0A          s=d.g
@@ -1122,25 +1122,24 @@
 javascript';
- 
 %0A        g.a
@@ -1144,25 +1144,24 @@
 .async=true;
- 
 %0A        g.s
@@ -1238,25 +1238,24 @@
 /matomo.js';
- 
 %0A        s.p
@@ -1473,17 +1473,16 @@
 ocument,
- 
 %0A       
@@ -1510,17 +1510,16 @@
 cript'),
- 
 %0A       
@@ -1589,17 +1589,16 @@
 script';
- 
 %0A      g
@@ -1609,17 +1609,16 @@
 nc=true;
- 
 %0A      g
@@ -1743,17 +1743,16 @@
 + '.js';
- 
 %0A      s
@@ -1779,24 +1779,447 @@
 fore(g,s);%0A%0A
+      // Sending Username Data%0A      $rootScope.$watch('currentUser', function() %7B%0A        var user = $rootScope.currentUser;%0A        if (user) %7B%0A          _paq.push(%5B%22setUserId%22, user.username%5D);%0A        %7D else %7B%0A          // https://developer.matomo.org/guides/tracking-javascript-guide#user-id%0A          // This doesn't seem to work fully, but it's good enough.%0A          _paq.push(%5B'resetUserId'%5D);%0A        %7D%0A      %7D);%0A
     %7D, funct

Save username to Matomo (#422)