Skip to content

Commit

Permalink
Fix bug where opt out setting was clobbered by restoring data from co…
Browse files Browse the repository at this point in the history
…okie (#196)
  • Loading branch information
Krishna Rajendran authored Oct 8, 2019
1 parent 765ab7c commit dc33f99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@ var _loadCookieDataProps = function _loadCookieDataProps(scope, cookieData) {
scope.options.userId = cookieData.userId;
}
if (cookieData.optOut !== null && cookieData.optOut !== undefined) {
scope.options.optOut = cookieData.optOut;
// Do not clobber config opt out value if cookieData has optOut as false
if (cookieData.optOut !== false) {
scope.options.optOut = cookieData.optOut;
}
}
if (cookieData.sessionId) {
scope._sessionId = parseInt(cookieData.sessionId);
Expand Down
8 changes: 8 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,14 @@ describe('setVersionName', function() {
assert.strictEqual(amplitude2.options.optOut, true);
});

it('should favor the config optOut setting over cookie optOut if the config optOut is set to true', function() {
var amplitude = new AmplitudeClient();
cookie.set(amplitude.options.cookieName, { optOut: false });
amplitude.init(apiKey, null, { optOut: true });

assert.strictEqual(amplitude.options.optOut, true);
});

it('should limit identify events queued', function() {
amplitude.init(apiKey, null, {savedMaxCount: 10});

Expand Down

0 comments on commit dc33f99

Please sign in to comment.