1616 *
1717 */
1818
19+ /*global logger*/
1920
2021define ( function ( require , exports , module ) {
2122 const EventDispatcher = require ( "utils/EventDispatcher" ) ,
2223 PreferencesManager = require ( "preferences/PreferencesManager" ) ,
24+ Metrics = require ( "utils/Metrics" ) ,
2325 Dialogs = require ( "widgets/Dialogs" ) ,
2426 DefaultDialogs = require ( "widgets/DefaultDialogs" ) ,
2527 Strings = require ( "strings" ) ,
@@ -164,10 +166,16 @@ define(function (require, exports, module) {
164166 return localAutoAuthURL . replace ( "http://localhost:" , "" ) ;
165167 }
166168
169+ const PLATFORM_STRINGS = {
170+ "win" : "Windows" ,
171+ "mac" : "mac" ,
172+ "linux" : "Linux"
173+ } ;
167174 // never rejects.
168175 async function _getAppAuthSession ( ) {
169176 const authPortURL = _getAutoAuthPortURL ( ) ;
170- const appName = encodeURIComponent ( `${ Strings . APP_NAME } Desktop on ${ Phoenix . platform } ` ) ;
177+ const platformStr = PLATFORM_STRINGS [ Phoenix . platform ] || Phoenix . platform ;
178+ const appName = encodeURIComponent ( `${ Strings . APP_NAME } Desktop on ${ platformStr } ` ) ;
171179 const resolveURL = `${ Phoenix . config . account_url } getAppAuthSession?autoAuthPort=${ authPortURL } &appName=${ appName } ` ;
172180 // {"isSuccess":true,"appSessionID":"a uuid...","validationCode":"SWXP07"}
173181 try {
@@ -182,7 +190,8 @@ define(function (require, exports, module) {
182190 return null ;
183191 } catch ( e ) {
184192 console . error ( e , "Failed to call getAppAuthSession API endpoint" , resolveURL ) ;
185- // todo raise metrics/log
193+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , 'getAppAuth' , Phoenix . platform ) ;
194+ logger . reportError ( e , "Failed to call getAppAuthSession API endpoint" + resolveURL ) ;
186195 return null ;
187196 }
188197 }
@@ -197,7 +206,7 @@ define(function (require, exports, module) {
197206 } catch ( e ) {
198207 console . error ( "failed to send auth login verification code to node" , e ) ;
199208 // we ignore this and continue for manual verification
200- // todo raise metrics
209+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , 'autoFail' , Phoenix . platform ) ;
201210 }
202211 }
203212
@@ -290,8 +299,10 @@ define(function (require, exports, module) {
290299 setTimeout ( checkLoginStatus , 100 ) ;
291300 }
292301 }
302+ let isAutoSignedIn = false ;
293303 exports . on ( _EVT_PAGE_FOCUSED , checkLoginStatus ) ;
294304 async function _AutoSignedIn ( ) {
305+ isAutoSignedIn = true ;
295306 await checkLoginStatus ( ) ;
296307 }
297308 authNodeConnector . one ( EVENT_CONNECTED , _AutoSignedIn ) ;
@@ -301,13 +312,18 @@ define(function (require, exports, module) {
301312 exports . off ( _EVT_PAGE_FOCUSED , checkLoginStatus ) ;
302313 authNodeConnector . off ( EVENT_CONNECTED , _AutoSignedIn ) ;
303314 clearTimeout ( closeTimeout ) ;
315+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH ,
316+ isAutoSignedIn ? 'autoLogin' : 'manLogin'
317+ , Phoenix . platform ) ;
318+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , "login" ,
319+ isAutoSignedIn ? 'auto' : 'man' ) ;
304320 } ) ;
305321 NativeApp . openURLInDefaultBrowser ( appSignInURL ) ;
306322 }
307323
308324 async function signOutAccount ( ) {
325+ const resolveURL = `${ Phoenix . config . account_url } logoutSession` ;
309326 try {
310- const resolveURL = `${ Phoenix . config . account_url } logoutSession` ;
311327 let input = {
312328 appSessionID : userProfile . apiKey
313329 } ;
@@ -329,23 +345,25 @@ define(function (require, exports, module) {
329345 Strings . SIGNED_OUT_FAILED_TITLE ,
330346 Strings . SIGNED_OUT_FAILED_MESSAGE
331347 ) ;
348+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , 'logoutFail' , Phoenix . platform ) ;
332349 return ;
333- // todo raise metrics
334350 }
335351 await _resetAccountLogin ( ) ;
336352 Dialogs . showModalDialog (
337353 DefaultDialogs . DIALOG_ID_INFO ,
338354 Strings . SIGNED_OUT ,
339355 Strings . SIGNED_OUT_MESSAGE_FRIENDLY
340356 ) ;
357+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , 'logoutOK' , Phoenix . platform ) ;
341358 } catch ( error ) {
342359 console . error ( "Network error. Could not log out session." , error ) ;
343360 Dialogs . showModalDialog (
344361 DefaultDialogs . DIALOG_ID_ERROR ,
345362 Strings . SIGNED_OUT_FAILED_TITLE ,
346363 Strings . SIGNED_OUT_FAILED_MESSAGE
347364 ) ;
348- // todo raise metrics
365+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , 'getAppAuth' , Phoenix . platform ) ;
366+ logger . reportError ( error , "Failed to call logout calling" + resolveURL ) ;
349367 }
350368 }
351369
0 commit comments