UNPKG

@deriv-com/analytics

Version:

Comprehensive analytics package for Deriv applications. Provides unified event tracking, A/B testing, and user analytics through RudderStack, PostHog and GrowthBook integrations with built-in caching and offline support.

9 lines (8 loc) 3.89 kB
/* @deriv-com/analytics - Browser ESM Bundle (RudderStack + PostHog) - Built with tsup */ var w=Object.defineProperty;var A=(e,t,r)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var R=(e,t,r)=>A(e,typeof t!="symbol"?t+"":t,r);var m="https://deriv.com/cdn-cgi/trace",O="https://cdn.growthbook.io",I="https://deriv-dataplane.rudderstack.com",f="https://ph.deriv.com",U="https://us.posthog.com",b=()=>{if(typeof window>"u")return f;let e=window.location.hostname;return e.includes(".deriv.me")?"https://ph.deriv.me":e.includes(".deriv.be")?"https://ph.deriv.be":e.includes(".deriv.ae")?"https://ph.deriv.ae":f},E=["deriv.com","deriv.be","deriv.me","deriv.team","deriv.ae"],y=["deriv.com","derivcrypto.com","besquare.my","besquare.com.my","ewallet.exchange","champion-fx.com","opalstraits.com","binary.com","binary.marketing","championgbs.com","4x.my","re-work.dev","regentmarkets.com","4x.com","binary.me","deriv.team","firstsource.io","firstsource.tech","deriv.hr","vmgbpo.net","mailisk.net","mailosaur.net","mobileapps.mailisk.net","w3e180zd.mailosaur.net"];function d(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)e[o]=r[o]}return e}var k={read:function(e){return e[0]==='"'&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function u(e,t){function r(n,c,i){if(!(typeof document>"u")){i=d({},t,i),typeof i.expires=="number"&&(i.expires=new Date(Date.now()+i.expires*864e5)),i.expires&&(i.expires=i.expires.toUTCString()),n=encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,i[a]!==!0&&(s+="="+i[a].split(";")[0]));return document.cookie=n+"="+e.write(c,n)+s}}function o(n){if(!(typeof document>"u"||arguments.length&&!n)){for(var c=document.cookie?document.cookie.split("; "):[],i={},s=0;s<c.length;s++){var a=c[s].split("="),x=a.slice(1).join("=");try{var p=decodeURIComponent(a[0]);if(i[p]=e.read(x,p),n===p)break}catch{}}return n?i[n]:i}}return Object.create({set:r,get:o,remove:function(n,c){r(n,"",d({},c,{expires:-1}))},withAttributes:function(n){return u(this.converter,d({},this.attributes,n))},withConverter:function(n){return u(d({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(e)}})}var g=u(k,{path:"/"});var z=(e,t)=>(...r)=>{t()&&console.log(`[ANALYTIC]${e}`,...r)},F=e=>{let t=e.split("@")[1]?.toLowerCase();return t?y.includes(t):!1},H=e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e),l=null,_=async()=>{if(l)return l;let e=JSON.parse(g.get("website_status")||"{}")?.clients_country;return l=(async()=>{try{let t=await fetch(m).catch(()=>null);if(!t)return e||"";let r=await t.text().catch(()=>"");return r?Object.fromEntries(r.split(` `).map(n=>n.split("=",2))).loc?.toLowerCase()||e||"":e||""}catch{return e||""}})(),l},h=e=>{if(e==null||typeof e!="object")return e;if(Array.isArray(e)){let o=[];for(let n=0;n<e.length;n++){let c=h(e[n]);c!=null&&o.push(c)}return o.length?o:void 0}let t={},r=!1;for(let o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;let n=h(e[o]);n==null||n===""||typeof n=="object"&&!Array.isArray(n)&&Object.keys(n).length===0||Array.isArray(n)&&n.length===0||(t[o]=n,r=!0)}return r?t:void 0},v=(e,t)=>{for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let o=e[r];o&&typeof o=="object"&&!Array.isArray(o)?v(o,t):t[r]=o}},$=e=>{if(e==null||typeof e!="object"||Array.isArray(e))return e;let t={};return v(e,t),t};export{R as a,O as b,I as c,U as d,b as e,E as f,z as g,F as h,H as i,_ as j,h as k,$ as l}; /*! Bundled license information: js-cookie/dist/js.cookie.mjs: (*! js-cookie v3.0.5 | MIT *) */ //# sourceMappingURL=chunk-F3U33XPR.mjs.map