From d68b2c71586b932e4642caca69bd8d13396c9ca1 Mon Sep 17 00:00:00 2001 From: Daniel Jih Date: Thu, 19 Jul 2018 16:03:27 -0700 Subject: [PATCH] save generated api properties tracking options --- src/amplitude-client.js | 7 +++++-- test/amplitude-client.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/amplitude-client.js b/src/amplitude-client.js index 4ccf568d..adbf6a63 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -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 @@ -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 || {}; diff --git a/test/amplitude-client.js b/test/amplitude-client.js index b0cd39cc..c39a042e 100644 --- a/test/amplitude-client.js +++ b/test/amplitude-client.js @@ -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() {