diff --git a/src/components/message/Message.js b/src/components/message/Message.js index cce2b6dd83..9bb6021cb5 100644 --- a/src/components/message/Message.js +++ b/src/components/message/Message.js @@ -8,7 +8,8 @@ import { createState, getRequestDuration, getTsCookieFromStorage, - getOrCreateDeviceID + getOrCreateDeviceID, + getGlobalSessionID } from '../../utils'; const Message = function ({ markup, meta, parentStyles, warnings }) { @@ -81,7 +82,8 @@ const Message = function ({ markup, meta, parentStyles, warnings }) { // getRequestDuration runs in the child component (iframe/banner message), // passing a value to onReady and up to the parent component to go out with // the other stats - requestDuration: getRequestDuration() + requestDuration: getRequestDuration(), + globalSessionID: getGlobalSessionID() }); onMarkup({ @@ -224,7 +226,8 @@ const Message = function ({ markup, meta, parentStyles, warnings }) { // getRequestDuration runs in the child component (iframe/banner message), // passing a value to onReady and up to the parent component to go out with // the other stats - requestDuration: getRequestDuration() + requestDuration: getRequestDuration(), + globalSessionID: getGlobalSessionID() }); } diff --git a/src/library/zoid/message/component.js b/src/library/zoid/message/component.js index 3698864b6c..2a41985ccf 100644 --- a/src/library/zoid/message/component.js +++ b/src/library/zoid/message/component.js @@ -14,7 +14,6 @@ import { getLibraryVersion, runStats, logger, - getOrCreateGlobalSessionID, getSessionID, getGlobalState, getCurrentTime, @@ -219,7 +218,7 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () => queryParam: false, value: ({ props }) => { const { onReady } = props; - return ({ meta, activeTags, ts, requestDuration, messageRequestId }) => { + return ({ meta, activeTags, ts, requestDuration, messageRequestId, globalSessionID }) => { const { account, merchantId, index, modal, getContainer, pageType } = props; const { trackingDetails, offerType, ppDebugId } = meta; const partnerClientId = merchantId && account.slice(10); // slice is to remove the characters 'client-id:' from account name @@ -255,10 +254,9 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () => // deviceID from internal iframe storage // should be populated previously by the treatments component deviceID: getOrCreateDeviceID(), - // Global Session ID allows messages to be correlated to button events - globalSessionID: getOrCreateGlobalSessionID(), // Session ID from parent local storage, - sessionID: getSessionID() + sessionID: getSessionID(), + globalSessionID }, [index]: { type: 'message', diff --git a/src/utils/sdk.js b/src/utils/sdk.js index ecd5484c9b..2c29390c0e 100644 --- a/src/utils/sdk.js +++ b/src/utils/sdk.js @@ -1,6 +1,6 @@ /* eslint-disable eslint-comments/disable-enable-pair, no-else-return */ import arrayFrom from 'core-js-pure/stable/array/from'; -import { getStorage as getBelterStorage, uniqueID as createBelterID } from '@krakenjs/belter/src'; +import { getStorage as getBelterStorage } from '@krakenjs/belter/src'; import { SDK_QUERY_KEYS, SDK_SETTINGS } from '@paypal/sdk-constants/src'; import { getClientID, @@ -14,8 +14,7 @@ import { getCSPNonce, getNamespace as getSDKNamespace, getDefaultNamespace as getDefaultSDKNamespace, - getGlobalSessionID as getSDKGlobalSessionID, - setGlobalSessionID as setSDKGlobalSessionID, + getPayPalSessionID as getSDKGlobalSessionID, getSessionID as getSDKSessionID, getStorageID as getSDKStorageID, getStorageState as getSDKStorageState, @@ -165,18 +164,12 @@ export function getStorage() { return getBelterStorage({ name: getNamespace() }); } -// Uses SDK methods to get and set a global session ID +// Uses SDK methods to get a global session ID // value will be passed in message_render events // and used to correlate with button events -export function getOrCreateGlobalSessionID() { +export function getGlobalSessionID() { if (__MESSAGES__.__TARGET__ === 'SDK') { - let globalSessionID = getSDKGlobalSessionID(); - if (!globalSessionID) { - globalSessionID = createBelterID(); - setSDKGlobalSessionID(globalSessionID); - } - - return globalSessionID; + return getSDKGlobalSessionID(); } else { return getStorage().getSessionID(); } diff --git a/tests/unit/spec/src/components/message/Message.test.js b/tests/unit/spec/src/components/message/Message.test.js index dacdcb84a7..31c865d89d 100644 --- a/tests/unit/spec/src/components/message/Message.test.js +++ b/tests/unit/spec/src/components/message/Message.test.js @@ -13,6 +13,7 @@ jest.mock('src/utils', () => ({ getActiveTags: jest.fn(), getTsCookieFromStorage: jest.fn(() => ts), getOrCreateDeviceID: jest.fn(() => 'uid_26a2522628_mtc6mjk6nti'), + getGlobalSessionID: jest.fn(() => 'uid_d31a430e8f_mtq6ndk6mjk'), request: jest.fn(() => Promise.resolve({ data: '' @@ -32,6 +33,7 @@ describe('Message', () => { payerId: 'DEV00000000NI', deviceID: 'uid_26a2522628_mtc6mjk6nti', sessionID: 'uid_fda0b4618b_mtg6ndy6mjc', + globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk', onClick: jest.fn(), onReady: jest.fn(), onHover: jest.fn(), @@ -85,6 +87,7 @@ describe('Message', () => { expect(window.xprops.onReady).toHaveBeenLastCalledWith({ meta: {}, messageRequestId: 'uid_xxxxxxxxxx_xxxxxxxxxxx', + globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk', requestDuration: 123, ts }); @@ -123,6 +126,7 @@ describe('Message', () => { expect(window.xprops.onReady).toHaveBeenLastCalledWith({ meta: {}, messageRequestId: originalMRID, + globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk', requestDuration: 123, ts }); @@ -150,6 +154,7 @@ describe('Message', () => { messageRequestId: '23456' }, messageRequestId: expect.not.stringMatching(originalMRID), + globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk', requestDuration: 123, ts }); @@ -168,6 +173,7 @@ describe('Message', () => { expect(window.xprops.onReady).toBeCalledWith({ meta: {}, messageRequestId: 'uid_xxxxxxxxxx_xxxxxxxxxxx', + globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk', requestDuration: 123, ts });