forked from pushtell/react-ab-test
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathstoreCookie.jsx
More file actions
28 lines (27 loc) · 803 Bytes
/
storeCookie.jsx
File metadata and controls
28 lines (27 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const storeCookie = () => {
const cookieStorage = {
getCookie: function (c_name) {
let c_value = document.cookie,
c_start = c_value.indexOf(' ' + c_name + '=');
if (c_start == -1) c_start = c_value.indexOf(c_name + '=');
if (c_start == -1) {
c_value = null;
} else {
c_start = c_value.indexOf('=', c_start) + 1;
var c_end = c_value.indexOf(';', c_start);
if (c_end == -1) {
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start, c_end));
}
return c_value;
},
setCookie: function (c_name, variantName) {
if (!this.getCookie(c_name)) {
document.cookie = c_name + '=' + variantName;
}
},
};
return cookieStorage;
};
export default storeCookie;