Skip to content

Commit 96d7add

Browse files
committed
Merge pull request #67 from amplitude/fix_cookie_test
fix cookie test key
2 parents 2ffb384 + abfdc10 commit 96d7add

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Add tracking of each user's initial_utm parameters (which is captured as a set once operation). Utm parameters are now sent only once per user session.
44
* Add documentation for SDK functions. You can take a look [here](https://rawgit.com/amplitude/Amplitude-Javascript/defensive_cleanup/documentation/Amplitude.html). A link has also been added to the Readme.
5+
* Fix cookie test bug. In rare cases, the cookie test failed to delete the key used in testing. Reloading the page generated new keys, filling up the cookie over time. Fixed test to re-use the same key.
56

67
### 2.10.0 (March 30, 2016)
78

amplitude.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,9 @@ module.exports = {
11361136
// Used in cookie as well
11371137
DEVICE_ID: 'amplitude_deviceId',
11381138
OPT_OUT: 'amplitude_optOut',
1139-
USER_ID: 'amplitude_userId'
1139+
USER_ID: 'amplitude_userId',
1140+
1141+
COOKIE_TEST: 'amplitude_cookie_test'
11401142
};
11411143

11421144
}, {}],
@@ -1148,6 +1150,7 @@ module.exports = {
11481150
* Uses cookie if available, otherwise fallback to localstorage.
11491151
*/
11501152

1153+
var Constants = require('./constants');
11511154
var Cookie = require('./cookie');
11521155
var JSON = require('json'); // jshint ignore:line
11531156
var localStorage = require('./localstorage'); // jshint ignore:line
@@ -1161,9 +1164,9 @@ cookieStorage.prototype._cookiesEnabled = function() {
11611164
var uid = String(new Date());
11621165
var result;
11631166
try {
1164-
Cookie.set(uid, uid);
1165-
result = Cookie.get(uid) === uid;
1166-
Cookie.remove(uid);
1167+
Cookie.set(Constants.COOKIE_TEST, uid);
1168+
result = Cookie.get(Constants.COOKIE_TEST) === uid;
1169+
Cookie.remove(Constants.COOKIE_TEST);
11671170
return result;
11681171
} catch (e) {
11691172
// cookies are not enabled
@@ -1233,7 +1236,7 @@ cookieStorage.prototype.getStorage = function() {
12331236

12341237
module.exports = cookieStorage;
12351238

1236-
}, {"./cookie":18,"json":7,"./localstorage":8}],
1239+
}, {"./constants":3,"./cookie":18,"json":7,"./localstorage":8}],
12371240
18: [function(require, module, exports) {
12381241
/*
12391242
* Cookie data

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.

src/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ module.exports = {
1515
// Used in cookie as well
1616
DEVICE_ID: 'amplitude_deviceId',
1717
OPT_OUT: 'amplitude_optOut',
18-
USER_ID: 'amplitude_userId'
18+
USER_ID: 'amplitude_userId',
19+
20+
COOKIE_TEST: 'amplitude_cookie_test'
1921
};

src/cookiestorage.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Uses cookie if available, otherwise fallback to localstorage.
66
*/
77

8+
var Constants = require('./constants');
89
var Cookie = require('./cookie');
910
var JSON = require('json'); // jshint ignore:line
1011
var localStorage = require('./localstorage'); // jshint ignore:line
@@ -18,9 +19,9 @@ cookieStorage.prototype._cookiesEnabled = function() {
1819
var uid = String(new Date());
1920
var result;
2021
try {
21-
Cookie.set(uid, uid);
22-
result = Cookie.get(uid) === uid;
23-
Cookie.remove(uid);
22+
Cookie.set(Constants.COOKIE_TEST, uid);
23+
result = Cookie.get(Constants.COOKIE_TEST) === uid;
24+
Cookie.remove(Constants.COOKIE_TEST);
2425
return result;
2526
} catch (e) {
2627
// cookies are not enabled

0 commit comments

Comments
 (0)