Skip to content

Commit

Permalink
save generated api properties tracking options
Browse files Browse the repository at this point in the history
  • Loading branch information
djih committed Jul 19, 2018
1 parent 34db2d5 commit d68b2c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
try {
this.options.apiKey = apiKey;
this._storageSuffix = '_' + apiKey + this._legacyStorageSuffix;

_parseConfig(this.options, opt_config);
var trackingOptions = _generateApiPropertiesTrackingConfig(this);
this._apiPropertiesTrackingOptions = Object.keys(trackingOptions).length > 0 ? {tracking_options: trackingOptions} : {};

this.cookieStorage.options({
expirationDays: this.options.cookieExpiration,
domain: this.options.domain
Expand Down Expand Up @@ -896,8 +900,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
_saveCookieData(this);

userProperties = userProperties || {};
var trackingOptions = _generateApiPropertiesTrackingConfig(this);
trackingOptions = Object.keys(trackingOptions).length > 0 ? {tracking_options: trackingOptions} : {};
var trackingOptions = merge({}, this._apiPropertiesTrackingOptions);
apiProperties = merge(trackingOptions, (apiProperties || {}));
eventProperties = eventProperties || {};
groups = groups || {};
Expand Down
17 changes: 17 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,23 @@ it ('should load saved events from localStorage new keys and send events', funct
version_name: true
});
});

it('should pregenerate tracking options for api properties', function() {
var trackingOptions = {
city: false,
ip_address: false,
language: false,
region: true,
};

var amplitude2 = new AmplitudeClient('new_app');
amplitude2.init(apiKey, null, {trackingOptions: trackingOptions});

assert.deepEqual(amplitude2._apiPropertiesTrackingOptions, {tracking_options: {
city: false,
ip_address: false
}});
});
});

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

0 comments on commit d68b2c7

Please sign in to comment.