Skip to content

Commit 8e0971e

Browse files
authored
feat: update setLibrary api make it ignore the null value of name or version (#449)
* feat: add more interface for flutter web support * patch: code clean up and other fix * test: add setUserId test * patch: test update * patch: remove unnecessary api interface * patch: make setLibrary function able to seprate set library name and version * patch: make setLibrary function able to seprate set library name and version * patch: setLibrary improvement * patch: make groupIdentify and identify api enable to pass outOfSession info * test: add test and chagnes based on comments
1 parent 69c18f7 commit 8e0971e

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/amplitude-client.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ var _convertProxyObjectToRealObject = function _convertProxyObjectToRealObject(i
11141114
* var identify = new amplitude.Identify().set('colors', ['rose', 'gold']).add('karma', 1).setOnce('sign_up_date', '2016-03-31');
11151115
* amplitude.identify(identify);
11161116
*/
1117-
AmplitudeClient.prototype.identify = function (identify_obj, opt_callback, opt_error_callback) {
1117+
AmplitudeClient.prototype.identify = function (identify_obj, opt_callback, opt_error_callback, outOfSession) {
11181118
if (this._shouldDeferCall()) {
11191119
return this._q.push(['identify'].concat(Array.prototype.slice.call(arguments, 0)));
11201120
}
@@ -1142,6 +1142,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback, opt_e
11421142
null,
11431143
opt_callback,
11441144
opt_error_callback,
1145+
outOfSession,
11451146
);
11461147
} else {
11471148
_logErrorsWithCallbacks(opt_callback, opt_error_callback, 0, 'No request sent', {
@@ -1162,6 +1163,7 @@ AmplitudeClient.prototype.groupIdentify = function (
11621163
identify_obj,
11631164
opt_callback,
11641165
opt_error_callback,
1166+
outOfSession,
11651167
) {
11661168
if (this._shouldDeferCall()) {
11671169
return this._q.push(['groupIdentify'].concat(Array.prototype.slice.call(arguments, 0)));
@@ -1205,6 +1207,7 @@ AmplitudeClient.prototype.groupIdentify = function (
12051207
null,
12061208
opt_callback,
12071209
opt_error_callback,
1210+
outOfSession,
12081211
);
12091212
} else {
12101213
_logErrorsWithCallbacks(opt_callback, opt_error_callback, 0, 'No request sent', {
@@ -1908,11 +1911,13 @@ AmplitudeClient.prototype.__VERSION__ = function getVersion() {
19081911
* @param {string} name - Custom library name
19091912
* @param {string} version - Custom library version
19101913
*/
1911-
AmplitudeClient.prototype.setLibrary = function setLibrary(
1912-
name = this.options.libraryName,
1913-
version = this.options.libraryVersion,
1914-
) {
1915-
this.options.library = { name: name, version: version };
1914+
AmplitudeClient.prototype.setLibrary = function setLibrary(name, version) {
1915+
if (name !== null && typeof name !== 'undefined') {
1916+
this.options.library.name = name;
1917+
}
1918+
if (version !== null && typeof version !== 'undefined') {
1919+
this.options.library.version = version;
1920+
}
19161921
};
19171922

19181923
/**

test/amplitude-client.js

+19
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,15 @@ describe('AmplitudeClient', function () {
15261526
assert.equal(value, 0);
15271527
assert.equal(message, 'No request sent');
15281528
});
1529+
1530+
it('should out of session', function () {
1531+
var identify = new Identify().set('prop1', 'value1');
1532+
amplitude.groupIdentify(group_type, group_name, identify, true);
1533+
1534+
assert.lengthOf(amplitude._unsentEvents, 0);
1535+
assert.lengthOf(amplitude._unsentIdentifys, 1);
1536+
assert.deepEqual(amplitude._unsentIdentifys[0].event.session_id, -1);
1537+
});
15291538
});
15301539

15311540
describe('logEvent with tracking options', function () {
@@ -2668,6 +2677,16 @@ describe('AmplitudeClient', function () {
26682677
assert.deepEqual(amplitude._unsentIdentifys[0].event.user_properties, { $set: { 10: 10 } });
26692678
});
26702679

2680+
it('should out of session', function () {
2681+
var identify = new Identify().set(10, 10);
2682+
amplitude.init(apiKey);
2683+
amplitude.identify(identify, null, null, true);
2684+
2685+
assert.lengthOf(amplitude._unsentEvents, 0);
2686+
assert.lengthOf(amplitude._unsentIdentifys, 1);
2687+
assert.deepEqual(amplitude._unsentIdentifys[0].event.session_id, -1);
2688+
});
2689+
26712690
it('should ignore event and user properties with too many items', function () {
26722691
amplitude.init(apiKey, null, { batchEvents: true, eventUploadThreshold: 2 });
26732692
var eventProperties = {};

0 commit comments

Comments
 (0)