Skip to content

Commit 2a401fd

Browse files
committed
update from master
2 parents 06b1ab4 + 4823fb6 commit 2a401fd

File tree

10 files changed

+119
-2098
lines changed

10 files changed

+119
-2098
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
### 2.9.1 (March 6, 2016)
4+
35
* Fix bug where saveReferrer throws exception if sessionStorage is disabled.
46
* Log messages with a try/catch to support IE 8.
57
* Validate event properties during logEvent and initialization before sending request.

amplitude.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,12 +2289,10 @@ var validatePropertyValue = function(key, value) {
22892289
if (invalidValueTypes.indexOf(valueType) !== -1) {
22902290
log('WARNING: Property key "' + key + '" with invalid value type ' + valueType + ', ignoring');
22912291
value = null;
2292-
}
2293-
else if (valueType === 'error') {
2292+
} else if (valueType === 'error') {
22942293
value = String(value);
22952294
log('WARNING: Property key "' + key + '" with value type error, coercing to ' + value);
2296-
}
2297-
else if (valueType === 'array') {
2295+
} else if (valueType === 'array') {
22982296
// check for nested arrays or objects
22992297
var arrayCopy = [];
23002298
for (var i = 0; i < value.length; i++) {
@@ -2307,8 +2305,7 @@ var validatePropertyValue = function(key, value) {
23072305
arrayCopy.push(validatePropertyValue(key, element));
23082306
}
23092307
value = arrayCopy;
2310-
}
2311-
else if (valueType === 'object') {
2308+
} else if (valueType === 'object') {
23122309
value = validateProperties(value);
23132310
}
23142311
return value;
@@ -3805,7 +3802,7 @@ module.exports = uuid;
38053802

38063803
}, {}],
38073804
15: [function(require, module, exports) {
3808-
module.exports = '2.9.0';
3805+
module.exports = '2.9.1';
38093806

38103807
}, {}],
38113808
16: [function(require, module, exports) {

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"main": "src/index.js",
44
"repo": "amplitude/amplitude-javascript",
55
"description": "Javascript library for Amplitude Analytics",
6-
"version": "2.9.0",
6+
"version": "2.9.1",
77
"keywords": [
88
"analytics",
99
"amplitude"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "amplitude-js",
33
"author": "Amplitude <support@amplitude.com>",
4-
"version": "2.9.0",
4+
"version": "2.9.1",
55
"license": "MIT",
66
"description": "Javascript library for Amplitude Analytics",
77
"keywords": [

src/utils.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ var validatePropertyValue = function(key, value) {
5252
if (invalidValueTypes.indexOf(valueType) !== -1) {
5353
log('WARNING: Property key "' + key + '" with invalid value type ' + valueType + ', ignoring');
5454
value = null;
55-
}
56-
else if (valueType === 'error') {
55+
} else if (valueType === 'error') {
5756
value = String(value);
5857
log('WARNING: Property key "' + key + '" with value type error, coercing to ' + value);
59-
}
60-
else if (valueType === 'array') {
58+
} else if (valueType === 'array') {
6159
// check for nested arrays or objects
6260
var arrayCopy = [];
6361
for (var i = 0; i < value.length; i++) {
@@ -70,8 +68,7 @@ var validatePropertyValue = function(key, value) {
7068
arrayCopy.push(validatePropertyValue(key, element));
7169
}
7270
value = arrayCopy;
73-
}
74-
else if (valueType === 'object') {
71+
} else if (valueType === 'object') {
7572
value = validateProperties(value);
7673
}
7774
return value;

src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = '2.9.0';
1+
module.exports = '2.9.1';

test/amplitude.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,50 @@ describe('Amplitude', function() {
394394
assert.equal(events[0].event_id, 49);
395395
assert.equal(events[1].event_type, '$identify');
396396
});
397+
398+
it('should validate event properties when loading saved events from localStorage', function() {
399+
var existingEvents = '[{"device_id":"15a82aaa-0d9e-4083-a32d-2352191877e6","user_id":"15a82aaa-0d9e-4083-a32d' +
400+
'-2352191877e6","timestamp":1455744744413,"event_id":2,"session_id":1455744733865,"event_type":"clicked",' +
401+
'"version_name":"Web","platform":"Web","os_name":"Chrome","os_version":"48","device_model":"Mac","language"' +
402+
':"en-US","api_properties":{},"event_properties":"{}","user_properties":{},"uuid":"1b8859d9-e91e-403e-92d4-' +
403+
'c600dfb83432","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":4},{"device_id":"15a82a' +
404+
'aa-0d9e-4083-a32d-2352191877e6","user_id":"15a82aaa-0d9e-4083-a32d-2352191877e6","timestamp":1455744746295,' +
405+
'"event_id":3,"session_id":1455744733865,"event_type":"clicked","version_name":"Web","platform":"Web",' +
406+
'"os_name":"Chrome","os_version":"48","device_model":"Mac","language":"en-US","api_properties":{},' +
407+
'"event_properties":{"10":"false","bool":true,"null":null,"string":"test","array":' +
408+
'[0,1,2,"3"],"nested_array":["a",{"key":"value"},["b"]],"object":{"key":"value"},"nested_object":' +
409+
'{"k":"v","l":[0,1],"o":{"k2":"v2","l2":["e2",{"k3":"v3"}]}}},"user_properties":{},"uuid":"650407a1-d705-' +
410+
'47a0-8918-b4530ce51f89","library":{"name":"amplitude-js","version":"2.9.0"},"sequence_number":5}]';
411+
localStorage.setItem('amplitude_unsent', existingEvents);
412+
413+
var amplitude2 = new Amplitude();
414+
amplitude2.init(apiKey, null, {
415+
batchEvents: true
416+
});
417+
418+
var expected = {
419+
'10': 'false',
420+
'bool': true,
421+
'string': 'test',
422+
'array': [0, 1, 2, '3'],
423+
'nested_array': ['a'],
424+
'object': {
425+
'key': 'value'
426+
},
427+
'nested_object': {
428+
'k': 'v',
429+
'l': [0, 1],
430+
'o': {
431+
'k2': 'v2',
432+
'l2': ['e2']
433+
}
434+
}
435+
}
436+
437+
// check that event loaded into memory
438+
assert.deepEqual(amplitude2._unsentEvents[0].event_properties, {});
439+
assert.deepEqual(amplitude2._unsentEvents[1].event_properties, expected);
440+
});
397441
});
398442

399443
describe('runQueuedFunctions', function() {
@@ -1628,7 +1672,7 @@ describe('Amplitude', function() {
16281672
10: 'false', // coerce key
16291673
'bool': true,
16301674
'null': null, // should be ignored
1631-
'function': utils.log, // should be ignored
1675+
'function': console.log, // should be ignored
16321676
'regex': /afdg/, // should be ignored
16331677
'error': e, // coerce value
16341678
'string': 'test',

0 commit comments

Comments
 (0)