@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 1.93 kB
JavaScript
import e from"../Services/analytics/collect-id.js";import t from"./EventsQueue.js";import{ANALYTICS_EVENT as n,ANALYTICS_INFO_TIMER_INTERVAL as l,ANALYTIC_LEVEL as a,ANALYTICS_PATH as o}from"./constants.js";import{debounce as r}from"../../utils/debounce.js";import{processAnalyticsData as c,createAnalyticsObject as i}from"./utils.js";import{analyticsPreProcessor as s}from"./analyticsPreProcessor.js";function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},l=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(l=l.concat(Object.getOwnPropertySymbols(n).filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})))),l.forEach((function(t){u(e,t,n[t])}))}return e}let m=null,f=null;const d=({locale:u,clientKey:d,analytics:b,amount:p,analyticsContext:j,bundleType:g})=>{const v=y({},{enabled:!0,checkoutAttemptId:null,analyticsData:{}},b),h=e({analyticsContext:j,clientKey:d,locale:u,amount:p,analyticsPath:o,bundleType:g}),O=t({analyticsContext:j,clientKey:d,analyticsPath:o}),P=()=>m?O.run(m):Promise.resolve(null),w={setUp:async e=>{const{payload:t,enabled:n}=v,l=n?a.all:a.initial,o=c(v.analyticsData);if(!m)try{m=await h(y({},e,t&&y({},t),Object.keys(o).length&&y({},o),{level:l}))}catch(e){console.warn("Fetching checkoutAttemptId failed."+(e?` Error=${e}`:""))}},getCheckoutAttemptId:()=>m,getEventsQueue:()=>O,createAnalyticsEvent:({event:e,data:t})=>{if(!v.enabled)return;const a=i(y({event:e},t));return((e,t)=>{const a=e===n.info?e:`${e}s`;O.add(`${a}`,t),e===n.info&&(clearTimeout(f),f=setTimeout((()=>{P()}),l)),e!==n.log&&e!==n.error||(clearTimeout(f),r(P)())})(e,a),a},getEnabled:()=>v.enabled,sendAnalytics:null};return w.sendAnalytics=!0===v.enabled?s(w):()=>{},w};export{d as default};
//# sourceMappingURL=Analytics.js.map