Skip to content
Merged
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
9 changes: 6 additions & 3 deletions src/components/message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
createState,
getRequestDuration,
getTsCookieFromStorage,
getOrCreateDeviceID
getOrCreateDeviceID,
getGlobalSessionID
} from '../../utils';

const Message = function ({ markup, meta, parentStyles, warnings }) {
Expand Down Expand Up @@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another spot below where onReady can be called for the rerender use case where we should include this to stay consistent and prevent accidentally removing the value if it were to be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nate, I've addressed the re-render logic

});

onMarkup({
Expand Down Expand Up @@ -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()
});
}

Expand Down
8 changes: 3 additions & 5 deletions src/library/zoid/message/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
getLibraryVersion,
runStats,
logger,
getOrCreateGlobalSessionID,
getSessionID,
getGlobalState,
getCurrentTime,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
17 changes: 5 additions & 12 deletions src/utils/sdk.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/spec/src/components/message/Message.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<!--{"markup":"<div>mock</div>","meta":{"messageRequestId":"23456"},"parentStyles":"body { color: blue; }","warnings":[]}-->'
Expand All @@ -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(),
Expand Down Expand Up @@ -85,6 +87,7 @@ describe('Message', () => {
expect(window.xprops.onReady).toHaveBeenLastCalledWith({
meta: {},
messageRequestId: 'uid_xxxxxxxxxx_xxxxxxxxxxx',
globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk',
requestDuration: 123,
ts
});
Expand Down Expand Up @@ -123,6 +126,7 @@ describe('Message', () => {
expect(window.xprops.onReady).toHaveBeenLastCalledWith({
meta: {},
messageRequestId: originalMRID,
globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk',
requestDuration: 123,
ts
});
Expand Down Expand Up @@ -150,6 +154,7 @@ describe('Message', () => {
messageRequestId: '23456'
},
messageRequestId: expect.not.stringMatching(originalMRID),
globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk',
requestDuration: 123,
ts
});
Expand All @@ -168,6 +173,7 @@ describe('Message', () => {
expect(window.xprops.onReady).toBeCalledWith({
meta: {},
messageRequestId: 'uid_xxxxxxxxxx_xxxxxxxxxxx',
globalSessionID: 'uid_d31a430e8f_mtq6ndk6mjk',
requestDuration: 123,
ts
});
Expand Down