@@ -425,7 +425,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
425
425
await this . guardAccess ( { kind : "user" , subject : user } , "update" ) ;
426
426
427
427
//hang on to user profile before it's overwritten for analytics below
428
- const oldProfile = { name : user . fullName , ... user . additionalData ?. profile } ;
428
+ const oldProfile = User . getProfile ( user ) ;
429
429
430
430
const allowedFields : ( keyof User ) [ ] = [ "avatarUrl" , "fullName" , "additionalData" ] ;
431
431
for ( const p of allowedFields ) {
@@ -437,24 +437,17 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
437
437
await this . userDB . updateUserPartial ( user ) ;
438
438
439
439
//track event and user profile if profile of partialUser changed
440
- const newProfile = { name : partialUser . fullName , ...partialUser . additionalData ?. profile } ;
441
- if ( newProfile ) {
442
- if (
443
- ! oldProfile ||
444
- newProfile . emailAddress != oldProfile . emailAddress ||
445
- newProfile . companyName != oldProfile . companyName ||
446
- newProfile . name != oldProfile . name
447
- ) {
448
- this . analytics . track ( {
449
- userId : user . id ,
450
- event : "profile_changed" ,
451
- properties : { new : newProfile , old : oldProfile } ,
452
- } ) ;
453
- this . analytics . identify ( {
454
- userId : user . id ,
455
- traits : { email : newProfile . emailAddress , company : newProfile . companyName , name : newProfile . name } ,
456
- } ) ;
457
- }
440
+ const newProfile = User . getProfile ( user ) ;
441
+ if ( User . Profile . hasChanges ( oldProfile , newProfile ) ) {
442
+ this . analytics . track ( {
443
+ userId : user . id ,
444
+ event : "profile_changed" ,
445
+ properties : { new : newProfile , old : oldProfile } ,
446
+ } ) ;
447
+ this . analytics . identify ( {
448
+ userId : user . id ,
449
+ traits : { email : newProfile . email , company : newProfile . company , name : newProfile . name } ,
450
+ } ) ;
458
451
}
459
452
460
453
return user ;
0 commit comments