UNPKG

@atlas-kitchen/adyen-web

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