Skip to content

Commit 75b536b

Browse files
authored
Merge pull request #211 from sputh/fix/null-keys
Fix issue where AsyncStorage can't re-set unsentEventString nor unsen…
2 parents b06134c + 2f05e67 commit 75b536b

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 5.7.1 (December 2, 2019)
2+
* Fix issue where null unsentKey and unsentIdentifyKeys were causing log crashes
3+
14
### 5.7.0 (November 22, 2019)
25
* Namespace AsyncStorage with api key to prevent cross domain contamination
36

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": "5.7.0",
4+
"version": "5.7.1",
55
"license": "MIT",
66
"description": "Javascript library for Amplitude Analytics",
77
"keywords": [

src/amplitude-client.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,31 @@ AmplitudeClient.prototype._migrateUnsentEvents = function _migrateUnsentEvents(c
238238
if (this.options.saveEvents) {
239239
var unsentEventsString = values[0];
240240
var unsentIdentifyKey = values[1];
241-
Promise.all([
242-
AsyncStorage.setItem(this.options.unsentKey + this._storageSuffix, unsentEventsString),
243-
AsyncStorage.setItem(this.options.unsentIdentifyKey + this._storageSuffix, unsentIdentifyKey),
244-
]).then(() => {
245-
Promise.all([
246-
AsyncStorage.removeItem(this.options.unsentKey),
247-
AsyncStorage.removeItem(this.options.unsentIdentifyKey),
248-
]).then(cb);
249-
}).catch((err) => {
250-
this.options.onError(err);
251-
});
241+
242+
var itemsToSet = [];
243+
var itemsToRemove = [];
244+
245+
if (!!unsentEventsString) {
246+
itemsToSet.push(AsyncStorage.setItem(this.options.unsentKey + this._storageSuffix, JSON.stringify(unsentEventsString)));
247+
itemsToRemove.push(AsyncStorage.removeItem(this.options.unsentKey));
248+
}
249+
250+
if (!!unsentIdentifyKey) {
251+
itemsToSet.push(AsyncStorage.setItem(this.options.unsentIdentifyKey + this._storageSuffix, JSON.stringify(unsentIdentifyKey)));
252+
itemsToRemove.push(AsyncStorage.removeItem(this.options.unsentIdentifyKey));
253+
}
254+
255+
if (itemsToSet.length > 0) {
256+
Promise.all(itemsToSet).then(() => {
257+
Promise.all(itemsToRemove);
258+
}).catch((err) => {
259+
this.options.onError(err);
260+
});
261+
}
252262
}
253-
}).catch((err) => {
263+
})
264+
.then(cb)
265+
.catch((err) => {
254266
this.options.onError(err);
255267
});
256268
};

0 commit comments

Comments
 (0)