Skip to content

Commit 35caef9

Browse files
committed
append R to end of generated deviceId
1 parent e125160 commit 35caef9

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

amplitude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Amplitude.prototype.init = function init(apiKey, opt_userId, opt_config, opt_cal
188188

189189
// load deviceId and userId from input, or try to fetch existing value from cookie
190190
this.options.deviceId = (type(opt_config) === 'object' && type(opt_config.deviceId) === 'string' &&
191-
!utils.isEmptyString(opt_config.deviceId) && opt_config.deviceId) || this.options.deviceId || UUID();
191+
!utils.isEmptyString(opt_config.deviceId) && opt_config.deviceId) || this.options.deviceId || UUID() + 'R';
192192
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
193193
this.options.userId || null;
194194

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Amplitude.prototype.init = function init(apiKey, opt_userId, opt_config, opt_cal
8282

8383
// load deviceId and userId from input, or try to fetch existing value from cookie
8484
this.options.deviceId = (type(opt_config) === 'object' && type(opt_config.deviceId) === 'string' &&
85-
!utils.isEmptyString(opt_config.deviceId) && opt_config.deviceId) || this.options.deviceId || UUID();
85+
!utils.isEmptyString(opt_config.deviceId) && opt_config.deviceId) || this.options.deviceId || UUID() + 'R';
8686
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
8787
this.options.userId || null;
8888

test/amplitude.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ describe('Amplitude', function() {
5050
assert.equal(amplitude.options.userId, userId);
5151
});
5252

53+
it('should generate a random deviceId', function() {
54+
amplitude.init(apiKey, userId);
55+
assert.lengthOf(amplitude.options.deviceId, 37); // UUID is length 36, but we append 'R' at end
56+
assert.equal(amplitude.options.deviceId[36], 'R');
57+
});
58+
5359
it('should validate config values', function() {
5460
var config = {
5561
apiEndpoint: 100, // invalid type
@@ -76,7 +82,7 @@ describe('Amplitude', function() {
7682
var stored = cookie.get(amplitude.options.cookieName);
7783
assert.property(stored, 'deviceId');
7884
assert.propertyVal(stored, 'userId', userId);
79-
assert.lengthOf(stored.deviceId, 36);
85+
assert.lengthOf(stored.deviceId, 37); // increase deviceId length by 1 for 'R' character
8086
});
8187

8288
it('should set language', function() {

0 commit comments

Comments
 (0)