Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 2b05ff0

Browse files
authored
Merge pull request #47 from akiliinteractive/master
change setNewDeviceId parameter order to match web SDK
2 parents e0ef726 + 0196810 commit 2b05ff0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Countly.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)