Skip to content

Commit 0e199bd

Browse files
authored
Merge pull request #73 from mixpanel/fix-cookie-set
Fix cookie set function
2 parents 40c158c + 1256064 commit 0e199bd

File tree

14 files changed

+319
-129
lines changed

14 files changed

+319
-129
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
**2.9.4** (22 Jul 2016)
2+
- Cookie setting fix: return cookie setting function to its previous functionality of using days instead of seconds
3+
14
**2.9.3** (19 Jul 2016)
25
- Autotrack: small tweaks
36

build/mixpanel.amd.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ define(function () { 'use strict';
22

33
var Config = {
44
DEBUG: false,
5-
LIB_VERSION: '2.9.3'
5+
LIB_VERSION: '2.9.4'
66
};
77

88
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -951,7 +951,7 @@ define(function () { 'use strict';
951951
return cookie;
952952
},
953953

954-
set: function(name, value, seconds, cross_subdomain, is_secure) {
954+
set_seconds: function(name, value, seconds, cross_subdomain, is_secure) {
955955
var cdomain = '',
956956
expires = '',
957957
secure = '';
@@ -976,6 +976,29 @@ define(function () { 'use strict';
976976
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
977977
},
978978

979+
set: function(name, value, days, cross_subdomain, is_secure) {
980+
var cdomain = '', expires = '', secure = '';
981+
982+
if (cross_subdomain) {
983+
var matches = document$1.location.hostname.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i),
984+
domain = matches ? matches[0] : '';
985+
986+
cdomain = ((domain) ? '; domain=.' + domain : '');
987+
}
988+
989+
if (days) {
990+
var date = new Date();
991+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
992+
expires = '; expires=' + date.toGMTString();
993+
}
994+
995+
if (is_secure) {
996+
secure = '; secure';
997+
}
998+
999+
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
1000+
},
1001+
9791002
remove: function(name, cross_subdomain) {
9801003
_.cookie.set(name, '', -1, cross_subdomain);
9811004
}
@@ -1863,7 +1886,7 @@ define(function () { 'use strict';
18631886
if (!isNaN(secondsToDisable) && secondsToDisable > 0) {
18641887
var disableUntil = _.timestamp() + (secondsToDisable * 1000);
18651888
console.log('disabling CE for ' + secondsToDisable + ' seconds (from ' + _.timestamp() + ' until ' + disableUntil + ')');
1866-
_.cookie.set(DISABLE_COOKIE, true, secondsToDisable, true);
1889+
_.cookie.set_seconds(DISABLE_COOKIE, true, secondsToDisable, true);
18671890
}
18681891
},
18691892

build/mixpanel.cjs.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var Config = {
44
DEBUG: false,
5-
LIB_VERSION: '2.9.3'
5+
LIB_VERSION: '2.9.4'
66
};
77

88
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -951,7 +951,7 @@ _.cookie = {
951951
return cookie;
952952
},
953953

954-
set: function(name, value, seconds, cross_subdomain, is_secure) {
954+
set_seconds: function(name, value, seconds, cross_subdomain, is_secure) {
955955
var cdomain = '',
956956
expires = '',
957957
secure = '';
@@ -976,6 +976,29 @@ _.cookie = {
976976
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
977977
},
978978

979+
set: function(name, value, days, cross_subdomain, is_secure) {
980+
var cdomain = '', expires = '', secure = '';
981+
982+
if (cross_subdomain) {
983+
var matches = document$1.location.hostname.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i),
984+
domain = matches ? matches[0] : '';
985+
986+
cdomain = ((domain) ? '; domain=.' + domain : '');
987+
}
988+
989+
if (days) {
990+
var date = new Date();
991+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
992+
expires = '; expires=' + date.toGMTString();
993+
}
994+
995+
if (is_secure) {
996+
secure = '; secure';
997+
}
998+
999+
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
1000+
},
1001+
9791002
remove: function(name, cross_subdomain) {
9801003
_.cookie.set(name, '', -1, cross_subdomain);
9811004
}
@@ -1863,7 +1886,7 @@ var ce = {
18631886
if (!isNaN(secondsToDisable) && secondsToDisable > 0) {
18641887
var disableUntil = _.timestamp() + (secondsToDisable * 1000);
18651888
console.log('disabling CE for ' + secondsToDisable + ' seconds (from ' + _.timestamp() + ' until ' + disableUntil + ')');
1866-
_.cookie.set(DISABLE_COOKIE, true, secondsToDisable, true);
1889+
_.cookie.set_seconds(DISABLE_COOKIE, true, secondsToDisable, true);
18671890
}
18681891
},
18691892

build/mixpanel.globals.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
var Config = {
55
DEBUG: false,
6-
LIB_VERSION: '2.9.3'
6+
LIB_VERSION: '2.9.4'
77
};
88

99
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -952,7 +952,7 @@
952952
return cookie;
953953
},
954954

955-
set: function(name, value, seconds, cross_subdomain, is_secure) {
955+
set_seconds: function(name, value, seconds, cross_subdomain, is_secure) {
956956
var cdomain = '',
957957
expires = '',
958958
secure = '';
@@ -977,6 +977,29 @@
977977
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
978978
},
979979

980+
set: function(name, value, days, cross_subdomain, is_secure) {
981+
var cdomain = '', expires = '', secure = '';
982+
983+
if (cross_subdomain) {
984+
var matches = document$1.location.hostname.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i),
985+
domain = matches ? matches[0] : '';
986+
987+
cdomain = ((domain) ? '; domain=.' + domain : '');
988+
}
989+
990+
if (days) {
991+
var date = new Date();
992+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
993+
expires = '; expires=' + date.toGMTString();
994+
}
995+
996+
if (is_secure) {
997+
secure = '; secure';
998+
}
999+
1000+
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
1001+
},
1002+
9801003
remove: function(name, cross_subdomain) {
9811004
_.cookie.set(name, '', -1, cross_subdomain);
9821005
}
@@ -1864,7 +1887,7 @@
18641887
if (!isNaN(secondsToDisable) && secondsToDisable > 0) {
18651888
var disableUntil = _.timestamp() + (secondsToDisable * 1000);
18661889
console.log('disabling CE for ' + secondsToDisable + ' seconds (from ' + _.timestamp() + ' until ' + disableUntil + ')');
1867-
_.cookie.set(DISABLE_COOKIE, true, secondsToDisable, true);
1890+
_.cookie.set_seconds(DISABLE_COOKIE, true, secondsToDisable, true);
18681891
}
18691892
},
18701893

build/mixpanel.umd.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var Config = {
88
DEBUG: false,
9-
LIB_VERSION: '2.9.3'
9+
LIB_VERSION: '2.9.4'
1010
};
1111

1212
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -955,7 +955,7 @@
955955
return cookie;
956956
},
957957

958-
set: function(name, value, seconds, cross_subdomain, is_secure) {
958+
set_seconds: function(name, value, seconds, cross_subdomain, is_secure) {
959959
var cdomain = '',
960960
expires = '',
961961
secure = '';
@@ -980,6 +980,29 @@
980980
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
981981
},
982982

983+
set: function(name, value, days, cross_subdomain, is_secure) {
984+
var cdomain = '', expires = '', secure = '';
985+
986+
if (cross_subdomain) {
987+
var matches = document$1.location.hostname.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i),
988+
domain = matches ? matches[0] : '';
989+
990+
cdomain = ((domain) ? '; domain=.' + domain : '');
991+
}
992+
993+
if (days) {
994+
var date = new Date();
995+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
996+
expires = '; expires=' + date.toGMTString();
997+
}
998+
999+
if (is_secure) {
1000+
secure = '; secure';
1001+
}
1002+
1003+
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
1004+
},
1005+
9831006
remove: function(name, cross_subdomain) {
9841007
_.cookie.set(name, '', -1, cross_subdomain);
9851008
}
@@ -1867,7 +1890,7 @@
18671890
if (!isNaN(secondsToDisable) && secondsToDisable > 0) {
18681891
var disableUntil = _.timestamp() + (secondsToDisable * 1000);
18691892
console.log('disabling CE for ' + secondsToDisable + ' seconds (from ' + _.timestamp() + ' until ' + disableUntil + ')');
1870-
_.cookie.set(DISABLE_COOKIE, true, secondsToDisable, true);
1893+
_.cookie.set_seconds(DISABLE_COOKIE, true, secondsToDisable, true);
18711894
}
18721895
},
18731896

examples/commonjs-browserify/bundle.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
var Config = {
55
DEBUG: false,
6-
LIB_VERSION: '2.9.3'
6+
LIB_VERSION: '2.9.4'
77
};
88

99
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
@@ -952,7 +952,7 @@ _.cookie = {
952952
return cookie;
953953
},
954954

955-
set: function(name, value, seconds, cross_subdomain, is_secure) {
955+
set_seconds: function(name, value, seconds, cross_subdomain, is_secure) {
956956
var cdomain = '',
957957
expires = '',
958958
secure = '';
@@ -977,6 +977,29 @@ _.cookie = {
977977
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
978978
},
979979

980+
set: function(name, value, days, cross_subdomain, is_secure) {
981+
var cdomain = '', expires = '', secure = '';
982+
983+
if (cross_subdomain) {
984+
var matches = document$1.location.hostname.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i),
985+
domain = matches ? matches[0] : '';
986+
987+
cdomain = ((domain) ? '; domain=.' + domain : '');
988+
}
989+
990+
if (days) {
991+
var date = new Date();
992+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
993+
expires = '; expires=' + date.toGMTString();
994+
}
995+
996+
if (is_secure) {
997+
secure = '; secure';
998+
}
999+
1000+
document$1.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
1001+
},
1002+
9801003
remove: function(name, cross_subdomain) {
9811004
_.cookie.set(name, '', -1, cross_subdomain);
9821005
}
@@ -1864,7 +1887,7 @@ var ce = {
18641887
if (!isNaN(secondsToDisable) && secondsToDisable > 0) {
18651888
var disableUntil = _.timestamp() + (secondsToDisable * 1000);
18661889
console.log('disabling CE for ' + secondsToDisable + ' seconds (from ' + _.timestamp() + ' until ' + disableUntil + ')');
1867-
_.cookie.set(DISABLE_COOKIE, true, secondsToDisable, true);
1890+
_.cookie.set_seconds(DISABLE_COOKIE, true, secondsToDisable, true);
18681891
}
18691892
},
18701893

examples/es2015-babelify/bundle.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ var ce = {
390390
if (!isNaN(secondsToDisable) && secondsToDisable > 0) {
391391
var disableUntil = _utils._.timestamp() + secondsToDisable * 1000;
392392
console.log('disabling CE for ' + secondsToDisable + ' seconds (from ' + _utils._.timestamp() + ' until ' + disableUntil + ')');
393-
_utils._.cookie.set(DISABLE_COOKIE, true, secondsToDisable, true);
393+
_utils._.cookie.set_seconds(DISABLE_COOKIE, true, secondsToDisable, true);
394394
}
395395
},
396396

@@ -638,7 +638,7 @@ Object.defineProperty(exports, '__esModule', {
638638
});
639639
var Config = {
640640
DEBUG: false,
641-
LIB_VERSION: '2.9.3'
641+
LIB_VERSION: '2.9.4'
642642
};
643643

644644
exports['default'] = Config;
@@ -5032,7 +5032,7 @@ _.cookie = {
50325032
return cookie;
50335033
},
50345034

5035-
set: function set(name, value, seconds, cross_subdomain, is_secure) {
5035+
set_seconds: function set_seconds(name, value, seconds, cross_subdomain, is_secure) {
50365036
var cdomain = '',
50375037
expires = '',
50385038
secure = '';
@@ -5057,6 +5057,31 @@ _.cookie = {
50575057
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
50585058
},
50595059

5060+
set: function set(name, value, days, cross_subdomain, is_secure) {
5061+
var cdomain = '',
5062+
expires = '',
5063+
secure = '';
5064+
5065+
if (cross_subdomain) {
5066+
var matches = document.location.hostname.match(/[a-z0-9][a-z0-9\-]+\.[a-z\.]{2,6}$/i),
5067+
domain = matches ? matches[0] : '';
5068+
5069+
cdomain = domain ? '; domain=.' + domain : '';
5070+
}
5071+
5072+
if (days) {
5073+
var date = new Date();
5074+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
5075+
expires = '; expires=' + date.toGMTString();
5076+
}
5077+
5078+
if (is_secure) {
5079+
secure = '; secure';
5080+
}
5081+
5082+
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/' + cdomain + secure;
5083+
},
5084+
50605085
remove: function remove(name, cross_subdomain) {
50615086
_.cookie.set(name, '', -1, cross_subdomain);
50625087
}

0 commit comments

Comments
 (0)