From 6d4d181b9a5577d7409b4cc9b40082a1f75e50d9 Mon Sep 17 00:00:00 2001 From: Kirill Shnurov Date: Sat, 9 Nov 2019 02:48:30 +0300 Subject: [PATCH] fix cookie domain setup --- documentation/Amplitude.html | 4 ++-- documentation/AmplitudeClient.html | 4 ++-- documentation/amplitude-client.js.html | 4 ++-- documentation/amplitude.js.html | 4 ++-- src/amplitude-client.js | 4 ++-- src/cookie.js | 4 ++-- src/options.js | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/documentation/Amplitude.html b/documentation/Amplitude.html index 43e6667b..7378fb58 100644 --- a/documentation/Amplitude.html +++ b/documentation/Amplitude.html @@ -1850,7 +1850,7 @@

setDomain - Sets a customer domain for the amplitude cookie. Useful if you want to support cross-subdomain tracking. + Sets a customer domain for the amplitude cookie. Specified domain will include all subdomains. If you want to disable tracking for subdomains specify an empty string `''`, this will set cookies for the current domain only. @@ -1972,7 +1972,7 @@
Parameters:
Example
-
amplitude.setDomain('.amplitude.com');
+
amplitude.setDomain('amplitude.com');
diff --git a/documentation/AmplitudeClient.html b/documentation/AmplitudeClient.html index 743fa323..d9cf7863 100644 --- a/documentation/AmplitudeClient.html +++ b/documentation/AmplitudeClient.html @@ -2036,7 +2036,7 @@

setDomain - Sets a customer domain for the amplitude cookie. Useful if you want to support cross-subdomain tracking. + Sets a customer domain for the amplitude cookie. Specified domain will include all subdomains. If you want to disable tracking for subdomains specify an empty string `''`, this will set cookies for the current domain only. @@ -2156,7 +2156,7 @@
Parameters:
Example
-
amplitudeClient.setDomain('.amplitude.com');
+
amplitudeClient.setDomain('amplitude.com');
diff --git a/documentation/amplitude-client.js.html b/documentation/amplitude-client.js.html index d331b9d2..59459517 100644 --- a/documentation/amplitude-client.js.html +++ b/documentation/amplitude-client.js.html @@ -589,10 +589,10 @@

Source: amplitude-client.js

}; /** - * Sets a customer domain for the amplitude cookie. Useful if you want to support cross-subdomain tracking. + * Sets a customer domain for the amplitude cookie. Specified domain will include all subdomains. If you want to disable tracking for subdomains specify an empty string `''`, this will set cookies for the current domain only. * @public * @param {string} domain to set. - * @example amplitudeClient.setDomain('.amplitude.com'); + * @example amplitudeClient.setDomain('amplitude.com'); */ AmplitudeClient.prototype.setDomain = function setDomain(domain) { if (!utils.validateInput(domain, 'domain', 'string')) { diff --git a/documentation/amplitude.js.html b/documentation/amplitude.js.html index 6b013e62..2cbd79a2 100644 --- a/documentation/amplitude.js.html +++ b/documentation/amplitude.js.html @@ -161,11 +161,11 @@

Source: amplitude.js

}; /** - * Sets a customer domain for the amplitude cookie. Useful if you want to support cross-subdomain tracking. + * Sets a customer domain for the amplitude cookie. Specified domain will include all subdomains. If you want to disable tracking for subdomains specify an empty string `''`, this will set cookies for the current domain only. * @public * @param {string} domain to set. * @deprecated Please use amplitude.getInstance().setDomain(domain); - * @example amplitude.setDomain('.amplitude.com'); + * @example amplitude.setDomain('amplitude.com'); */ Amplitude.prototype.setDomain = function setDomain(domain) { this.getInstance().setDomain(domain); diff --git a/src/amplitude-client.js b/src/amplitude-client.js index 607975e8..6d85d350 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -718,10 +718,10 @@ AmplitudeClient.prototype.saveEvents = function saveEvents() { }; /** - * Sets a customer domain for the amplitude cookie. Useful if you want to support cross-subdomain tracking. + * Sets a customer domain for the amplitude cookie. Specified domain will include all subdomains. If you want to disable tracking for subdomains specify an empty string `''`, this will set cookies for the current domain only. * @public * @param {string} domain to set. - * @example amplitudeClient.setDomain('.amplitude.com'); + * @example amplitudeClient.setDomain('amplitude.com'); */ AmplitudeClient.prototype.setDomain = function setDomain(domain) { if (!utils.validateInput(domain, 'domain', 'string')) { diff --git a/src/cookie.js b/src/cookie.js index bae0c6ae..80da0c71 100644 --- a/src/cookie.js +++ b/src/cookie.js @@ -48,7 +48,7 @@ const topDomain = (url) => { for (let i = 0; i < levels.length; ++i) { const cname = '__tld_test__'; const domain = levels[i]; - const opts = { domain: '.' + domain }; + const opts = { domain: domain }; baseCookie.set(cname, 1, opts); if (baseCookie.get(cname)) { @@ -71,7 +71,7 @@ var options = function(opts) { _options.expirationDays = opts.expirationDays; _options.secure = opts.secure; - var domain = (!utils.isEmptyString(opts.domain)) ? opts.domain : '.' + topDomain(getLocation().href); + var domain = (opts.domain !== undefined) ? opts.domain : topDomain(getLocation().href); var token = Math.random(); _options.domain = domain; set('amplitude_test', token); diff --git a/src/options.js b/src/options.js index ebd8262a..0b3ce93e 100644 --- a/src/options.js +++ b/src/options.js @@ -17,7 +17,7 @@ export default { cookieExpiration: 365 * 10, cookieName: 'amplitude_id', deviceIdFromUrlParam: false, - domain: '', + domain: undefined, eventUploadPeriodMillis: 30 * 1000, // 30s eventUploadThreshold: 30, forceHttps: true,