Skip to content

Commit 2fe8235

Browse files
committed
allow tracking option config input
1 parent 1056024 commit 2fe8235

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

src/amplitude-client.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ var _parseConfig = function _parseConfig(options, config) {
166166

167167
// validates config value is defined, is the correct type, and some additional value sanity checks
168168
var parseValidateAndLoad = function parseValidateAndLoad(key) {
169-
if (!DEFAULT_OPTIONS.hasOwnProperty(key)) {
169+
if (!options.hasOwnProperty(key)) {
170170
return; // skip bogus config values
171171
}
172172

173173
var inputValue = config[key];
174-
var expectedType = type(DEFAULT_OPTIONS[key]);
174+
var expectedType = type(options[key]);
175175
if (!utils.validateInput(inputValue, key + ' option', expectedType)) {
176176
return;
177177
}
@@ -180,14 +180,16 @@ var _parseConfig = function _parseConfig(options, config) {
180180
} else if ((expectedType === 'string' && !utils.isEmptyString(inputValue)) ||
181181
(expectedType === 'number' && inputValue > 0)) {
182182
options[key] = inputValue;
183+
} else if (expectedType === 'object') {
184+
_parseConfig(options[key], inputValue);
183185
}
184-
};
186+
};
185187

186-
for (var key in config) {
188+
for (var key in config) {
187189
if (config.hasOwnProperty(key)) {
188190
parseValidateAndLoad(key);
189191
}
190-
}
192+
}
191193
};
192194

193195
/**
@@ -921,7 +923,6 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
921923
sequence_number: sequenceNumber, // for ordering events and identifys
922924
groups: utils.truncate(utils.validateGroups(groups)),
923925
user_agent: this._userAgent
924-
// country: null
925926
};
926927

927928
if (eventType === Constants.IDENTIFY_EVENT) {

src/options.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import language from './language';
33
// default options
44
export default {
55
apiEndpoint: 'api.amplitude.com',
6+
batchEvents: false,
67
cookieExpiration: 365 * 10,
78
cookieName: 'amplitude_id',
9+
deviceIdFromUrlParam: false,
810
domain: '',
11+
eventUploadPeriodMillis: 30 * 1000, // 30s
12+
eventUploadThreshold: 30,
13+
forceHttps: true,
14+
includeGclid: false,
915
includeReferrer: false,
1016
includeUtm: false,
1117
language: language.language,
@@ -14,15 +20,21 @@ export default {
1420
platform: 'Web',
1521
savedMaxCount: 1000,
1622
saveEvents: true,
23+
saveParamsReferrerOncePerSession: true,
1724
sessionTimeout: 30 * 60 * 1000,
25+
trackingOptions: {
26+
city: true,
27+
device_model: true,
28+
dma: true,
29+
ip_address: true,
30+
language: true,
31+
os_name: true,
32+
os_version: true,
33+
platform: true,
34+
region: true,
35+
version_name: true
36+
},
1837
unsentKey: 'amplitude_unsent',
1938
unsentIdentifyKey: 'amplitude_unsent_identify',
2039
uploadBatchSize: 100,
21-
batchEvents: false,
22-
eventUploadThreshold: 30,
23-
eventUploadPeriodMillis: 30 * 1000, // 30s
24-
forceHttps: true,
25-
includeGclid: false,
26-
saveParamsReferrerOncePerSession: true,
27-
deviceIdFromUrlParam: false,
2840
};

test/amplitude-client.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,32 @@ it ('should load saved events from localStorage new keys and send events', funct
709709
// check request
710710
assert.lengthOf(server.requests, 0);
711711
});
712+
713+
it('should merge tracking options during parseConfig', function() {
714+
var trackingOptions = {
715+
city: false,
716+
ip_address: false,
717+
language: false,
718+
region: true,
719+
};
720+
721+
var amplitude2 = new AmplitudeClient('new_app');
722+
amplitude2.init(apiKey, null, {trackingOptions: trackingOptions});
723+
724+
// check config loaded correctly
725+
assert.deepEqual(amplitude2.options.trackingOptions, {
726+
city: false,
727+
device_model: true,
728+
dma: true,
729+
ip_address: false,
730+
language: false,
731+
os_name: true,
732+
os_version: true,
733+
platform: true,
734+
region: true,
735+
version_name: true
736+
});
737+
});
712738
});
713739

714740
describe('runQueuedFunctions', function() {

0 commit comments

Comments
 (0)