Skip to content

Commit 529ad88

Browse files
authored
feat: add observe plan options (#427)
1 parent e010d3e commit 529ad88

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/amplitude-client.js

+13
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
12691269
eventProperties = eventProperties || {};
12701270
groups = groups || {};
12711271
groupProperties = groupProperties || {};
1272+
12721273
var event = {
12731274
device_id: this.options.deviceId,
12741275
user_id: this.options.userId,
@@ -1297,6 +1298,14 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
12971298
user_agent: this._userAgent,
12981299
};
12991300

1301+
if (_isObservePlanSet(this)) {
1302+
event.plan = {
1303+
branch: this.options.plan.branch || undefined,
1304+
source: this.options.plan.source || undefined,
1305+
version: this.options.plan.version || undefined,
1306+
};
1307+
}
1308+
13001309
if (eventType === Constants.IDENTIFY_EVENT || eventType === Constants.GROUP_IDENTIFY_EVENT) {
13011310
this._unsentIdentifys.push({ event, callback, errorCallback });
13021311
this._limitEventsQueued(this._unsentIdentifys);
@@ -1317,6 +1326,10 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
13171326
}
13181327
};
13191328

1329+
const _isObservePlanSet = function _isObservePlanSet(scope) {
1330+
return scope.options.plan && (scope.options.plan.source || scope.options.plan.branch || scope.options.plan.version);
1331+
};
1332+
13201333
var _shouldTrackField = function _shouldTrackField(scope, field) {
13211334
return !!scope.options.trackingOptions[field];
13221335
};

src/options.js

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import language from './language';
2828
* @property {boolean} [optOut=`false`] - Whether or not to disable tracking for the current user.
2929
* @property {function} [onError=`() => {}`] - Function to call on error.
3030
* @property {function} [onExitPage=`() => {}`] - Function called when the user exits the browser. Useful logging on page exit.
31+
* @property {Object} [plan] Tracking plan properties
32+
* @property {string} [plan.branch] The tracking plan branch name e.g. "main"
33+
* @property {string} [plan.source] The tracking plan source e.g. "web"
34+
* @property {string} [plan.version] The tracking plan version e.g. "1", "15"
3135
* @property {string} [platform=`Web`] - Platform device is running on. Defaults to `Web` (browser, including mobile browsers).
3236
* @property {number} [savedMaxCount=`1000`] - Maximum number of events to save in localStorage. If more events are logged while offline, then old events are removed.
3337
* @property {boolean} [saveEvents=`true`] - If `true`, saves events to localStorage and removes them upon successful upload. *Note: Without saving events, events may be lost if the user navigates to another page before the events are uploaded.*
@@ -67,6 +71,11 @@ export default {
6771
optOut: false,
6872
onError: () => {},
6973
onExitPage: () => {},
74+
plan: {
75+
branch: '',
76+
source: '',
77+
version: '',
78+
},
7079
platform: 'Web',
7180
savedMaxCount: 1000,
7281
saveEvents: true,

test/amplitude-client.js

+12
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,18 @@ describe('AmplitudeClient', function () {
855855

856856
amplitude.cookieStorage.options.restore();
857857
});
858+
859+
it('should set observer plan options', function () {
860+
var amplitude = new AmplitudeClient('observer plan');
861+
var plan = {
862+
branch: 'my-feature-branch',
863+
source: 'web',
864+
version: '1.0.0',
865+
};
866+
amplitude.init(apiKey, null, { plan: plan });
867+
868+
assert.deepEqual(amplitude.options.plan, plan);
869+
});
858870
});
859871

860872
describe('runQueuedFunctions', function () {

0 commit comments

Comments
 (0)