This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -514,10 +514,11 @@ class Countly {
514514 )
515515
516516 /**
517- * @description setNewDeviceId:onServer method implementation
518- * @param {* } ROOT_URL dashboard base address
519- */
520- setNewDeviceId = ( onServer = false , deviceId ) => (
517+ * Change current user/device id
518+ * @param {string } newId - new user/device ID to use
519+ * @param {boolean } onServer - if true, move data from old ID to new ID on server
520+ **/
521+ setNewDeviceId = ( deviceId , onServer = false ) => (
521522 new Promise ( async ( resolve , reject ) => {
522523 if ( onServer ) {
523524 if ( this . DEVICE_ID === deviceId ) {
@@ -529,8 +530,9 @@ class Countly {
529530 } catch ( error ) {
530531 return reject ( new Error ( `Unable to change DeviceId ${ error } ` ) ) ;
531532 }
532- } else if ( onServer === false ) {
533+ } else { // merge locally, stop session and start new session
533534 try {
535+ await this . stop ( ) ;
534536 const result = await Ajax . setItem ( 'DEVICE_ID' , deviceId , ( result ) => { this . log ( result ) } ) ;
535537 this . DEVICE_ID = deviceId ;
536538 this . storedEvents = { } ;
@@ -540,7 +542,6 @@ class Countly {
540542 return reject ( new Error ( `Unable to change DeviceId ${ error } ` ) ) ;
541543 }
542544 }
543- return reject ( new Error ( 'Unable to change DeviceId onServer is not set' ) ) ;
544545 } )
545546 )
546547
You can’t perform that action at this time.
0 commit comments