diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 7dbf97285f..4e598b7be8 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -74,6 +74,7 @@ __deferLoadIfEnabled(); /*#endif#*/ var tower = angular.module('Tower', [ + 'pendolytics', 'ngRoute', 'ngSanitize', 'ngCookies', @@ -830,9 +831,9 @@ var tower = angular.module('Tower', [ }]) .run(['$compile', '$cookieStore', '$rootScope', '$log', 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer', 'ClearScope', 'HideStream', 'Socket', - 'LoadConfig', 'Store', 'ShowSocketHelp', 'AboutAnsibleHelp', + 'LoadConfig', 'Store', 'ShowSocketHelp', 'AboutAnsibleHelp', 'pendoService', function ($compile, $cookieStore, $rootScope, $log, CheckLicense, $location, Authorization, LoadBasePaths, Timer, ClearScope, HideStream, Socket, - LoadConfig, Store, ShowSocketHelp, AboutAnsibleHelp) { + LoadConfig, Store, ShowSocketHelp, AboutAnsibleHelp, pendoService) { var sock; @@ -1010,6 +1011,7 @@ var tower = angular.module('Tower', [ // when the user refreshes we want to open the socket, except if the user is on the login page, which should happen after the user logs in (see the AuthService module for that call to OpenSocket) if($location.$$url !== '/login'){ $rootScope.$emit('OpenSocket'); + pendoService.issuePendoIdentity(); } } diff --git a/awx/ui/client/src/login/authenticationServices/authentication.service.js b/awx/ui/client/src/login/authenticationServices/authentication.service.js index 0473f1bd7e..ae14be47e5 100644 --- a/awx/ui/client/src/login/authenticationServices/authentication.service.js +++ b/awx/ui/client/src/login/authenticationServices/authentication.service.js @@ -1,4 +1,4 @@ - /************************************************* +/************************************************* * Copyright (c) 2015 Ansible, Inc. * * All Rights Reserved @@ -109,6 +109,7 @@ export default setLicense: function (data) { var license = data.license_info; + license.analytics_status = data.analytics_status; license.version = data.version; license.tested = false; Store('license', license); diff --git a/awx/ui/client/src/login/authenticationServices/main.js b/awx/ui/client/src/login/authenticationServices/main.js index c6e4818cb3..a7de90ecc7 100644 --- a/awx/ui/client/src/login/authenticationServices/main.js +++ b/awx/ui/client/src/login/authenticationServices/main.js @@ -8,10 +8,12 @@ import authenticationService from './authentication.service'; import checkAccess from './checkAccess.factory'; import isAdmin from './isAdmin.factory'; import timer from './timer.factory'; +import pendoService from './pendo.service'; export default angular.module('authentication', []) .factory('Authorization', authenticationService) .factory('CheckAccess', checkAccess) .factory('IsAdmin', isAdmin) - .factory('Timer', timer); + .factory('Timer', timer) + .service('pendoService', pendoService); diff --git a/awx/ui/client/src/login/authenticationServices/pendo.service.js b/awx/ui/client/src/login/authenticationServices/pendo.service.js new file mode 100644 index 0000000000..e20002f6a7 --- /dev/null +++ b/awx/ui/client/src/login/authenticationServices/pendo.service.js @@ -0,0 +1,143 @@ +/************************************************* +* Copyright (c) 2015 Ansible, Inc. +* +* All Rights Reserved +*************************************************/ + + +export default + [ '$rootScope', '$pendolytics', 'Rest', 'GetBasePath', 'ProcessErrors', '$q', + 'Store', '$log', + function ($rootScope, $pendolytics, Rest, GetBasePath, ProcessErrors, $q, + Store, $log) { + return { + setPendoOptions: function (config) { + var options = { + visitor: { + id: null, + role: null, + email: null + }, + account: { + id: null, + planLevel: config.license_type, + planPrice: config.instance_count, + creationDate: config.license_date, + trial: config.trial + } + }; + if(config.analytics_status === 'detailed'){ + this.setDetailed(options, config); + } + else if(config.analytics_status === 'anonymous'){ + this.setAnonymous(options); + } + return options; + + }, + + setDetailed: function(options, config) { + // Detailed mode + // VisitorId: username+hash of license_key + // AccountId: hash of license_key from license + // email: contact_email from license OR email from Tower account + + options.visitor.id = $rootScope.current_user.username + '@' + config.deployment_id; + options.account.id = config.deployment_id; + options.visitor.email = $rootScope.current_user.email; + }, + + setAnonymous: function (options) { + //Anonymous mode + // VisitorId: + // AccountId: + // email: + + options.visitor.id = 0; + options.account.id = "tower.ansible.com"; + options.visitor.email = ""; + }, + + setRole: function(options) { + var deferred = $q.defer(); + if($rootScope.current_user.is_superuser === true){ + options.visitor.role = 'admin'; + deferred.resolve(options); + } + else{ + var url = GetBasePath('users') + $rootScope.current_user.id + '/admin_of_organizations/'; + Rest.setUrl(url); + var promise = Rest.get(); + promise.then(function (response) { + if(response.data.count > 0 ) { + options.visitor.role = "orgadmin"; + deferred.resolve(options); + } + else { + options.visitor.role = "user"; + deferred.resolve(options); + } + }); + promise.catch(function (response) { + ProcessErrors($rootScope, response.data, response.status, null, { + hdr: 'Error!', + msg: 'Failed to get inventory name. GET returned status: ' + + response.status }); + deferred.reject('Could not resolve pendo role.'); + }); + } + return deferred.promise; + }, + + getConfig: function () { + var config = Store('license'), + deferred = $q.defer(); + if(_.isEmpty(config)){ + var url = GetBasePath('config'); + Rest.setUrl(url); + var promise = Rest.get(); + promise.then(function (response) { + config = response.license_info; + config.analytics_status = response.analytics_status; + if(config.analytics_status !== 'off'){ + deferred.resolve(config); + } + else { + deferred.reject('Pendo is turned off.'); + } + }); + promise.catch(function (response) { + ProcessErrors($rootScope, response.data, response.status, null, { + hdr: 'Error!', + msg: 'Failed to get inventory name. GET returned status: ' + + response.status }); + deferred.reject('Could not resolve pendo config.'); + }); + } + else if(config.analytics_status !== 'off'){ + deferred.resolve(config); + } + else { + deferred.reject('Pendo is turned off.'); + } + return deferred.promise; + }, + + issuePendoIdentity: function () { + var that = this; + this.getConfig().then(function(config){ + var options = that.setPendoOptions(config); + that.setRole(options).then(function(options){ + $pendolytics.identify(options); + }, function(reason){ + // reject function for setRole + $log.debug(reason); + }); + }, function(reason){ + // reject function for getConfig + $log.debug(reason); + }); + } + }; + } +]; diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index 2bd204c072..5aeb6a2eb3 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -55,12 +55,11 @@ */ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait', - 'Timer', 'Empty', 'ClearScope', '$scope', + 'Timer', 'Empty', 'ClearScope', '$scope', 'pendoService', function ($log, $cookieStore, $compile, $window, $rootScope, $location, Authorization, ToggleClass, Alert, Wait, - Timer, Empty, ClearScope, scope) { + Timer, Empty, ClearScope, scope, pendoService) { - var setLoginFocus, lastPath, lastUser, sessionExpired, loginAgain, - e, html; + var setLoginFocus, lastPath, lastUser, sessionExpired, loginAgain; setLoginFocus = function () { // Need to clear out any open dialog windows that might be open when this modal opens. @@ -143,6 +142,7 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$l Authorization.getLicense() .success(function (data) { Authorization.setLicense(data); + pendoService.issuePendoIdentity(); Wait("stop"); if (lastPath() && lastUser()) { // Go back to most recent navigation path diff --git a/awx/ui/templates/ui/index.html b/awx/ui/templates/ui/index.html index 74ce0464a2..637cc36312 100644 --- a/awx/ui/templates/ui/index.html +++ b/awx/ui/templates/ui/index.html @@ -26,6 +26,15 @@ + + +