Skip to content

Commit d68b2c7

Browse files
committed
save generated api properties tracking options
1 parent 34db2d5 commit d68b2c7

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/amplitude-client.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
6767
try {
6868
this.options.apiKey = apiKey;
6969
this._storageSuffix = '_' + apiKey + this._legacyStorageSuffix;
70+
7071
_parseConfig(this.options, opt_config);
72+
var trackingOptions = _generateApiPropertiesTrackingConfig(this);
73+
this._apiPropertiesTrackingOptions = Object.keys(trackingOptions).length > 0 ? {tracking_options: trackingOptions} : {};
74+
7175
this.cookieStorage.options({
7276
expirationDays: this.options.cookieExpiration,
7377
domain: this.options.domain
@@ -896,8 +900,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
896900
_saveCookieData(this);
897901

898902
userProperties = userProperties || {};
899-
var trackingOptions = _generateApiPropertiesTrackingConfig(this);
900-
trackingOptions = Object.keys(trackingOptions).length > 0 ? {tracking_options: trackingOptions} : {};
903+
var trackingOptions = merge({}, this._apiPropertiesTrackingOptions);
901904
apiProperties = merge(trackingOptions, (apiProperties || {}));
902905
eventProperties = eventProperties || {};
903906
groups = groups || {};

test/amplitude-client.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,23 @@ it ('should load saved events from localStorage new keys and send events', funct
736736
version_name: true
737737
});
738738
});
739+
740+
it('should pregenerate tracking options for api properties', function() {
741+
var trackingOptions = {
742+
city: false,
743+
ip_address: false,
744+
language: false,
745+
region: true,
746+
};
747+
748+
var amplitude2 = new AmplitudeClient('new_app');
749+
amplitude2.init(apiKey, null, {trackingOptions: trackingOptions});
750+
751+
assert.deepEqual(amplitude2._apiPropertiesTrackingOptions, {tracking_options: {
752+
city: false,
753+
ip_address: false
754+
}});
755+
});
739756
});
740757

741758
describe('runQueuedFunctions', function() {

0 commit comments

Comments
 (0)