Skip to content

Commit fc4d624

Browse files
committed
patch: make setLibrary function able to seprate set library name and version
1 parent 9632966 commit fc4d624

File tree

2 files changed

+8
-34
lines changed

2 files changed

+8
-34
lines changed

src/amplitude-client.js

+5-22
Original file line numberDiff line numberDiff line change
@@ -1908,30 +1908,13 @@ AmplitudeClient.prototype.__VERSION__ = function getVersion() {
19081908
* @param {string} name - Custom library name
19091909
* @param {string} version - Custom library version
19101910
*/
1911-
AmplitudeClient.prototype.setLibrary = function setLibrary(name, version) {
1911+
AmplitudeClient.prototype.setLibrary = function setLibrary(
1912+
name = this.options.libraryName,
1913+
version = this.options.libraryVersion,
1914+
) {
19121915
this.options.library = { name: name, version: version };
19131916
};
19141917

1915-
/**
1916-
* Sets the library name.
1917-
* @public
1918-
* @param {string} libraryName - the library name.
1919-
* @example amplitudeClient.setLibraryName('my_library_name');
1920-
*/
1921-
AmplitudeClient.prototype.setLibraryName = function setLibraryName(libraryName) {
1922-
this.options.library.name = libraryName;
1923-
};
1924-
1925-
/**
1926-
* Sets the library Version.
1927-
* @public
1928-
* @param {string} userId - the library version.
1929-
* @example amplitudeClient.setLibraryVersion('1.0.0');
1930-
*/
1931-
AmplitudeClient.prototype.setLibraryVersion = function setLibraryVersion(libraryVersion) {
1932-
this.options.library.version = libraryVersion;
1933-
};
1934-
19351918
/**
19361919
* Determines whether or not to push call to this._q or invoke it
19371920
* @private
@@ -2063,7 +2046,7 @@ AmplitudeClient.prototype.setUseDynamicConfig = function setUseDynamicConfig(use
20632046
};
20642047

20652048
/**
2066-
* Sets the server zone , used for server api endpoint and dynamic configuration..
2049+
* Sets the server zone , used for server api endpoint and dynamic configuration.
20672050
* @public
20682051
* @param {string} serverZone - the server zone value. AmplitudeServerZone.US or AmplitudeServerZone.EU.
20692052
* @param {bool} serverZoneBasedApi - (optional) update api endpoint with serverZone change or not. For data residency, recommend to enable it unless using own proxy server.

test/amplitude-client.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -4172,6 +4172,7 @@ describe('AmplitudeClient', function () {
41724172
beforeEach(function () {
41734173
reset();
41744174
});
4175+
41754176
it('should use default library options', function () {
41764177
amplitude.init(apiKey);
41774178
amplitude.logEvent('Event Type 1');
@@ -4199,31 +4200,21 @@ describe('AmplitudeClient', function () {
41994200
assert.equal(name, 'test-library');
42004201
assert.equal(version, '1.0-test');
42014202
});
4202-
});
42034203

4204-
describe('libraryName', function () {
4205-
beforeEach(function () {
4206-
reset();
4207-
});
42084204
it('should use the customize library name and default library version', function () {
42094205
amplitude.init(apiKey);
4210-
amplitude.setLibraryName('test-library');
4206+
amplitude.setLibrary('test-library', undefined);
42114207
amplitude.logEvent('Event Type');
42124208

42134209
const { name, version } = JSON.parse(queryString.parse(server.requests[0].requestBody).e)[0].library;
42144210

42154211
assert.equal(name, 'test-library');
42164212
assert.equal(version, amplitude.options.library.version);
42174213
});
4218-
});
42194214

4220-
describe('libraryVersion', function () {
4221-
beforeEach(function () {
4222-
reset();
4223-
});
42244215
it('should use the customize library version and default library name', function () {
42254216
amplitude.init(apiKey);
4226-
amplitude.setLibraryVersion('1.0-test');
4217+
amplitude.setLibrary(undefined, '1.0-test');
42274218
amplitude.logEvent('Event Type');
42284219

42294220
const { name, version } = JSON.parse(queryString.parse(server.requests[0].requestBody).e)[0].library;

0 commit comments

Comments
 (0)