Skip to content

Commit

Permalink
feat: add partner_id support (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingzhuozhen authored Jul 25, 2022
1 parent 27b4957 commit 7b343ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
groups: utils.truncate(utils.validateGroups(groups)),
group_properties: utils.truncate(utils.validateProperties(groupProperties)),
user_agent: this._userAgent,
partner_id: this.options.partnerId || null,
};

if (_isObservePlanSet(this)) {
Expand Down
2 changes: 2 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { version as libraryVersion } from '../package.json';
* @property {boolean} [useDynamicConfig] - Enable dynamic configuration to find best server url for user.
* @property {boolean} [serverZoneBasedApi] - To update api endpoint with serverZone change or not. For data residency, recommend to enable it unless using own proxy server.
* @property {number} [sessionId=`null`] - The custom Session ID for the current session. *Note: This is not recommended unless you know what you are doing because the Session ID of a session is utilized for all session metrics in Amplitude.
* @property {string} [partnerId=`null`] - The partner id value
*/
export default {
apiEndpoint: Constants.EVENT_LOG_URL,
Expand Down Expand Up @@ -125,4 +126,5 @@ export default {
useDynamicConfig: false,
serverZoneBasedApi: false,
sessionId: null,
partnerId: '',
};
21 changes: 21 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4551,4 +4551,25 @@ describe('AmplitudeClient', function () {
requestStub.restore();
});
});

describe('partnerId Support', function () {
beforeEach(function () {
reset();
});

it('should include partner_id', function () {
const partnerId = 'test-partner-id';
amplitude.init(apiKey, null, { batchEvents: true, partnerId: partnerId });

amplitude.logEvent('testEvent1');
assert.equal(amplitude._unsentEvents[0].event.partner_id, partnerId);
});

it('should set partner_id default null', function () {
amplitude.init(apiKey, null, { batchEvents: true });

amplitude.logEvent('testEvent1');
assert.equal(amplitude._unsentEvents[0].event.partner_id, null);
});
});
});

0 comments on commit 7b343ea

Please sign in to comment.