UNPKG

@atlas-kitchen/adyen-web

Version:
3 lines (2 loc) 1.73 kB
import e from"../Services/analytics/collect-id.js";import t from"./EventsQueue.js";import{ANALYTIC_LEVEL as n,ANALYTICS_EVENT as l,ANALYTICS_INFO_TIMER_INTERVAL as a,ANALYTICS_PATH as o}from"./constants.js";import{debounce as r}from"../../utils/debounce.js";import{processAnalyticsData as c}from"./utils.js";function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(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){i(e,t,n[t])}))}return e}let u=null,y=null;const f=({locale:i,clientKey:f,analytics:m,amount:b,analyticsContext:d,bundleType:p})=>{const g=s({},{enabled:!0,checkoutAttemptId:null,analyticsData:{}},m),j=e({analyticsContext:d,clientKey:f,locale:i,analyticsPath:o,bundleType:p}),h=t({analyticsContext:d,clientKey:f,analyticsPath:o}),v=()=>u?h.run(u):Promise.resolve(null);return{setUp:async e=>{const{payload:t,enabled:l}=g,a=l?n.all:n.initial,o=c(g.analyticsData);if(!u)try{u=await j(s({},e,t&&s({},t),Object.keys(o).length&&s({},o),{level:a}))}catch(e){console.warn("Fetching checkoutAttemptId failed."+(e?` Error=${e}`:""))}},getCheckoutAttemptId:()=>u,getEventsQueue:()=>h,getEnabled:()=>g.enabled,sendAnalytics:e=>{if(!g.enabled)return!1;return((e,t)=>{const n=e===l.info?e:`${e}s`;h.add(`${n}`,t),e===l.info&&(clearTimeout(y),y=setTimeout((()=>{v()}),a)),e!==l.log&&e!==l.error||(clearTimeout(y),r(v)())})(e.getEventCategory(),e),!0}}};export{f as default}; //# sourceMappingURL=Analytics.js.map