Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cookies for subdomains setup #205

Open
wants to merge 1 commit into
base: v8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions documentation/Amplitude.html
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ <h4 class="name" id="setDomain"><span class="type-signature"></span>setDomain<sp


<div class="description">
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.
</div>


Expand Down Expand Up @@ -1972,7 +1972,7 @@ <h5>Parameters:</h5>

<h5>Example</h5>

<pre class="prettyprint"><code>amplitude.setDomain('.amplitude.com');</code></pre>
<pre class="prettyprint"><code>amplitude.setDomain('amplitude.com');</code></pre>



Expand Down
4 changes: 2 additions & 2 deletions documentation/AmplitudeClient.html
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ <h4 class="name" id="setDomain"><span class="type-signature"></span>setDomain<sp


<div class="description">
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.
</div>


Expand Down Expand Up @@ -2156,7 +2156,7 @@ <h5>Parameters:</h5>

<h5>Example</h5>

<pre class="prettyprint"><code>amplitudeClient.setDomain('.amplitude.com');</code></pre>
<pre class="prettyprint"><code>amplitudeClient.setDomain('amplitude.com');</code></pre>



Expand Down
4 changes: 2 additions & 2 deletions documentation/amplitude-client.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ <h1 class="page-title">Source: amplitude-client.js</h1>
};

/**
* 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')) {
Expand Down
4 changes: 2 additions & 2 deletions documentation/amplitude.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ <h1 class="page-title">Source: amplitude.js</h1>
};

/**
* 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);
Expand Down
4 changes: 2 additions & 2 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
4 changes: 2 additions & 2 deletions src/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down