Skip to content

Commit 5985deb

Browse files
authored
Merge pull request #130 from amplitude/accept-numerical-user-ids
Allow for number user ids
2 parents 2e396c7 + 69bb860 commit 5985deb

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

amplitude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5730,7 +5730,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
57305730

57315731
// load deviceId and userId from input, or try to fetch existing value from cookie
57325732
this.options.deviceId = type(opt_config) === 'object' && type(opt_config.deviceId) === 'string' && !utils.isEmptyString(opt_config.deviceId) && opt_config.deviceId || this.options.deviceIdFromUrlParam && this._getDeviceIdFromUrlParam(this._getUrlParams()) || this.options.deviceId || uuid$1() + 'R';
5733-
this.options.userId = type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId || this.options.userId || null;
5733+
this.options.userId = type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId || type(opt_userId) === 'number' && opt_userId.toString() || this.options.userId || null;
57345734

57355735
// load unsent events and identifies before any attempt to log new ones
57365736
if (this.options.saveEvents) {

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude-client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
8383
!utils.isEmptyString(opt_config.deviceId) && opt_config.deviceId) ||
8484
(this.options.deviceIdFromUrlParam && this._getDeviceIdFromUrlParam(this._getUrlParams())) ||
8585
this.options.deviceId || UUID() + 'R';
86-
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
86+
this.options.userId =
87+
(type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
88+
(type(opt_userId) === 'number' && opt_userId.toString()) ||
8789
this.options.userId || null;
8890

8991
// load unsent events and identifies before any attempt to log new ones

test/amplitude-client.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ describe('AmplitudeClient', function() {
7373
assert.equal(amplitude.options.userId, userId);
7474
});
7575

76+
it('should accept numerical userIds', function() {
77+
const userId = 5;
78+
amplitude.init(apiKey, 5);
79+
assert.equal(amplitude.options.userId, '5');
80+
});
81+
7682
it('should generate a random deviceId', function() {
7783
amplitude.init(apiKey, userId);
7884
assert.lengthOf(amplitude.options.deviceId, 37); // UUID is length 36, but we append 'R' at end

0 commit comments

Comments
 (0)