feat(project): add google analytics in app (#599)

pull/601/head
Anthony Lapenna 2017-02-14 11:39:26 +13:00 committed by GitHub
parent 85a07237b1
commit 66c574f74d
4 changed files with 50 additions and 9 deletions

View File

@ -12,6 +12,7 @@ angular.module('portainer', [
'angularUtils.directives.dirPagination',
'LocalStorageModule',
'angular-jwt',
'angular-google-analytics',
'portainer.templates',
'portainer.filters',
'portainer.rest',
@ -47,7 +48,7 @@ angular.module('portainer', [
'task',
'templates',
'volumes'])
.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', 'localStorageServiceProvider', 'jwtOptionsProvider', function ($stateProvider, $urlRouterProvider, $httpProvider, localStorageServiceProvider, jwtOptionsProvider) {
.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', 'localStorageServiceProvider', 'jwtOptionsProvider', 'AnalyticsProvider', function ($stateProvider, $urlRouterProvider, $httpProvider, localStorageServiceProvider, jwtOptionsProvider, AnalyticsProvider) {
'use strict';
localStorageServiceProvider
@ -64,6 +65,8 @@ angular.module('portainer', [
});
$httpProvider.interceptors.push('jwtInterceptor');
AnalyticsProvider.setAccount('@@CONFIG_GA_ID');
$urlRouterProvider.otherwise('/auth');
$stateProvider
@ -484,7 +487,7 @@ angular.module('portainer', [
};
});
}])
.run(['$rootScope', '$state', 'Authentication', 'authManager', 'StateManager', 'Messages', function ($rootScope, $state, Authentication, authManager, StateManager, Messages) {
.run(['$rootScope', '$state', 'Authentication', 'authManager', 'StateManager', 'Messages', 'Analytics', function ($rootScope, $state, Authentication, authManager, StateManager, Messages, Analytics) {
StateManager.initialize().then(function success(state) {
if (state.application.authentication) {
authManager.checkAuthOnRefresh();
@ -498,6 +501,11 @@ angular.module('portainer', [
Messages.error("Failure", err, 'Unable to retrieve application settings');
});
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
Analytics.trackPage(toState.url);
Analytics.pageView();
});
$rootScope.$state = $state;
}])
// This is your docker url that the api will use to make requests

View File

@ -12,7 +12,8 @@
"api",
"portainer",
"uifordocker",
"dockerui"
"dockerui",
"swarm"
],
"license": "MIT",
"ignore": [
@ -35,6 +36,7 @@
"angular-utils-pagination": "~0.11.1",
"angular-local-storage": "~0.5.2",
"angular-jwt": "~0.1.8",
"angular-google-analytics": "~1.1.9",
"bootstrap": "~3.3.6",
"filesize": "~3.3.0",
"jquery": "1.11.1",

View File

@ -13,6 +13,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-filerev');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-replace');
// Default task.
grunt.registerTask('default', ['jshint', 'build']);
@ -42,7 +43,8 @@ module.exports = function (grunt) {
'copy:assets',
'filerev',
'usemin',
'clean:tmp'
'clean:tmp',
'replace'
]);
grunt.registerTask('release-win', [
'clean:all',
@ -57,7 +59,8 @@ module.exports = function (grunt) {
'copy',
'filerev',
'usemin',
'clean:tmp'
'clean:tmp',
'replace'
]);
grunt.registerTask('release-arm', [
'clean:all',
@ -72,7 +75,8 @@ module.exports = function (grunt) {
'copy',
'filerev',
'usemin',
'clean:tmp'
'clean:tmp',
'replace'
]);
grunt.registerTask('release-arm64', [
'clean:all',
@ -87,7 +91,8 @@ module.exports = function (grunt) {
'copy',
'filerev',
'usemin',
'clean:tmp'
'clean:tmp',
'replace'
]);
grunt.registerTask('release-macos', [
'clean:all',
@ -102,7 +107,8 @@ module.exports = function (grunt) {
'copy',
'filerev',
'usemin',
'clean:tmp'
'clean:tmp',
'replace'
]);
grunt.registerTask('lint', ['jshint']);
grunt.registerTask('run', ['if:unixBinaryNotExist', 'build', 'shell:buildImage', 'shell:run']);
@ -260,6 +266,7 @@ module.exports = function (grunt) {
'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'bower_components/ng-file-upload/ng-file-upload.min.js',
'bower_components/angular-utils-pagination/dirPagination.js',
'bower_components/angular-google-analytics/dist/angular-google-analytics.min.js',
'bower_components/angular-ui-select/dist/select.min.js'],
dest: '<%= distdir %>/js/angular.js'
}
@ -459,6 +466,26 @@ module.exports = function (grunt) {
},
ifFalse: ['shell:buildWindowsBinary']
}
},
replace: {
dist: {
options: {
patterns: [
{
match: 'CONFIG_GA_ID',
replacement: '<%= pkg.config.GA_ID %>'
}
]
},
files: [
{
expand: true,
flatten: true,
src: ['dist/js/**.js'],
dest: 'dist/js/'
}
]
}
}
});
};

View File

@ -10,9 +10,12 @@
"bugs": {
"url": "https://github.com/portainer/portainer/issues"
},
"config": {
"GA_ID": "UA-84944922-2"
},
"licenses": [
{
"type": "MIT",
"type": "Zlib",
"url": "https://raw.githubusercontent.com/portainer/portainer/develop/LICENSE"
}
],
@ -35,6 +38,7 @@
"grunt-if": "^0.1.5",
"grunt-karma": "~0.4.4",
"grunt-recess": "~0.3",
"grunt-replace": "^1.0.1",
"grunt-shell": "^1.1.2",
"grunt-usemin": "^3.1.1"
},