Skip to content

Commit

Permalink
feat: update setLibrary api make it ignore the null value of name or …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
yuhao900914 authored Nov 18, 2021
1 parent 69c18f7 commit 8e0971e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ var _convertProxyObjectToRealObject = function _convertProxyObjectToRealObject(i
* var identify = new amplitude.Identify().set('colors', ['rose', 'gold']).add('karma', 1).setOnce('sign_up_date', '2016-03-31');
* amplitude.identify(identify);
*/
AmplitudeClient.prototype.identify = function (identify_obj, opt_callback, opt_error_callback) {
AmplitudeClient.prototype.identify = function (identify_obj, opt_callback, opt_error_callback, outOfSession) {
if (this._shouldDeferCall()) {
return this._q.push(['identify'].concat(Array.prototype.slice.call(arguments, 0)));
}
Expand Down Expand Up @@ -1142,6 +1142,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback, opt_e
null,
opt_callback,
opt_error_callback,
outOfSession,
);
} else {
_logErrorsWithCallbacks(opt_callback, opt_error_callback, 0, 'No request sent', {
Expand All @@ -1162,6 +1163,7 @@ AmplitudeClient.prototype.groupIdentify = function (
identify_obj,
opt_callback,
opt_error_callback,
outOfSession,
) {
if (this._shouldDeferCall()) {
return this._q.push(['groupIdentify'].concat(Array.prototype.slice.call(arguments, 0)));
Expand Down Expand Up @@ -1205,6 +1207,7 @@ AmplitudeClient.prototype.groupIdentify = function (
null,
opt_callback,
opt_error_callback,
outOfSession,
);
} else {
_logErrorsWithCallbacks(opt_callback, opt_error_callback, 0, 'No request sent', {
Expand Down Expand Up @@ -1908,11 +1911,13 @@ AmplitudeClient.prototype.__VERSION__ = function getVersion() {
* @param {string} name - Custom library name
* @param {string} version - Custom library version
*/
AmplitudeClient.prototype.setLibrary = function setLibrary(
name = this.options.libraryName,
version = this.options.libraryVersion,
) {
this.options.library = { name: name, version: version };
AmplitudeClient.prototype.setLibrary = function setLibrary(name, version) {
if (name !== null && typeof name !== 'undefined') {
this.options.library.name = name;
}
if (version !== null && typeof version !== 'undefined') {
this.options.library.version = version;
}
};

/**
Expand Down
19 changes: 19 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,15 @@ describe('AmplitudeClient', function () {
assert.equal(value, 0);
assert.equal(message, 'No request sent');
});

it('should out of session', function () {
var identify = new Identify().set('prop1', 'value1');
amplitude.groupIdentify(group_type, group_name, identify, true);

assert.lengthOf(amplitude._unsentEvents, 0);
assert.lengthOf(amplitude._unsentIdentifys, 1);
assert.deepEqual(amplitude._unsentIdentifys[0].event.session_id, -1);
});
});

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

it('should out of session', function () {
var identify = new Identify().set(10, 10);
amplitude.init(apiKey);
amplitude.identify(identify, null, null, true);

assert.lengthOf(amplitude._unsentEvents, 0);
assert.lengthOf(amplitude._unsentIdentifys, 1);
assert.deepEqual(amplitude._unsentIdentifys[0].event.session_id, -1);
});

it('should ignore event and user properties with too many items', function () {
amplitude.init(apiKey, null, { batchEvents: true, eventUploadThreshold: 2 });
var eventProperties = {};
Expand Down

0 comments on commit 8e0971e

Please sign in to comment.