Skip to content

Commit 772cec5

Browse files
committed
final cleanup
1 parent 744ad1b commit 772cec5

File tree

10 files changed

+79
-112
lines changed

10 files changed

+79
-112
lines changed

amplitude.js

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,17 @@ var _parseConfig = function _parseConfig(options, config) {
235235
return;
236236
}
237237

238-
// verifies config value is defined, is the correct type, and some additional value verification
238+
// validates config value is defined, is the correct type, and some additional value sanity checks
239239
var parseValidateLoad = function parseValidateLoad(key, expectedType) {
240-
var input_value = config[key];
241-
if(input_value === undefined || !utils.validateInput(input_value, key + ' option', expectedType)) {
240+
var inputValue = config[key];
241+
if (inputValue === undefined || !utils.validateInput(inputValue, key + ' option', expectedType)) {
242242
return;
243243
}
244244
if (expectedType === 'boolean') {
245-
options[key] = !!input_value;
246-
} else {
247-
options[key] = (expectedType === 'string' && !utils.isEmptyString(input_value) && input_value) ||
248-
(expectedType === 'number' && config[key] > 0 && input_value) ||
249-
options[key];
245+
options[key] = !!inputValue;
246+
} else if ((expectedType === 'string' && !utils.isEmptyString(inputValue)) ||
247+
(expectedType === 'number' && inputValue > 0)) {
248+
options[key] = inputValue;
250249
}
251250
};
252251

@@ -289,7 +288,7 @@ Amplitude.prototype._apiKeySet = function _apiKeySet(methodName) {
289288
* @private
290289
*/
291290
Amplitude.prototype._loadSavedUnsentEvents = function _loadSavedUnsentEvents(unsentKey) {
292-
var savedUnsentEventsString = localStorage.getItem(unsentKey);
291+
var savedUnsentEventsString = this._getFromStorage(localStorage, unsentKey);
293292
if (utils.isEmptyString(savedUnsentEventsString)) {
294293
return []; // new app, does not have any saved events
295294
}
@@ -397,7 +396,6 @@ Amplitude.prototype._sendEventsIfReady = function _sendEventsIfReady(callback) {
397396
* Helper function to fetch values from storage
398397
* Storage argument allows for localStoraoge and sessionStoraoge
399398
* @private
400-
* @deprecated
401399
*/
402400
Amplitude.prototype._getFromStorage = function _getFromStorage(storage, key) {
403401
return storage.getItem(key);
@@ -407,10 +405,9 @@ Amplitude.prototype._getFromStorage = function _getFromStorage(storage, key) {
407405
* Helper function to set values in storage
408406
* Storage argument allows for localStoraoge and sessionStoraoge
409407
* @private
410-
* @deprecated
411408
*/
412-
Amplitude.prototype._setInStorage = function _setInStorage(storage, key) {
413-
storage.setItem(key);
409+
Amplitude.prototype._setInStorage = function _setInStorage(storage, key, value) {
410+
storage.setItem(key, value);
414411
};
415412

416413
/**
@@ -549,15 +546,15 @@ var _sendUserPropertiesOncePerSession = function _sendUserPropertiesOncePerSessi
549546

550547
// only save userProperties if not already in sessionStorage under key or if storage disabled
551548
var hasSessionStorage = utils.sessionStorageEnabled();
552-
if ((hasSessionStorage && !(sessionStorage.getItem(storageKey))) || !hasSessionStorage) {
549+
if ((hasSessionStorage && !(scope._getFromStorage(sessionStorage, storageKey))) || !hasSessionStorage) {
553550
for (var property in userProperties) {
554551
if (userProperties.hasOwnProperty(property)) {
555552
identify.set(property, userProperties[property]);
556553
}
557554
}
558555

559556
if (hasSessionStorage) {
560-
sessionStorage.setItem(storageKey, JSON.stringify(userProperties));
557+
scope._setInStorage(sessionStorage, storageKey, JSON.stringify(userProperties));
561558
}
562559
}
563560

@@ -608,16 +605,12 @@ Amplitude.prototype._saveReferrer = function _saveReferrer(referrer) {
608605
* @private
609606
*/
610607
Amplitude.prototype.saveEvents = function saveEvents() {
611-
if (!this._apiKeySet('saveEvents()')) {
612-
return;
613-
}
614-
615608
try {
616-
localStorage.setItem(this.options.unsentKey, JSON.stringify(this._unsentEvents));
609+
this._setInStorage(localStorage, this.options.unsentKey, JSON.stringify(this._unsentEvents));
617610
} catch (e) {}
618611

619612
try {
620-
localStorage.setItem(this.options.unsentIdentifyKey, JSON.stringify(this._unsentIdentifys));
613+
this._setInStorage(localStorage, this.options.unsentIdentifyKey, JSON.stringify(this._unsentIdentifys));
621614
} catch (e) {}
622615
};
623616

@@ -628,7 +621,7 @@ Amplitude.prototype.saveEvents = function saveEvents() {
628621
* @example amplitude.setDomain('.amplitude.com');
629622
*/
630623
Amplitude.prototype.setDomain = function setDomain(domain) {
631-
if (!this._apiKeySet('setDomain()') || !utils.validateInput(domain, 'domain', 'string')) {
624+
if (!utils.validateInput(domain, 'domain', 'string')) {
632625
return;
633626
}
634627

@@ -651,10 +644,6 @@ Amplitude.prototype.setDomain = function setDomain(domain) {
651644
* @example amplitude.setUserId('joe@gmail.com');
652645
*/
653646
Amplitude.prototype.setUserId = function setUserId(userId) {
654-
if (!this._apiKeySet('setUserId()')) {
655-
return;
656-
}
657-
658647
try {
659648
this.options.userId = (userId !== undefined && userId !== null && ('' + userId)) || null;
660649
_saveCookieData(this);
@@ -670,7 +659,7 @@ Amplitude.prototype.setUserId = function setUserId(userId) {
670659
* @example: amplitude.setOptOut(true);
671660
*/
672661
Amplitude.prototype.setOptOut = function setOptOut(enable) {
673-
if (!this._apiKeySet('setOptOut()') || !utils.validateInput(enable, 'enable', 'boolean')) {
662+
if (!utils.validateInput(enable, 'enable', 'boolean')) {
674663
return;
675664
}
676665

@@ -691,7 +680,7 @@ Amplitude.prototype.setOptOut = function setOptOut(enable) {
691680
* @example amplitude.setDeviceId('45f0954f-eb79-4463-ac8a-233a6f45a8f0');
692681
*/
693682
Amplitude.prototype.setDeviceId = function setDeviceId(deviceId) {
694-
if (!this._apiKeySet('setDeviceId()') || !utils.validateInput(deviceId, 'deviceId', 'string')) {
683+
if (!utils.validateInput(deviceId, 'deviceId', 'string')) {
695684
return;
696685
}
697686

@@ -1128,7 +1117,7 @@ module.exports = Amplitude;
11281117
3: [function(require, module, exports) {
11291118
module.exports = {
11301119
API_VERSION: 2,
1131-
MAX_STRING_LENGTH: 1024,
1120+
MAX_STRING_LENGTH: 4096,
11321121
IDENTIFY_EVENT: '$identify',
11331122

11341123
// localStorageKeys

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/Amplitude.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ <h4 class="name" id="__VERSION__"><span class="type-signature"></span>__VERSION_
184184

185185
<dt class="tag-source">Source:</dt>
186186
<dd class="tag-source"><ul class="dummy"><li>
187-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line1017">line 1017</a>
187+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line1006">line 1006</a>
188188
</li></ul></dd>
189189

190190

@@ -267,7 +267,7 @@ <h4 class="name" id="clearUserProperties"><span class="type-signature"></span>cl
267267

268268
<dt class="tag-source">Source:</dt>
269269
<dd class="tag-source"><ul class="dummy"><li>
270-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line629">line 629</a>
270+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line618">line 618</a>
271271
</li></ul></dd>
272272

273273

@@ -354,7 +354,7 @@ <h4 class="name" id="getSessionId"><span class="type-signature"></span>getSessio
354354

355355
<dt class="tag-source">Source:</dt>
356356
<dd class="tag-source"><ul class="dummy"><li>
357-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line217">line 217</a>
357+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line216">line 216</a>
358358
</li></ul></dd>
359359

360360

@@ -533,7 +533,7 @@ <h5>Parameters:</h5>
533533

534534
<dt class="tag-source">Source:</dt>
535535
<dd class="tag-source"><ul class="dummy"><li>
536-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line650">line 650</a>
536+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line639">line 639</a>
537537
</li></ul></dd>
538538

539539

@@ -828,7 +828,7 @@ <h4 class="name" id="isNewSession"><span class="type-signature"></span>isNewSess
828828

829829
<dt class="tag-source">Source:</dt>
830830
<dd class="tag-source"><ul class="dummy"><li>
831-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line208">line 208</a>
831+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line207">line 207</a>
832832
</li></ul></dd>
833833

834834

@@ -1028,7 +1028,7 @@ <h5>Parameters:</h5>
10281028

10291029
<dt class="tag-source">Source:</dt>
10301030
<dd class="tag-source"><ul class="dummy"><li>
1031-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line802">line 802</a>
1031+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line791">line 791</a>
10321032
</li></ul></dd>
10331033

10341034

@@ -1210,7 +1210,7 @@ <h5>Parameters:</h5>
12101210

12111211
<dt class="tag-source">Source:</dt>
12121212
<dd class="tag-source"><ul class="dummy"><li>
1213-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line829">line 829</a>
1213+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line818">line 818</a>
12141214
</li></ul></dd>
12151215

12161216

@@ -1348,7 +1348,7 @@ <h5>Parameters:</h5>
13481348

13491349
<dt class="tag-source">Source:</dt>
13501350
<dd class="tag-source"><ul class="dummy"><li>
1351-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line587">line 587</a>
1351+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line576">line 576</a>
13521352
</li></ul></dd>
13531353

13541354

@@ -1484,7 +1484,7 @@ <h5>Parameters:</h5>
14841484

14851485
<dt class="tag-source">Source:</dt>
14861486
<dd class="tag-source"><ul class="dummy"><li>
1487-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line524">line 524</a>
1487+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line517">line 517</a>
14881488
</li></ul></dd>
14891489

14901490

@@ -1573,7 +1573,7 @@ <h4 class="name" id="setGlobalUserProperties"><span class="type-signature"></spa
15731573

15741574
<dt class="tag-source">Source:</dt>
15751575
<dd class="tag-source"><ul class="dummy"><li>
1576-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line1007">line 1007</a>
1576+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line996">line 996</a>
15771577
</li></ul></dd>
15781578

15791579

@@ -1704,7 +1704,7 @@ <h5>Parameters:</h5>
17041704

17051705
<dt class="tag-source">Source:</dt>
17061706
<dd class="tag-source"><ul class="dummy"><li>
1707-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line566">line 566</a>
1707+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line555">line 555</a>
17081708
</li></ul></dd>
17091709

17101710

@@ -1835,7 +1835,7 @@ <h5>Parameters:</h5>
18351835

18361836
<dt class="tag-source">Source:</dt>
18371837
<dd class="tag-source"><ul class="dummy"><li>
1838-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line547">line 547</a>
1838+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line540">line 540</a>
18391839
</li></ul></dd>
18401840

18411841

@@ -1995,7 +1995,7 @@ <h5>Parameters:</h5>
19951995

19961996
<dt class="tag-source">Source:</dt>
19971997
<dd class="tag-source"><ul class="dummy"><li>
1998-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line610">line 610</a>
1998+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line599">line 599</a>
19991999
</li></ul></dd>
20002000

20012001

@@ -2131,7 +2131,7 @@ <h5>Parameters:</h5>
21312131

21322132
<dt class="tag-source">Source:</dt>
21332133
<dd class="tag-source"><ul class="dummy"><li>
2134-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line690">line 690</a>
2134+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line679">line 679</a>
21352135
</li></ul></dd>
21362136

21372137

@@ -2297,7 +2297,7 @@ <h5>Parameters:</h5>
22972297

22982298
<dt class="tag-source">Source:</dt>
22992299
<dd class="tag-source"><ul class="dummy"><li>
2300-
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line785">line 785</a>
2300+
<a href="amplitude.js.html">amplitude.js</a>, <a href="amplitude.js.html#line774">line 774</a>
23012301
</li></ul></dd>
23022302

23032303

@@ -2343,7 +2343,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
23432343
<br class="clear">
23442344

23452345
<footer>
2346-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 04 2016 17:24:30 GMT-0700 (PDT)
2346+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
23472347
</footer>
23482348

23492349
<script> prettyPrint(); </script>

documentation/Identify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
12951295
<br class="clear">
12961296

12971297
<footer>
1298-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 04 2016 17:24:30 GMT-0700 (PDT)
1298+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 05 2016 00:06:12 GMT-0700 (PDT)
12991299
</footer>
13001300

13011301
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)