Skip to content

Commit 84e1a57

Browse files
authored
fix(cookies): reduce cookie lifetime (#306)
* fix(cookies): reduce cookie lifetime * fix broken test * fix broken tests and light linting
1 parent 75066bf commit 84e1a57

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

src/options.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (BUILD_COMPAT_REACT_NATIVE) {
1414
export default {
1515
apiEndpoint: 'api.amplitude.com',
1616
batchEvents: false,
17-
cookieExpiration: 365 * 10,
17+
cookieExpiration: 365, // 12 months is for GDPR compliance
1818
cookieName: 'amplitude_id', // this is a deprecated option
1919
sameSiteCookie: 'Lax', // cookie privacy policy
2020
cookieForceUpgrade: false,
@@ -52,7 +52,7 @@ export default {
5252
os_version: true,
5353
platform: true,
5454
region: true,
55-
version_name: true
55+
version_name: true,
5656
},
5757
unsetParamsReferrerOnNewSession: false,
5858
unsentKey: 'amplitude_unsent',

test/amplitude-client.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('AmplitudeClient', function() {
166166
amplitude.init(apiKey, userId, config);
167167
assert.equal(amplitude.options.apiEndpoint, 'api.amplitude.com');
168168
assert.equal(amplitude.options.batchEvents, false);
169-
assert.equal(amplitude.options.cookieExpiration, 3650);
169+
assert.equal(amplitude.options.cookieExpiration, 365);
170170
assert.equal(amplitude.options.cookieName, 'amplitude_id');
171171
assert.equal(amplitude.options.eventUploadPeriodMillis, 30000);
172172
assert.equal(amplitude.options.eventUploadThreshold, 30);
@@ -3311,7 +3311,7 @@ describe('setVersionName', function() {
33113311
describe('setDomain', function() {
33123312
beforeEach(() => {
33133313
reset();
3314-
amplitude.init(apiKey, null, { cookieExpiration: 365, secureCookie: true });
3314+
amplitude.init(apiKey, null, { cookieExpiration: 1, secureCookie: true });
33153315
});
33163316

33173317
it('should set the cookie domain to null for an invalid domain', () => {
@@ -3323,7 +3323,7 @@ describe('setVersionName', function() {
33233323
it('should not change the expirationDays options', () => {
33243324
amplitude.setDomain('.foobar.com');
33253325
const options = cookie.options();
3326-
assert.equal(options.expirationDays, 365);
3326+
assert.equal(options.expirationDays, 1);
33273327
});
33283328

33293329
it('should not change the secureCookie options', () => {

test/amplitude.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('Amplitude', function() {
268268
amplitude.init(apiKey, userId, config);
269269
assert.equal(amplitude.options.apiEndpoint, 'api.amplitude.com');
270270
assert.equal(amplitude.options.batchEvents, false);
271-
assert.equal(amplitude.options.cookieExpiration, 3650);
271+
assert.equal(amplitude.options.cookieExpiration, 365);
272272
assert.equal(amplitude.options.cookieName, 'amplitude_id');
273273
assert.equal(amplitude.options.eventUploadPeriodMillis, 30000);
274274
assert.equal(amplitude.options.eventUploadThreshold, 30);

test/cookie.js

+19-22
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,47 @@
11
import cookie from '../src/cookie.js';
2-
import baseCookie from '../src/base-cookie';
3-
import getLocation from '../src/get-location';
42

5-
describe('Cookie', function() {
6-
7-
before(function() {
3+
describe('Cookie', () => {
4+
before(() => {
85
cookie.reset();
96
});
107

11-
afterEach(function() {
8+
afterEach(() => {
129
cookie.remove('x');
1310
cookie.reset();
1411
});
1512

16-
describe('get', function() {
17-
it('should get an existing cookie', function() {
18-
cookie.set('x', { a : 'b' });
19-
assert.deepEqual(cookie.get('x'), { a : 'b' });
13+
describe('get', () => {
14+
it('should get an existing cookie', () => {
15+
cookie.set('x', { a: 'b' });
16+
assert.deepEqual(cookie.get('x'), { a: 'b' });
2017
});
2118

22-
it('should not throw an error on a malformed cookie', function () {
23-
document.cookie="x=y; path=/";
19+
it('should not throw an error on a malformed cookie', () => {
20+
document.cookie = 'x=y; path=/';
2421
assert.isNull(cookie.get('x'));
2522
});
2623
});
2724

28-
describe('remove', function () {
29-
it('should remove a cookie', function() {
30-
cookie.set('x', { a : 'b' });
31-
assert.deepEqual(cookie.get('x'), { a : 'b' });
25+
describe('remove', () => {
26+
it('should remove a cookie', () => {
27+
cookie.set('x', { a: 'b' });
28+
assert.deepEqual(cookie.get('x'), { a: 'b' });
3229
cookie.remove('x');
3330
assert.isNull(cookie.get('x'));
3431
});
3532
});
3633

37-
describe('options', function() {
38-
it('should set default options', function() {
34+
describe('options', () => {
35+
it('should set default options', () => {
3936
assert.deepEqual(cookie.options(), {
4037
expirationDays: undefined,
41-
domain: undefined
38+
domain: undefined,
4239
});
4340
});
4441

45-
it('should save options', function() {
46-
cookie.options({ expirationDays: 365 });
47-
assert.equal(cookie.options().expirationDays, 365);
42+
it('should save options', () => {
43+
cookie.options({ expirationDays: 1 });
44+
assert.equal(cookie.options().expirationDays, 1);
4845
});
4946
});
5047
});

0 commit comments

Comments
 (0)