coveo.analytics 2.32.0 → 2.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -164,20 +164,12 @@
164
164
  function Cookie() {
165
165
  }
166
166
  Cookie.set = function (name, value, expire) {
167
- var domain, expirationDate, domainParts, host;
167
+ var expirationDate;
168
168
  if (expire) {
169
169
  expirationDate = new Date();
170
170
  expirationDate.setTime(expirationDate.getTime() + expire);
171
171
  }
172
- host = window.location.hostname;
173
- if (host.indexOf('.') === -1) {
174
- writeCookie(name, value, expirationDate);
175
- }
176
- else {
177
- domainParts = host.split('.');
178
- domain = domainParts[domainParts.length - 2] + '.' + domainParts[domainParts.length - 1];
179
- writeCookie(name, value, expirationDate, domain);
180
- }
172
+ writeCookie(name, value, expirationDate, getCookieDomain(window.location.hostname));
181
173
  };
182
174
  Cookie.get = function (name) {
183
175
  var cookiePrefix = name + '=';
@@ -196,6 +188,35 @@
196
188
  };
197
189
  return Cookie;
198
190
  }());
191
+ function getCookieDomain(host) {
192
+ if (host.indexOf('.') === -1) {
193
+ return undefined;
194
+ }
195
+ var domainParts = host.split('.');
196
+ for (var domainLength = 2; domainLength <= domainParts.length; domainLength++) {
197
+ var domain = domainParts.slice(-domainLength).join('.');
198
+ if (supportsCookieDomain(domain)) {
199
+ return domain;
200
+ }
201
+ }
202
+ return undefined;
203
+ }
204
+ function supportsCookieDomain(domain) {
205
+ var name = "__coveo_cookie_domain_test_".concat(Math.random().toString(36).substring(2));
206
+ try {
207
+ writeCookie(name, '1', undefined, domain);
208
+ return Cookie.get(name) === '1';
209
+ }
210
+ catch (_a) {
211
+ return false;
212
+ }
213
+ finally {
214
+ try {
215
+ writeCookie(name, '', new Date(0), domain);
216
+ }
217
+ catch (_b) { }
218
+ }
219
+ }
199
220
  function writeCookie(name, value, expirationDate, domain) {
200
221
  document.cookie =
201
222
  "".concat(name, "=").concat(value) +
@@ -664,7 +685,7 @@
664
685
  v5.DNS = DNS;
665
686
  v5.URL = URL$1;
666
687
 
667
- var libVersion = "2.32.0";
688
+ var libVersion = "2.33.1";
668
689
 
669
690
  var getFormattedLocation = function (location) {
670
691
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);