Skip to content

Commit 83edd6c

Browse files
committed
fix: Ensure transitory DAS for launcherOptions settings
1 parent 3cb1319 commit 83edd6c

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/persistence.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default function _Persistence(mpInstance) {
2525
localStorageData = self.getLocalStorage(),
2626
cookies = self.getCookie(),
2727
allData;
28-
2928
// https://go.mparticle.com/work/SQDSDKS-6045
3029
// Determine if there is any data in cookies or localStorage to figure out if it is the first time the browser is loading mParticle
3130
if (!localStorageData && !cookies) {
@@ -36,6 +35,8 @@ export default function _Persistence(mpInstance) {
3635
}
3736

3837
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
38+
// Call storeDataInMemory without parameters will create a new DAS
39+
self.storeDataInMemory();
3940
return;
4041
}
4142

test/src/tests-persistence.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,59 @@ describe('persistence', () => {
19041904

19051905
expect(getLocalStorage()).to.not.be.ok;
19061906
});
1907+
1908+
it('should allow identity calls and event sending without any persistence data', async () => {
1909+
mParticle.config.useCookieStorage = false;
1910+
mParticle.init(apiKey, mParticle.config);
1911+
1912+
await waitForCondition(hasIdentifyReturned);
1913+
1914+
// Verify identity call was made
1915+
const identityCalls = fetchMock.calls().filter(call =>
1916+
call[0].includes('/identify')
1917+
);
1918+
expect(identityCalls.length).to.equal(1);
1919+
1920+
const identityData = JSON.parse(identityCalls[0][1].body as string);
1921+
expect(identityData).to.have.property('known_identities');
1922+
1923+
// Should have a device_application_stamp generated by SDK
1924+
expect(identityData.known_identities).to.have.property('device_application_stamp');
1925+
expect(identityData.known_identities.device_application_stamp).to.be.a('string');
1926+
1927+
// Reset for event test
1928+
fetchMock.resetHistory();
1929+
1930+
// Test 2: Event sending should work without persistence data
1931+
mParticle.logEvent('No Persistence Test Event');
1932+
1933+
// Verify event was sent
1934+
const eventCalls = fetchMock.calls().filter(call =>
1935+
call[0].includes('/events')
1936+
);
1937+
1938+
expect(eventCalls.length).to.be.greaterThan(0);
1939+
1940+
const eventCall = eventCalls.find(call =>
1941+
(call[1].body as string).includes('No Persistence Test Event')
1942+
);
1943+
expect(eventCall).to.be.ok;
1944+
1945+
const eventBatch = JSON.parse(eventCall[1].body as string);
1946+
expect(eventBatch).to.have.property('events');
1947+
expect(eventBatch.events.length).to.be.greaterThan(0);
1948+
1949+
const testEvent = eventBatch.events.find(event =>
1950+
event.data && event.data.event_name === 'No Persistence Test Event'
1951+
);
1952+
expect(testEvent).to.be.ok;
1953+
1954+
expect(findCookie()).to.not.be.ok;
1955+
expect(getLocalStorage()).to.not.be.ok;
1956+
1957+
const store = mParticle.getInstance()._Store;
1958+
expect(identityData.known_identities.device_application_stamp).to.equal(store.deviceId);
1959+
});
19071960
});
19081961

19091962
describe('set to false', () => {

0 commit comments

Comments
 (0)