@paypal/checkout-components 5.0.202 → 5.0.203-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.202",
3
+ "version": "5.0.203-alpha.0",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -13,4 +13,11 @@ export const ATTRIBUTE = {
13
13
  PAY_NOW: ('data-pay-now' : 'data-pay-now')
14
14
  };
15
15
 
16
+ export const FPTI_CPL_KEY = {
17
+ PAGE_NAME: ('page_name' : 'page_name'),
18
+ CPL_COMP_METRICS: ('cpl_comp_metrics' : 'cpl_comp_metrics'),
19
+ CPL_CHUNK_METRICS: ('cpl_chunk_metrics' : 'cpl_chunk_metrics'),
20
+ CPL_QUERY_METRICS: ('cpl_query_metrics' : 'cpl_query_metrics')
21
+ };
22
+
16
23
  export const DEFAULT = ('default' : 'default');
package/src/lib/cpl.js ADDED
@@ -0,0 +1,96 @@
1
+ /* @flow */
2
+ import { getLogger } from '@paypal/sdk-client/src';
3
+ import { FPTI_KEY } from '@paypal/sdk-constants/src';
4
+
5
+ import { FPTI_CPL_KEY } from '../constants';
6
+
7
+ /* To Track time spent in each phase(cdn download, chunks download, etc)
8
+ logCPLPhase('first_interactable_render')
9
+ logCPLPhase('html_body', 'comp', true);
10
+ logCPLPhase('html_body', 'comp');
11
+ */
12
+ const cplPhases = {};
13
+ export const logCPLPhase = (buttonID : string, phase : string, category : string, isStart : ?boolean) => {
14
+ try {
15
+ // to remove Query from phase
16
+ phase = phase.replace(/Query/g, '');
17
+ if (!cplPhases[buttonID]) {
18
+ cplPhases[buttonID] = {
19
+ query: {},
20
+ chunk: {},
21
+ comp: {}
22
+ };
23
+ }
24
+ const epochNow = Date.now();
25
+ if (category && cplPhases[buttonID][category] && phase) {
26
+ if (isStart && !cplPhases[buttonID][category][phase]) {
27
+ cplPhases[buttonID][category][phase] = {
28
+ start: epochNow
29
+ };
30
+ } else if (cplPhases[buttonID][category][phase]) {
31
+ if (
32
+ cplPhases[buttonID][category][phase].start &&
33
+ !cplPhases[buttonID][category][phase].tt
34
+ ) {
35
+ cplPhases[buttonID][category][phase].tt =
36
+ epochNow - cplPhases[buttonID][category][phase].start;
37
+ }
38
+ } else {
39
+ getLogger().info('CPL_LOG_PHASE_UNHANDLED_CONDITION').track({
40
+ phase,
41
+ category,
42
+ isStart
43
+ }).flush();
44
+ }
45
+ } else if (phase && !cplPhases[buttonID][category][phase]) {
46
+ if (performance && performance.timing) {
47
+ cplPhases[buttonID][category][phase] = epochNow - performance.timing.fetchStart;
48
+ }
49
+ }
50
+ } catch (err) {
51
+ getLogger().info('CPL_LOG_PHASE_ERROR').track({
52
+ phase,
53
+ category,
54
+ isStart,
55
+ err: err.message || 'CPL_LOG_PHASE_ERROR',
56
+ details: err.details,
57
+ stack: JSON.stringify(err.stack || err)
58
+ }).flush();
59
+ }
60
+ };
61
+
62
+ const _store = {
63
+ triggerInitialCPLEvent: true,
64
+ hasContingencies: false
65
+ };
66
+
67
+ const triggerCPLLatencyMetricsFPTI = (buttonId : string) => {
68
+ const cplLatencyMetrics = {
69
+ [FPTI_KEY.STATE]: 'CPL_LATENCY_METRICS',
70
+ [FPTI_KEY.TRANSITION]: 'process_client_metrics',
71
+ [FPTI_CPL_KEY.PAGE_NAME]: `main:xo:paypal-components:smart-payment-buttons`,
72
+ [FPTI_CPL_KEY.CPL_COMP_METRICS]: JSON.stringify(cplPhases?.[buttonId]?.comp || {}),
73
+ [FPTI_CPL_KEY.CPL_QUERY_METRICS]: JSON.stringify(cplPhases?.[buttonId]?.query || {}),
74
+ [FPTI_CPL_KEY.CPL_CHUNK_METRICS]: JSON.stringify(cplPhases?.[buttonId]?.chunk || {})
75
+ };
76
+
77
+ getLogger().info('CPL_LATENCY_METRICS_FIRST_RENDER').track(cplLatencyMetrics).flush();
78
+ };
79
+
80
+ export const updateTriggerInitialCPLEvent = (state : boolean) => {
81
+ getLogger().info(`CPL_UPDATE_TRIGGER_INITIAL_CPL_EVENT_TO_${ state.toString() }`).flush();
82
+ _store.triggerInitialCPLEvent = state;
83
+ };
84
+
85
+ export const shouldTriggerInitialCPLEvent = () : boolean => {
86
+ return _store.triggerInitialCPLEvent;
87
+ };
88
+
89
+ export const triggerInitialCPLEvent = (buttonId : string) => {
90
+ if (shouldTriggerInitialCPLEvent()) {
91
+ // Set the flag to false so that CPL call is not triggered again
92
+ updateTriggerInitialCPLEvent(false);
93
+ // Trigger FPTI event to capture the time spent on different phases.
94
+ triggerCPLLatencyMetricsFPTI(buttonId);
95
+ }
96
+ };
package/src/lib/index.js CHANGED
@@ -4,3 +4,4 @@ export * from './errors';
4
4
  export * from './isRTLLanguage';
