Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
eventProperties = eventProperties || {};
groups = groups || {};
groupProperties = groupProperties || {};

var event = {
device_id: this.options.deviceId,
user_id: this.options.userId,
Expand Down Expand Up @@ -1297,6 +1298,14 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
user_agent: this._userAgent,
};

if (_isObservePlanSet(this)) {
event.plan = {
branch: this.options.plan.branch || undefined,
source: this.options.plan.source || undefined,
version: this.options.plan.version || undefined,
};
}

if (eventType === Constants.IDENTIFY_EVENT || eventType === Constants.GROUP_IDENTIFY_EVENT) {
this._unsentIdentifys.push({ event, callback, errorCallback });
this._limitEventsQueued(this._unsentIdentifys);
Expand All @@ -1317,6 +1326,10 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
}
};

const _isObservePlanSet = function _isObservePlanSet(scope) {
return scope.options.plan && (scope.options.plan.source || scope.options.plan.branch || scope.options.plan.version);
};

var _shouldTrackField = function _shouldTrackField(scope, field) {
return !!scope.options.trackingOptions[field];
};
Expand Down
9 changes: 9 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import language from './language';
* @property {boolean} [optOut=`false`] - Whether or not to disable tracking for the current user.
* @property {function} [onError=`() => {}`] - Function to call on error.
* @property {function} [onExitPage=`() => {}`] - Function called when the user exits the browser. Useful logging on page exit.
* @property {Object} [plan] Tracking plan properties
* @property {string} [plan.branch] The tracking plan branch name e.g. "main"
* @property {string} [plan.source] The tracking plan source e.g. "web"
* @property {string} [plan.version] The tracking plan version e.g. "1", "15"
* @property {string} [platform=`Web`] - Platform device is running on. Defaults to `Web` (browser, including mobile browsers).
* @property {number} [savedMaxCount=`1000`] - Maximum number of events to save in localStorage. If more events are logged while offline, then old events are removed.
* @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.*
Expand Down Expand Up @@ -67,6 +71,11 @@ export default {
optOut: false,
onError: () => {},
onExitPage: () => {},
plan: {
branch: '',
source: '',
version: '',
},
platform: 'Web',
savedMaxCount: 1000,
saveEvents: true,
Expand Down
12 changes: 12 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ describe('AmplitudeClient', function () {

amplitude.cookieStorage.options.restore();
});

it('should set observer plan options', function () {
var amplitude = new AmplitudeClient('observer plan');
var plan = {
branch: 'my-feature-branch',
source: 'web',
version: '1.0.0',
};
amplitude.init(apiKey, null, { plan: plan });

assert.deepEqual(amplitude.options.plan, plan);
});
});

describe('runQueuedFunctions', function () {
Expand Down