Skip to content

add timing data to xprops #2471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
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
42 changes: 42 additions & 0 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
getJsSdkLibrary,
wasShopperInsightsUsed,
isPayPalTrustedUrl,
getSDKInitTime,
} from "@paypal/sdk-client/src";
import {
rememberFunding,
Expand Down Expand Up @@ -1067,6 +1068,47 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
queryParam: true,
},

sdkInitTimings: {
type: "object",
queryParam: false,
required: false,
value: () => {
// eslint-disable-next-line compat/compat
const sdkScript = window?.performance
?.getEntriesByType("resource")
// eslint-disable-next-line security/detect-unsafe-regex
.find(({ name }) => /paypal\.com(?::\d+)?\/sdk\/js/.test(name));

const isCached = (performanceEntry) => {
if (
!performanceEntry ||
typeof performanceEntry.duration === "undefined"
) {
return "unknown";
}

return performanceEntry.duration === 0 ? "yes" : "no";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this yes/no standard for existing performance queries that we have?

Copy link
Member Author

@wsbrunson wsbrunson Feb 18, 2025

Choose a reason for hiding this comment

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

its what we did in nextgen. normally I would have done true/false but the presence of unknown made me go a different direction.

I'm not sure of any precedent for this type of thing, I'm open to suggestions

};

let sdkInitTimeStamp;

// this technically isn't possible with the way paypal-sdk-client
// is set up but one day it could be refactored and this would throw
// an error and block the button from rendering
try {
sdkInitTimeStamp = getSDKInitTime();
} catch (error) {
// do nothing
}

return {
sdkInitTimeStamp,
sdkScriptDownloadDuration: sdkScript?.duration,
isSdkCached: isCached(sdkScript),
};
},
},

sdkMeta: {
type: "string",
queryParam: true,
Expand Down
Loading