5
5
  export * from './security';
6
6
  export * from './session';
7
+ export * from './cpl';
@@ -13,7 +13,7 @@ import { uniqueID, memoize, isApplePaySupported, supportsPopups as userAgentSupp
13
13
  import { FUNDING, FUNDING_BRAND_LABEL, QUERY_BOOL, ENV, FPTI_KEY } from '@paypal/sdk-constants/src';
14
14
  import { node, dom } from 'jsx-pragmatic/src';
15
15
 
16
- import { getSessionID, storageState, sessionState } from '../../lib';
16
+ import { getSessionID, storageState, sessionState, logCPLPhase } from '../../lib';
17
17
  import { normalizeButtonStyle, type ButtonProps } from '../../ui/buttons/props';
18
18
  import { isFundingEligible } from '../../funding';
19
19
 
@@ -256,6 +256,7 @@ export const getButtonsComponent : () => ButtonsComponent = memoize(() => {
256
256
  required: false,
257
257
  default: () => noop,
258
258
  decorate: ({ props, value = noop }) => {
259
+ logCPLPhase(props.buttonSessionID, 'first_render', 'comp', true);
259
260
  return (...args) => {
260
261
  const { fundingSource } = props;
261
262
  const venmoExperiment = createVenmoExperiment();
@@ -12,6 +12,7 @@ import type { ZoidProps } from 'zoid/src';
12
12
  import { DEFAULT_POPUP_SIZE } from '../checkout';
13
13
  import { Buttons } from '../../ui';
14
14
  import { type ButtonProps } from '../../ui/buttons/props';
15
+ import { logCPLPhase, triggerInitialCPLEvent } from '../../lib';
15
16
 
16
17
  type PrerenderedButtonsProps = {|
17
18
  nonce : ?string,
@@ -66,7 +67,8 @@ export function PrerenderedButtons({ nonce, onRenderCheckout, props } : Prerende
66
67
  onRenderCheckout({ fundingSource, card });
67
68
  }
68
69
  };
69
-
70
+ logCPLPhase(props.buttonSessionID, 'first_render', 'comp');
71
+ triggerInitialCPLEvent(props.buttonSessionID);
70
72
  return (
71
73
  <html>
72
74
  <body>