Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 0 deletions src/library/zoid/message/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getLibraryVersion,
runStats,
logger,
getOrCreateGlobalSessionID,
getSessionID,
getGlobalState,
getCurrentTime,
Expand Down Expand Up @@ -248,6 +249,8 @@ 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()
},
Expand Down
3 changes: 2 additions & 1 deletion src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { request } from './miscellaneous';
import { getLibraryVersion, getDisableSetCookie } from './sdk';

function generateLogPayload(account, { meta, events: bizEvents, tracking }) {
const { deviceID, sessionID, integration_type, messaging_version } = meta.global ?? {};
const { deviceID, sessionID, integration_type, messaging_version, globalSessionID } = meta.global ?? {};

let clientID;
if (account.startsWith('client-id:')) {
Expand Down Expand Up @@ -98,6 +98,7 @@ function generateLogPayload(account, { meta, events: bizEvents, tracking }) {

// Global Details
device_id: deviceID,
global_session_id: globalSessionID,
session_id: sessionID,
integration_type,
integration_version: messaging_version,
Expand Down
24 changes: 23 additions & 1 deletion 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 } from '@krakenjs/belter/src';
import { getStorage as getBelterStorage, uniqueID as createBelterID } from '@krakenjs/belter/src';
import { SDK_QUERY_KEYS, SDK_SETTINGS } from '@paypal/sdk-constants/src';
import {
getClientID,
Expand All @@ -14,6 +14,8 @@ import {
getCSPNonce,
getNamespace as getSDKNamespace,
getDefaultNamespace as getDefaultSDKNamespace,
getGlobalSessionID as getSDKGlobalSessionID,
setGlobalSessionID as setSDKGlobalSessionID,
getSessionID as getSDKSessionID,
getStorageID as getSDKStorageID,
getStorageState as getSDKStorageState,
Expand Down Expand Up @@ -161,6 +163,26 @@ export function getStorage() {
return getBelterStorage({ name: getNamespace() });
}

// Uses SDK methods to get and set a global session ID
// value will be passed in message_render events
// and used to correlate with button events
export function getOrCreateGlobalSessionID() {
if (__MESSAGES__.__TARGET__ === 'SDK') {
const globalSessionID = getSDKGlobalSessionID();

if (globalSessionID) {
return globalSessionID;
} else {
const globalSessionIDValue = createBelterID();
setSDKGlobalSessionID(globalSessionIDValue);

return globalSessionIDValue;
}
} else {
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I mentioned we could just leave this as undefined. Let's actually just use the same fallback as getSessionID, so getStorage().getSessionID(). They can be the same value that's fine.

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, Ive made the update.

}
Copy link
Contributor

Choose a reason for hiding this comment

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

we can update 171 to use a let so we can re-assign the variable to prevent creating another variable. something like this:

let globalSessionID = getSDKGlobalSessionID();
    if (!globalSessionID) {
        globalSessionID = createBelterID();
        setSDKGlobalSessionID(globalSessionID);
    }

    return globalSessionID;

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 Rene, Ive made the update in latest commit.

}

// Use SDK methods when available, otherwise manually fetch storage via belter
// see: https://github.com/paypal/paypal-sdk-client/blob/master/src/session.js
export function getSessionID() {
Expand Down