Skip to content
Closed
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
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ export const HTTP_SERVER_ERROR = 500 as const;

export type PrivacyControl = 'functional' | 'targeting';

export type StorageTypes = 'SDKState' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite';
export type StorageTypes = 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite';

export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
SDKState: 'functional',
OfflineEvents: 'functional',
IdentityCache: 'functional',
TimeOnSite: 'targeting',
Expand Down
16 changes: 1 addition & 15 deletions src/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function _Persistence(mpInstance) {
localStorageData = self.getLocalStorage(),
cookies = self.getCookie(),
allData;

// https://go.mparticle.com/work/SQDSDKS-6045
// Determine if there is any data in cookies or localStorage to figure out if it is the first time the browser is loading mParticle
if (!localStorageData && !cookies) {
Expand All @@ -35,10 +34,6 @@ export default function _Persistence(mpInstance) {
mpInstance._Store.isFirstRun = false;
}

if (mpInstance._Store.getPrivacyFlag('SDKState')) {
return;
}

// https://go.mparticle.com/work/SQDSDKS-6045
if (!mpInstance._Store.isLocalStorageAvailable) {
mpInstance._Store.SDKConfig.useCookieStorage = true;
Expand Down Expand Up @@ -117,10 +112,7 @@ export default function _Persistence(mpInstance) {
};

this.update = function() {
if (
!mpInstance._Store.webviewBridgeEnabled &&
!mpInstance._Store.getPrivacyFlag('SDKState')
) {
if (!mpInstance._Store.webviewBridgeEnabled) {
if (mpInstance._Store.SDKConfig.useCookieStorage) {
self.setCookie();
}
Expand Down Expand Up @@ -810,9 +802,6 @@ export default function _Persistence(mpInstance) {

// https://go.mparticle.com/work/SQDSDKS-6021
this.savePersistence = function(persistence) {
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
return;
}
var encodedPersistence = self.encodePersistence(
JSON.stringify(persistence)
),
Expand Down Expand Up @@ -857,9 +846,6 @@ export default function _Persistence(mpInstance) {
};

this.getPersistence = function() {
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
return null;
}
var persistence = this.useLocalStorage()
? this.getLocalStorage()
: this.getCookie();
Expand Down
36 changes: 6 additions & 30 deletions test/jest/persistence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,12 @@ describe('Persistence', () => {
});

describe('#update', () => {
describe('noFunctional privacy flag set to true', () => {
beforeEach(() => {
store.setNoFunctional(true);
store.webviewBridgeEnabled = false;
});

it('should NOT write to cookie and localStorage when useCookieStorage is true', () => {
store.SDKConfig.useCookieStorage = true;

const setCookieSpy = jest.spyOn(persistence, 'setCookie');
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');

persistence.update();

expect(setCookieSpy).not.toHaveBeenCalled();
expect(setLocalStorageSpy).not.toHaveBeenCalled();
});

it('should NOT write to localStorage when useCookieStorage is false', () => {
store.SDKConfig.useCookieStorage = false;

const setCookieSpy = jest.spyOn(persistence, 'setCookie');
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');

persistence.update();

expect(setCookieSpy).not.toHaveBeenCalled();
expect(setLocalStorageSpy).not.toHaveBeenCalled();
});
});
// describe('noFunctional privacy flag set to true', () => {
// beforeEach(() => {
// store.setNoFunctional(true);
// store.webviewBridgeEnabled = false;
// });
// });

describe('noFunctional privacy flag set to false', () => {
beforeEach(() => {
Expand Down
22 changes: 0 additions & 22 deletions test/src/tests-persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,28 +1882,6 @@ describe('persistence', () => {
beforeEach(() => {
mParticle.config.launcherOptions = { noFunctional: true };
});

it('should NOT store cookie when useCookieStorage = true', async () => {
mParticle.config.useCookieStorage = true;

mParticle.init(apiKey, mParticle.config);
await waitForCondition(hasIdentifyReturned);

mParticle.getInstance()._Persistence.update();

expect(findCookie()).to.not.be.ok;
});

it('should NOT write localStorage when useCookieStorage = false', async () => {
mParticle.config.useCookieStorage = false;

mParticle.init(apiKey, mParticle.config);
await waitForCondition(hasIdentifyReturned);

mParticle.getInstance()._Persistence.update();

expect(getLocalStorage()).to.not.be.ok;
});
});

describe('set to false', () => {
Expand Down
Loading