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,