소스 검색

Add Google Analytics

Gaël Métais 10 년 전
부모
커밋
17a644c5d8
6개의 변경된 파일41개의 추가작업 그리고 12개의 파일을 삭제
  1. 1 0
      .gitignore
  2. 18 4
      Gruntfile.js
  3. 7 2
      front/src/js/app.js
  4. 10 0
      front/src/main.html
  5. 1 0
      package.json
  6. 4 6
      server_config/settings-prod.json

+ 1 - 0
.gitignore

@@ -3,5 +3,6 @@ bower_components
 .vagrant
 results/*
 coverage
+front/build
 
 har.json

+ 18 - 4
Gruntfile.js

@@ -1,14 +1,12 @@
 module.exports = function(grunt) {
 
-    var DEV_SERVER_PORT = 8383;
-    var TEST_SERVER_PORT = 8387;
-
     // Tell our Express server that Grunt launched it
     process.env.GRUNTED = true;
 
     // Project configuration.
     grunt.initConfig({
         pkg: grunt.file.readJSON('package.json'),
+        settings: grunt.file.readJSON('./server_config/settings.json'),
         
         font: {
             icons: {
@@ -37,6 +35,21 @@ module.exports = function(grunt) {
                 ]
             }
         },
+        replace: {
+            dist: {
+                options: {
+                    patterns: [
+                        {
+                            match: 'googleAnalyticsId',
+                            replacement: '<%= settings.googleAnalyticsId %>'
+                        }
+                    ]
+                },
+                files: [
+                    {expand: true, flatten: true, src: ['front/src/main.html'], dest: 'front/build/'}
+                ]
+            }
+        },
         jshint: {
             all: [
                 '*.js',
@@ -171,7 +184,8 @@ module.exports = function(grunt) {
     ]);
 
     grunt.registerTask('build', [
-        'less'
+        'less',
+        'replace'
     ]);
 
     grunt.registerTask('hint', [

+ 7 - 2
front/src/js/app.js

@@ -12,9 +12,14 @@ var yltApp = angular.module('YellowLabTools', [
     'gradeDirective',
 ]);
 
-yltApp.run(function($rootScope) {
+yltApp.run(['$rootScope', '$location', function($rootScope, $location) {
     $rootScope.loadedRunId = null;
-});
+
+    // Google Analytics
+    $rootScope.$on('$routeChangeSuccess', function(){
+        ga('send', 'pageview', {'page': $location.path()});
+    });
+}]);
 
 yltApp.config(['$routeProvider', '$locationProvider',
     function($routeProvider, $locationProvider) {

+ 10 - 0
front/src/main.html

@@ -35,5 +35,15 @@
     <div class="footer">
         <p><a href="/about">Learn more</a><br>If you like <b>Yellow Lab Tools</b>, <a href="https://github.com/gmetais/YellowLabTools" target="_blank" class="star">give it a <span>&#9733;</span> on GitHub</a>!</p>
     </div>
+
+    <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');
+        if ('@@googleAnalyticsId'.indexOf('UA-') === 0) {
+            ga('create', '@@googleAnalyticsId', 'auto');
+        }
+    </script>
 </body>
 </html>

+ 1 - 0
package.json

@@ -32,6 +32,7 @@
     "grunt-express": "^1.4.1",
     "grunt-fontsmith": "^0.9.1",
     "grunt-mocha-test": "^0.12.4",
+    "grunt-replace": "^0.8.0",
     "matchdep": "^0.3.0",
     "mocha": "^2.1.0",
     "phantomjs": "^1.9.13",

+ 4 - 6
server_config/settings-prod.json

@@ -1,12 +1,10 @@
 {
     "serverPort": 80,
-    "googleAnalyticsId": "UA-54493828-1",
+    "googleAnalyticsId": "",
 
-    "authorized-keys": {
+    "authorizedKeys": {
         
     },
-    "tokenSalt": "",
-    "authorizedApplications": [
-        
-    ]
+    "maxAnonymousRunsPerDay": 50,
+    "maxAnonymousCallsPerDay": 2000
 }