diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f3de83..3b3c6be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## XX.XX.XX +- Added a new method `set_id(newDeviceId)` for managing device ID changes according to the device ID Type + ## 24.10.0 - Default max segmentation value count changed from 30 to 100 - Mitigated an issue where SDK could create an unintended dump file diff --git a/lib/countly.js b/lib/countly.js index 761ca7a..6cbed26 100644 --- a/lib/countly.js +++ b/lib/countly.js @@ -627,6 +627,25 @@ Countly.Bulk = Bulk; return Countly.device_id; }; + /** + * Changes the current device ID according to the device ID type (the preffered method) + * @param {string} newId - new user/device ID to use. Must be a non-empty string value. Invalid values (like null, empty string or undefined) will be rejected + * */ + Countly.set_id = function (newId) { + cc.log(cc.logLevelEnums.INFO, "set_id, Changing the device ID to:[" + newId + "]"); + if (newId == null || newId === "") { + cc.log(cc.logLevelEnums.WARNING, "set_id, The provided device is not a valid ID"); + return; + } + if (Countly.deviceIdType === cc.deviceIdTypeEnums.DEVELOPER_SUPPLIED) { + /*change ID without merge as current ID is Dev supplied, so not first login*/ + Countly.change_id(newId, false); + } else { + /*change ID with merge as current ID is not Dev supplied*/ + Countly.change_id(newId, true); + } + }; + /** * Change current user/device id * @param {string} newId - new user/device ID to use