@traqio/web 0.6.2 → 0.7.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.
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{var Gt=Object.create;var oe=Object.defineProperty;var Kt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Ft=Object.getPrototypeOf,jt=Object.prototype.hasOwnProperty;var Yt=(n,e,t)=>()=>{if(t)throw t[0];try{return n&&(e=n(n=0)),e}catch(s){throw t=[s],s}};var M=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var De=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Vt(e))!jt.call(n,i)&&i!==t&&oe(n,i,{get:()=>e[i],enumerable:!(s=Kt(e,i))||s.enumerable});return n};var Wt=(n,e,t)=>(t=n!=null?Gt(Ft(n)):{},De(e||!n||!n.__esModule?oe(t,"default",{value:n,enumerable:!0}):t,n)),U=n=>De(oe({},"__esModule",{value:!0}),n);var ue=M(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});v.Skan=v.SKAN_STATE_KEY=v.CONVERSION_WINDOWS=void 0;v.windowForAge=Ue;v.shouldLockWindow=qe;v.fineValueForRevenue=Ge;v.fineValueForEvents=Ke;v.coarseValueForRevenue=Ve;v.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function Ue(n){let e=v.CONVERSION_WINDOWS.find(t=>n>=t.startHours&&n<t.endHours);return e?e.window:null}function qe(n,e){let t=Ue(e);if(t==null||!n||!n.length)return!1;let s=n.find(i=>i.window===t);return!s||!s.lock?!1:s.lockAfterHours==null?!0:e>=s.lockAfterHours}var Xt=63,Qt=6;function Ge(n,e){let t=0;for(let s=0;s<Math.min(e.length,Xt+1);s++)n>=e[s]&&(t=s);return t}function Ke(n,e){let t=new Set(n),s=0;return e.slice(0,Qt).forEach((i,r)=>{t.has(i)&&(s|=1<<r)}),s}function Ve(n,e){if(!e)return;let t,s=-1/0;for(let i of["low","medium","high"]){let r=e[i];r!=null&&n>=r&&r>=s&&(t=i,s=r)}return t}var Le={revenue:0,events:[],lastFine:null};v.SKAN_STATE_KEY="traq_skan_state";var ae=class{constructor(){this.mapping=null,this.state={...Le},this.enabled=!1}async init(e){this.opts=e,this.enabled=!!e.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(e){!this.enabled||!(e>0)||!Number.isFinite(e)||(this.state.revenue+=e,this.persist(),this.push())}markEvent(e){!this.enabled||this.state.events.includes(e)||(this.state.events.push(e),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var i,r;let e=this.mapping;if(!e||!this.opts.native)return;let t,s;if(e.mode==="events"){if(!((i=e.eventBits)!=null&&i.length))return;t=Ke(this.state.events,e.eventBits)}else{if(!((r=e.revenueBuckets)!=null&&r.length))return;t=Ge(this.state.revenue,e.revenueBuckets),s=Ve(this.state.revenue,e.coarseRevenue)}this.state.lastFine==null&&t===0||this.state.lastFine!=null&&t<=this.state.lastFine||(this.state.lastFine=t,this.persist(),this.opts.native.updateConversionValue(t,s,this.lockWindowNow()))}lockWindowNow(){var s;let e=this.state.firstSeenAt;if(e==null)return!1;let t=(this.now()-e)/36e5;return qe((s=this.mapping)==null?void 0:s.postbackWindows,t)}now(){return this.opts.nowFn?this.opts.nowFn():Date.now()}async fetchMapping(){var t;let e=(t=this.opts.fetchFn)!=null?t:typeof fetch=="function"?fetch:void 0;if(!e)return null;try{let s=await e(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!s.ok)return null;let i=await s.json();return i&&typeof i=="object"?i:null}catch{return null}}async restore(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(v.SKAN_STATE_KEY));t&&(this.state={...Le,...JSON.parse(t)})}catch{}}async persist(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(v.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};v.Skan=ae});var de=M(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.EXPOSURE_EVENT=c.MAX_PROPS_BYTES=c.MAX_SCREEN_NAME=c.MAX_EVENT_NAME=c.ANALYTICS_SESSION_IDLE_MS=c.MAX_TRAITS=c.MAX_GROUP_TYPES=void 0;c.cleanUserId=Bt;c.isEntry=je;c.nextAnalyticsBatch=$t;c.exposureProps=Jt;c.cleanGroupType=ce;c.cleanGroupKey=le;c.cleanGroups=es;c.withGroup=ts;c.cleanTraits=is;c.withSuperProps=rs;c.cleanEventName=os;c.cleanScreenName=as;c.cleanProps=Ye;c.touchSession=us;c.parseSession=cs;function Bt(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=256?e:null}function je(n){return n==="identify"||n==="group"||n==="alias"}function $t(n,e,t){let s,i=!1,r=[];for(let o of n){if(r.length>=t)break;if(!je(o.kind)){let f=o.asUser!==void 0?o.asUser||void 0:e;if(!i)s=f,i=!0;else if(f!==s)break}let{asUser:a,...l}=o;r.push(l)}return{events:r,userId:i?s:e,taken:r.length}}var Ht=200;function Fe(n){let e=typeof n=="string"?n.trim():typeof n=="number"&&Number.isFinite(n)||typeof n=="boolean"?String(n):"";return e&&e.length<=Ht?e:null}function Jt(n,e,t){let s=Fe(n),i=Fe(e);return!s||!i?null:{...t&&typeof t=="object"&&!Array.isArray(t)?t:{},experiment:s,variant:i}}var zt=/^[a-z][a-z0-9_]{0,29}$/;c.MAX_GROUP_TYPES=5;var Zt=256;function ce(n){if(typeof n!="string")return null;let e=n.trim();return zt.test(e)?e:null}function le(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=Zt?e:null}function es(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=c.MAX_GROUP_TYPES)break;let i=ce(t),r=le(s);i&&r&&(e[i]=r)}return e}function ts(n,e,t){let s=ce(e),i=le(t);return!s||!i||!(s in n)&&Object.keys(n).length>=c.MAX_GROUP_TYPES?null:{groups:{...n,[s]:i},type:s,key:i,changed:n[s]!==i}}var ss=/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;c.MAX_TRAITS=50;var ns=200;function is(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=c.MAX_TRAITS)break;if(ss.test(t))if(typeof s=="string"){let i=s.trim();i&&(e[t]=i.slice(0,ns))}else(typeof s=="number"&&Number.isFinite(s)||typeof s=="boolean")&&(e[t]=s)}return e}function rs(n,e){var t;return Object.keys(e).length&&(t=Ye({...e,...n!=null?n:{}}))!=null?t:n}c.ANALYTICS_SESSION_IDLE_MS=1800*1e3;c.MAX_EVENT_NAME=128;c.MAX_SCREEN_NAME=512;c.MAX_PROPS_BYTES=4096;c.EXPOSURE_EVENT="$exposure";function os(n){if(typeof n!="string")return null;let e=n.trim();return!e||e.length>c.MAX_EVENT_NAME||e.startsWith("$")&&e!==c.EXPOSURE_EVENT?null:e}function as(n){if(typeof n!="string")return null;let e=n.trim();return e?e.slice(0,c.MAX_SCREEN_NAME):null}function Ye(n){if(!(typeof n!="object"||n===null||Array.isArray(n)))try{let e=JSON.stringify(n);return!e||e==="{}"||e.length>c.MAX_PROPS_BYTES?void 0:JSON.parse(e)}catch{return}}function us(n,e,t){return n&&typeof n.id=="string"&&typeof n.last=="number"&&e-n.last<=c.ANALYTICS_SESSION_IDLE_MS&&e>=n.last-6e4?{id:n.id,last:Math.max(e,n.last)}:{id:t(),last:e}}function cs(n){if(!n)return null;try{let e=JSON.parse(n);return typeof e.id=="string"&&typeof e.last=="number"?{id:e.id,last:e.last}:null}catch{return null}}});var fe=M(b=>{"use strict";Object.defineProperty(b,"__esModule",{value:!0});b.ADSERVICES_ATTEMPTS_KEY=b.ADSERVICES_SENT_KEY=void 0;b.reportAdServicesToken=ds;b.ADSERVICES_SENT_KEY="traq_adservices_sent";b.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var ls=5;async function ds(n){var s,i;if(!((s=n.native)!=null&&s.getAttributionToken))return"unsupported";if(await We(n,b.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await n.native.getAttributionToken()}catch{}if(!e||!e.trim()){let r=Number(await We(n,b.ADSERVICES_ATTEMPTS_KEY))||0;return await he(n,b.ADSERVICES_ATTEMPTS_KEY,String(r+1)),r+1>=ls&&await he(n,b.ADSERVICES_SENT_KEY,"1"),"no-token"}let t=(i=n.fetchFn)!=null?i:typeof fetch=="function"?fetch:void 0;if(!t)return"post-failed";try{if(!(await t(`${n.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:n.sdkKey,token:e.trim(),deviceId:n.deviceId,appUserId:n.userId,...n.debug?{debug:!0}:{}})})).ok)return"post-failed"}catch{return"post-failed"}return await he(n,b.ADSERVICES_SENT_KEY,"1"),"sent"}async function We(n,e){var t,s;try{return(s=await((t=n.storage)==null?void 0:t.getItem(e)))!=null?s:null}catch{return null}}async function he(n,e,t){var s;try{await((s=n.storage)==null?void 0:s.setItem(e,t))}catch{}}});var pe=M(P=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.isTrackingUrl=fs;P.isOpenUrl=ps;P.toDeepLink=Be;P.upgradeStoredDeepLink=gs;var hs=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/,Xe=/^\/o\/[0-9a-fA-F-]{36}\/?$/;function Qe(n){var t;let e=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(n);return e?(t=e[1])!=null?t:"":null}function fs(n){let e=Qe(n);return e!==null&&(hs.test(e)||Xe.test(e))}function ps(n){let e=Qe(n);return e!==null&&Xe.test(e)}function Be(n,e,t){var r,o,a;if(!(n!=null&&n.matched)||!n.via)return null;let s=(r=n.matchType)!=null?r:n.via==="ip_match"?"probabilistic":n.via,i=(o=n.payload)!=null?o:{deepLink:n.deepLink,value:null,params:{}};return{payload:i,matchType:s,confidence:s==="probabilistic"?(a=n.confidence)!=null?a:"low":null,deferred:e,code:n.code,deepLink:i.deepLink,via:n.via,...t?{url:t}:{}}}function gs(n){var t,s,i;if(!n||typeof n!="object")return null;let e=n;return e.payload&&e.matchType?e:e.via?Be({matched:!0,via:e.via,code:(t=e.code)!=null?t:null,deepLink:(s=e.deepLink)!=null?s:null},(i=e.deferred)!=null?i:!0,e.url):null}});var q={};var x=Yt(()=>{"use strict"});var me=M(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.CAPACITOR_ADMOB_PAID_EVENTS=g.MAX_RN_MIN_VERSION=g.MAX_RN_REVENUE_EVENTS=g.GMA_MIN_VERSION=g.GMA_FULLSCREEN_CHANNELS=g.AdRevenueGate=void 0;g.fromGoogleMobileAdsPaid=ye;g.fromGoogleMobileAdsChannel=ze;g.fromGoogleMobileAdsNativeAd=Ze;g.fromMaxAdInfo=et;g.fromCapacitorAdMob=Ss;g.watchReactNativeAds=_s;function ys(n){return Array.isArray(n)?n.length>0:n===!0}var ge=class{constructor(e=t=>console.warn(t)){this.warn=e,this.coverage={},this.warned=new Set,this.seen=new WeakSet}arm(e){this.coverage={...e}}captures(e){return ys(this.coverage[e])}capturesFormat(e,t){let s=this.coverage[e];return s===!0?!0:Array.isArray(s)&&t!==void 0&&s.includes(t)}manual(e,t){return this.captures(e)?(this.warnOnce(`manual:${e}`,`[traqio] adRevenue.${e} is on: manual ${t}() ignored \u2014 Traqio already captures this network, remove the call.`),!1):!0}helper(e,t,s,i){return this.capturesFormat(e,t)?(this.warnOnce(`helper:${e}:${t}`,`[traqio] adRevenue.${e} already captures ${t} ads: ${i} ignored for them, keep it on the formats it is documented for.`),!1):this.first(s)}first(e){return!e||typeof e!="object"?!0:this.seen.has(e)?!1:(this.seen.add(e),!0)}warnOnce(e,t){if(!this.warned.has(e)){this.warned.add(e);try{this.warn(t)}catch{}}}};g.AdRevenueGate=ge;var ms=["unknown","estimated","publisher_provided","precise"];function He(n){var e;return typeof n=="number"&&(e=ms[n])!=null?e:"unknown"}function E(n){return typeof n=="string"&&n.trim()?n:void 0}function k(n){return n&&typeof n=="object"?n:void 0}function Je(n){let e=typeof n=="string"&&/^\d+$/.test(n.trim())?Number(n):n;return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}g.GMA_FULLSCREEN_CHANNELS={rnapp_google_mobile_ads_app_open_event:"app_open",rnapp_google_mobile_ads_interstitial_event:"interstitial",rnapp_google_mobile_ads_rewarded_event:"rewarded",rnapp_google_mobile_ads_rewarded_interstitial_event:"rewarded_interstitial"};g.GMA_MIN_VERSION="12.4.0";function ye(n,e={}){var o;let t=k(n);if(!t)return;let s=E(t.currency);if(!s)return;let i=Je(t.valueMicros);if(i===void 0){if(!(typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=0))return;i=Math.round(t.value*1e6)}let r=k((o=k(t.responseInfo))==null?void 0:o.loadedAdapterResponse);return{valueMicros:i,currency:s,precision:He(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:E(r==null?void 0:r.adSourceName)}}function ze(n,e){let t=k(e),s=k(t==null?void 0:t.body);if(!(!t||(s==null?void 0:s.type)!=="paid"))return ye(s.data,{adUnitId:E(t.adUnitId),adFormat:g.GMA_FULLSCREEN_CHANNELS[n]})}function Ze(n){let e=k(n);if((e==null?void 0:e.type)==="paid")return ye(e,{adFormat:"native"})}g.MAX_RN_REVENUE_EVENTS=["OnBannerAdRevenuePaid","OnMRecAdRevenuePaid","OnInterstitialAdRevenuePaid","OnRewardedAdRevenuePaid","OnAppOpenAdRevenuePaid"];g.MAX_RN_MIN_VERSION="5.0.0";function et(n){let e=k(n);if(!(!e||typeof e.revenue!="number"))return{revenue:e.revenue,revenuePrecision:E(e.revenuePrecision),adUnitId:E(e.adUnitId),format:E(e.adFormat),networkName:E(e.networkName)}}g.CAPACITOR_ADMOB_PAID_EVENTS={bannerAdPaid:"banner",nativeAdPaid:"native",interstitialAdImpression:"interstitial",onRewardedVideoAdImpression:"rewarded",onRewardedInterstitialAdImpression:"rewarded_interstitial",appOpenAdImpression:"app_open"};function Ss(n,e){let t=k(n),s=Je(t==null?void 0:t.valueMicros),i=E(t==null?void 0:t.currencyCode);if(!(!t||s===void 0||!i))return{valueMicros:s,currency:i,precision:He(t.precision),adUnitId:E(t.adUnitId),adFormat:e,adSourceName:E(t.networkName)}}function $e(n,e){var t,s,i,r,o;try{return(r=(s=(t=n.TurboModuleRegistry)==null?void 0:t.get)==null?void 0:s.call(t,e))!=null?r:(i=n.NativeModules)==null?void 0:i[e]}catch{return(o=n.NativeModules)==null?void 0:o[e]}}var vs=["interstitial","rewarded","rewarded_interstitial","app_open"];function _s(n,e,t){var a,l,f,T;if(!t)try{t=(x(),U(q))}catch{return{coverage:{},stop:()=>{}}}let s=[],i={},r=(p,m,S=d=>d)=>d=>{try{let y=p(d);y&&m(y,S(d))}catch{}},o=p=>{var m,S;return(S=k((m=k(p))==null?void 0:m.body))==null?void 0:S.data};if(n.admob){i.admob=[];for(let[S,d]of Object.entries(g.GMA_FULLSCREEN_CHANNELS)){let y=(a=t.DeviceEventEmitter)==null?void 0:a.addListener(S,r(_=>ze(S,_),e.admob,o));y&&(s.push(y),i.admob.push(d))}let p=$e(t,"RNGoogleMobileAdsNativeModule"),m=r(Ze,e.admob);try{if(p&&typeof p.onAdEvent=="function")s.push(p.onAdEvent(m)),i.admob.push("native");else if(p&&t.NativeEventEmitter){let S=new t.NativeEventEmitter(((l=t.Platform)==null?void 0:l.OS)==="ios"?p:void 0);s.push(S.addListener("RNGMANativeAdEvent",m)),i.admob.push("native")}}catch{}}if(n.applovinMax){let p=$e(t,"AppLovinMAX");if(p&&t.NativeEventEmitter)try{let m=[...g.MAX_RN_REVENUE_EVENTS];try{let d=(T=(f=p.getConstants)==null?void 0:f.call(p))!=null?T:{},y=Object.keys(d).filter(_=>/^ON_.*_AD_REVENUE_PAID$/.test(_)).map(_=>d[_]).filter(_=>typeof _=="string");y.length&&(m=[...new Set([...y,...m])])}catch{}let S=new t.NativeEventEmitter(p);for(let d of m)s.push(S.addListener(d,r(et,e.applovinMax)));i.applovinMax=[...vs]}catch{}}return{coverage:i,stop:()=>{for(let p of s.splice(0))try{p.remove()}catch{}}}}});var vt=M(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u.Traqio=u.Client=u.AdRevenueGate=u.watchReactNativeAds=u.fromMaxAdInfo=u.fromGoogleMobileAdsPaid=u.fromGoogleMobileAdsNativeAd=u.fromGoogleMobileAdsChannel=u.fromCapacitorAdMob=u.MAX_RN_REVENUE_EVENTS=u.MAX_RN_MIN_VERSION=u.GMA_MIN_VERSION=u.GMA_FULLSCREEN_CHANNELS=u.CAPACITOR_ADMOB_PAID_EVENTS=u.isTrackingUrl=u.isOpenUrl=u.ANALYTICS_SESSION_IDLE_MS=u.reportAdServicesToken=u.Skan=u.SDK_VERSION=void 0;u.normalizeMetaInstallReferrers=gt;u.normalizeAdvertisingId=yt;u.fromMaxAd=H;u.detectDebug=mt;u.isLocalPage=St;var bs=ue(),h=de(),Is=fe(),N=pe(),B=me();u.SDK_VERSION="0.11.0";var As=ue();Object.defineProperty(u,"Skan",{enumerable:!0,get:function(){return As.Skan}});var Es=fe();Object.defineProperty(u,"reportAdServicesToken",{enumerable:!0,get:function(){return Es.reportAdServicesToken}});var ks=de();Object.defineProperty(u,"ANALYTICS_SESSION_IDLE_MS",{enumerable:!0,get:function(){return ks.ANALYTICS_SESSION_IDLE_MS}});var pt=pe();Object.defineProperty(u,"isOpenUrl",{enumerable:!0,get:function(){return pt.isOpenUrl}});Object.defineProperty(u,"isTrackingUrl",{enumerable:!0,get:function(){return pt.isTrackingUrl}});var I=me();Object.defineProperty(u,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return I.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(u,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return I.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(u,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return I.GMA_MIN_VERSION}});Object.defineProperty(u,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return I.MAX_RN_MIN_VERSION}});Object.defineProperty(u,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return I.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(u,"fromCapacitorAdMob",{enumerable:!0,get:function(){return I.fromCapacitorAdMob}});Object.defineProperty(u,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return I.fromGoogleMobileAdsChannel}});Object.defineProperty(u,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return I.fromGoogleMobileAdsNativeAd}});Object.defineProperty(u,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return I.fromGoogleMobileAdsPaid}});Object.defineProperty(u,"fromMaxAdInfo",{enumerable:!0,get:function(){return I.fromMaxAdInfo}});Object.defineProperty(u,"watchReactNativeAds",{enumerable:!0,get:function(){return I.watchReactNativeAds}});Object.defineProperty(u,"AdRevenueGate",{enumerable:!0,get:function(){return I.AdRevenueGate}});var ws="traq_install_sent",Ts="traq_install_sent_debug",tt="traq_install_attempts",Ns="traq_ad_id_sent",Rs="traq_ad_id_sent_debug",G="/ingest/advertising-id",Se="traq_ad_id_consent",Os="traq_ad_id_answer_sent",Ms="traq_ad_id_answer_sent_debug",st="traq_referrer",nt="traq_queue",it="traq_ad_queue",rt="traq_device_id",ot="traq_last_session",at="traq_erased",R="traq_deferred_link",ve="traq_deferred_consent_retry_until",Ps=60*6e4,ut="traq_consent",ct="traq_analytics_queue",_e="traq_analytics_session",lt="traq_super_props",dt="traq_groups",xs="/ingest/analytics",Cs=50,be=1e3,Ds=100,Ls=20,Us=new Set([400,413,422]),ht=500,qs=100,ft=1e3,$=1e3,Gs=300*1e3,Ks=3e3,Vs=3,Fs=1800*1e3,js=["facebook","instagram","facebook_lite"];function gt(n){if(!Array.isArray(n))return[];let e=[];for(let t of n){if(!t||typeof t!="object")continue;let s=t;if(typeof s.provider!="string"||!js.includes(s.provider)||typeof s.installReferrer!="string"||!s.installReferrer.trim())continue;let i=s.isCt===1||s.isCt===!0?1:s.isCt===0||s.isCt===!1?0:null;if(i===null)continue;let r=typeof s.actualTimestamp=="number"&&Number.isFinite(s.actualTimestamp)&&s.actualTimestamp>0?s.actualTimestamp:void 0;e.push({provider:s.provider,installReferrer:s.installReferrer,isCt:i,...r!==void 0?{actualTimestamp:r}:{}})}return e}var Ys=["not_determined","restricted","denied","authorized"],Ws={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},Xs={BANNER:"banner",LEADER:"banner",MREC:"banner",INTER:"interstitial",INTERSTITIAL:"interstitial",REWARDED:"rewarded",REWARDED_INTER:"rewarded_interstitial",NATIVE:"native",APPOPEN:"app_open",APP_OPEN:"app_open"},Qs="00000000-0000-0000-0000-000000000000";function yt(n){if(typeof n!="string")return;let e=n.trim();if(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(e))return e===Qs?void 0:e}function H(n){var e,t,s;if(typeof n.revenue=="number"&&Number.isFinite(n.revenue)&&n.revenue>=0)return{valueMicros:Math.round(n.revenue*1e6),currency:"USD",precision:(t=Ws[(e=n.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:n.adUnitId,adFormat:Xs[((s=n.format)!=null?s:"").toUpperCase()],adSourceName:n.networkName,ts:n.ts}}function O(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)})}function Bs(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function $s(){var n;try{let e=(x(),U(q)),t=(n=e==null?void 0:e.default)!=null?n:e;if(typeof(t==null?void 0:t.getItem)=="function"&&typeof(t==null?void 0:t.setItem)=="function")return{getItem:s=>t.getItem(s),setItem:(s,i)=>t.setItem(s,i)}}catch{}}function Hs(){var n,e;try{let t=(e=(n=(x(),U(q)))==null?void 0:n.Platform)==null?void 0:e.OS;return t==="ios"||t==="android"?t:void 0}catch{return}}var J=class{constructor(){this.queue=[],this.adQueue=[],this.adGate=new B.AdRevenueGate,this.adBatchId=null,this.context={sdkVersion:u.SDK_VERSION},this.referrer=null,this.started=!1,this.flushing=!1,this.flushTimer=null,this.retryMs=$,this.skan=new bs.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null,this.att=null,this.adIdConsent=null,this.adIdSync=null,this.debug=!1,this.analyticsQueue=[],this.analyticsSession=null,this.earlyAnalytics=[],this.currentScreen=null,this.superProps={},this.groups={},this.resetBeforeInit=!1,this.maxRevenuePaid=e=>{try{let t=(0,B.fromMaxAdInfo)(e),s=t&&H(t);s&&this.adGate.helper("applovinMax",s.adFormat,e,"Traqio.maxRevenuePaid")&&this.queueAdRevenue(s,"applovin_max","auto")}catch{}}}get isDebug(){return this.debug}async init(e){var t,s;if(!this.started){if(this.started=!0,this.opts={collectContext:!0,...e,userId:(t=e.userId)!=null?t:this.earlyUserId,storage:(s=e.storage)!=null?s:$s()},this.opts.storage||console.warn("[traqio] no storage available \u2014 pass `storage` to init() or install @react-native-async-storage/async-storage, otherwise the install is re-sent at every launch."),this.debug=await mt(e),await this.restoreConsent(e.consent),await this.restoreAdvertisingIdConsent(),await this.restoreQueue(),await this.restoreAdQueue(),await this.restoreAnalytics(),await this.buildContext(),await this.restoreErased()){this.earlyAnalytics=[];return}if(this.isWeb)this.earlyAnalytics=[];else for(let i of this.earlyAnalytics.splice(0))this.pushAnalytics(i,!1);if(!this.isWeb){let i=!!this.opts.storage&&!await this.opts.storage.getItem(this.installSentKey).catch(()=>"1");await this.sendInstallOnce(),this.syncAdvertisingId(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(i).then(r=>r!=null?r:this.retryDeferredWithConsent()),this.wireDeepLinks())}this.isWeb?this.maybeStartSession(!1):await this.maybeStartSession(!0),await this.initSkan(),await this.initAppleAds(),this.wireLifecycle(),this.wireAdRevenue(),(this.queue.length||this.adQueue.length||this.analyticsQueue.length)&&this.scheduleFlush(0)}}wireAdRevenue(){var s,i;let e=this.opts.adRevenue;if(!e||this.isWeb||!(e.admob||e.applovinMax))return;let t={admob:(r,o)=>{this.adGate.first(o)&&this.queueAdRevenue(r,"admob","auto")},applovinMax:(r,o)=>{let a=H(r);a&&this.adGate.first(o)&&this.queueAdRevenue(a,"applovin_max","auto")}};try{let r=(s=this.opts.native)!=null&&s.watchAdRevenue?(i=this.opts.native.watchAdRevenue(e,t))!=null?i:e:(0,B.watchReactNativeAds)(e,t).coverage;this.adGate.arm(r)}catch{}}track(e,t){var i,r;if(!this.started||this.erased)return;let s=((i=t==null?void 0:t.transactionId)==null?void 0:i.trim())||void 0;this.enqueue({name:e,eventId:O(),value:t==null?void 0:t.value,currency:t==null?void 0:t.currency,...s?{transactionId:s,store:(r=t==null?void 0:t.store)!=null?r:this.defaultStore()}:{}}),this.skan.markEvent(e),t!=null&&t.value&&this.skan.addRevenue(t.value)}capture(e,t){try{let s=(0,h.cleanEventName)(e);if(!s)return;let i=(0,h.cleanProps)(t);this.queueAnalytics({kind:"custom",name:s,ts:Date.now(),...i?{props:i}:{}})}catch{}}identify(e,t,s){try{let i=typeof e=="string"?e.trim():"";if(!i)return;this.opts?this.setUserId(i):this.earlyUserId=i;let r=(0,h.cleanTraits)(t),o=(0,h.cleanTraits)(s);if(!Object.keys(r).length&&!Object.keys(o).length)return;this.queueAnalytics({kind:"identify",ts:Date.now(),userId:i,...Object.keys(r).length?{set:r}:{},...Object.keys(o).length?{setOnce:o}:{}})}catch{}}register(e){try{this.superProps=(0,h.cleanTraits)({...this.superProps,...(0,h.cleanTraits)(e)}),this.persistSuperProps()}catch{}}unregister(e){if(typeof e!="string"||!(e in this.superProps))return;let t={...this.superProps};delete t[e],this.superProps=t,this.persistSuperProps()}getSuperProperties(){return{...this.superProps}}group(e,t,s,i){try{let r=(0,h.withGroup)(this.groups,e,t);if(!r)return;this.groups=r.groups,this.persistGroups();let o=(0,h.cleanTraits)(s),a=(0,h.cleanTraits)(i);if(!r.changed&&!Object.keys(o).length&&!Object.keys(a).length)return;this.queueAnalytics({kind:"group",ts:Date.now(),groupType:r.type,groupKey:r.key,...Object.keys(o).length?{set:o}:{},...Object.keys(a).length?{setOnce:a}:{}})}catch{}}resetGroups(){this.groups={},this.persistGroups()}getGroups(){return{...this.groups}}alias(e){try{let t=this.opts?this.opts.userId:this.earlyUserId,s=(0,h.cleanUserId)(e);if(!t||!s||s===t)return;this.queueAnalytics({kind:"alias",ts:Date.now(),userId:t,previousId:s})}catch{}}reset(){try{let e=this.opts?this.opts.userId:this.earlyUserId;if(e){for(let t of this.analyticsQueue)!(0,h.isEntry)(t.kind)&&t.asUser===void 0&&(t.asUser=e);for(let t of this.earlyAnalytics)!(0,h.isEntry)(t.kind)&&t.asUser===void 0&&(t.asUser=e)}if(this.opts?this.opts.userId=void 0:(this.earlyUserId=void 0,this.resetBeforeInit=!0),this.superProps={},this.groups={},this.analyticsSession=null,this.currentScreen=null,this.opts&&this.isWeb)return;this.persistSuperProps(),this.persistGroups(),this.forgetAnalyticsSession()}catch{}}exposure(e,t,s){var i;try{let r=(0,h.exposureProps)(e,t,s);r&&this.capture(h.EXPOSURE_EVENT,(i=(0,h.cleanProps)(r))!=null?i:{experiment:r.experiment,variant:r.variant})}catch{}}screen(e,t){try{let s=(0,h.cleanScreenName)(e);if(!s)return;let i=Date.now(),r=this.analyticsSession!==null&&i-this.analyticsSession.last<=h.ANALYTICS_SESSION_IDLE_MS;if(s===this.currentScreen&&r)return;this.currentScreen=s;let o=(0,h.cleanProps)(t);this.queueAnalytics({kind:"pageview",ts:i,screen:s,...o?{props:o}:{}})}catch{}}trackScreens(e){let t=()=>{try{let i=e.getCurrentRoute();i!=null&&i.name&&this.screen(i.name)}catch{}},s;try{s=e.addListener("state",t)}catch{s=void 0}return t(),()=>{try{typeof s=="function"&&s()}catch{}}}get hostPlatform(){var e,t;return(t=(e=this.opts.native)==null?void 0:e.platform)!=null?t:Hs()}defaultStore(){let e=this.hostPlatform;return e==="ios"?"app_store":e==="android"?"play_store":void 0}trackAdRevenue(e){this.adGate.manual("admob","trackAdRevenue")&&this.queueAdRevenue(e,"admob","manual")}trackMaxAdRevenue(e){if(!this.adGate.manual("applovinMax","trackMaxAdRevenue"))return;let t=H(e);t&&this.queueAdRevenue(t,"applovin_max","manual")}admobPaid(e,t="banner"){return s=>{try{let i=(0,B.fromGoogleMobileAdsPaid)(s,{adUnitId:e,adFormat:t});i&&this.adGate.helper("admob",t,s,"Traqio.admobPaid()")&&this.queueAdRevenue(i,"admob","auto")}catch{}}}queueAdRevenue(e,t,s){var i;!this.started||this.erased||!(e.valueMicros>=0)||!e.currency||(this.adQueue.push({...e,source:t,origin:s,impressionId:O(),ts:(i=e.ts)!=null?i:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>ft&&this.adQueue.splice(0,this.adQueue.length-ft),this.persistAdQueue(),this.scheduleFlush())}getInstallReferrer(){return this.started?this.readReferrer():Promise.resolve({status:"unavailable",retryable:!1})}onDeepLink(e){this.deepLinkListeners.add(e);let t=this.undelivered.splice(0);for(let s of t)e(s);return()=>{this.deepLinkListeners.delete(e)}}async handleUrl(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,N.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),s=(0,N.isOpenUrl)(e),i=(0,N.toDeepLink)(t,s,e);return i&&s&&await this.keepDeferred(i),i&&this.emitDeepLink(i),i}getDeferredDeepLink(){var e;return(e=this.deferred)!=null?e:Promise.resolve(null)}async redeemDeepLinkCode(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!e.trim())return null;let t=await this.postJson({code:e},"/deeplink/code"),s=(0,N.toDeepLink)(t,!0);return s?(await this.keepDeferred(s),this.emitDeepLink(s),s):null}async forgetMe(){return this.started?this.erased?!0:await this.post({deviceId:this.context.deviceId,appUserId:this.opts.userId},"/privacy/forget")?(await this.markErased(),!0):!1:!1}async setConsent(e){var t,s;this.consent=e?"granted":"denied",await((s=(t=this.opts)==null?void 0:t.storage)==null?void 0:s.setItem(ut,this.consent).catch(()=>{})),e&&this.deferred&&!this.erased&&(this.deferred=this.deferred.then(i=>i!=null?i:this.retryDeferredWithConsent()),await this.deferred)}async setAdvertisingIdConsent(e){var t,s;this.adIdConsent=e?"granted":"denied",!(!this.started||!this.opts)&&(await((t=this.opts.storage)==null?void 0:t.setItem(Se,this.adIdConsent).catch(()=>{})),!(this.isWeb||this.erased)&&(await((s=this.adIdSync)==null?void 0:s.catch(()=>{})),await this.syncAdvertisingId()))}get forgotten(){return this.erased}setUserId(e){this.opts&&(this.opts.userId=e)}flush(){this.erased||(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.drain())}appOpened(){!this.started||this.erased||(this.maybeStartSession(),this.syncAdvertisingId())}get skanMapping(){return this.skan.activeMapping}async initAppleAds(){if(this.opts.appleAds===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.getAttributionToken||await(0,Is.reportAdServicesToken)({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,deviceId:this.context.deviceId,userId:this.opts.userId,storage:this.opts.storage,native:{getAttributionToken:()=>e.getAttributionToken()},debug:this.debug})}async initSkan(){if(this.opts.skan===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.updateConversionValue||await this.skan.init({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,storage:this.opts.storage,native:{updateConversionValue:(t,s,i)=>{var r;return(r=e.updateConversionValue)==null?void 0:r.call(e,t,s,i)}}})}async resolveDeferredOnce(e){let t=this.opts.storage;try{let l=await(t==null?void 0:t.getItem(R));if(l)return(0,N.upgradeStoredDeepLink)(JSON.parse(l))}catch{}if(!e&&!await(t==null?void 0:t.getItem(`${R}_pending`).catch(()=>null)))return null;let s=this.hostPlatform,i=s==="android"?await this.readReferrer():null;await(t==null?void 0:t.setItem(`${R}_pending`,"1").catch(()=>{}));let r=await this.askDeferred(s,i==null?void 0:i.referrer);if(!r)return null;let o=(0,N.toDeepLink)(r,!0),a=await this.storedDeferred();if(a)return a;try{await(t==null?void 0:t.setItem(R,JSON.stringify(o))),!o&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(ve,String(Date.now()+Ps)))}catch{}return o&&this.emitDeepLink(o),o}askDeferred(e,t){return this.postJson({platform:e,installReferrer:t,...this.consent?{consent:this.consent}:{},...this.context.osVersion?{osVersion:this.context.osVersion}:{},...this.context.deviceModel?{deviceModel:this.context.deviceModel}:{}},"/deeplink/deferred")}async retryDeferredWithConsent(){var r,o;let e=(r=this.opts)==null?void 0:r.storage;if(!e||this.consent!=="granted"||this.opts.deepLinking===!1||this.isWeb)return null;let t=Number(await e.getItem(ve).catch(()=>null));if(!t||(await e.setItem(ve,"").catch(()=>{}),Date.now()>t))return null;let s=await this.storedDeferred();if(s)return s;let i=(0,N.toDeepLink)(await this.askDeferred(this.hostPlatform,void 0),!0);return i?(await((o=this.opts.storage)==null?void 0:o.setItem(R,JSON.stringify(i)).catch(()=>{})),this.emitDeepLink(i),i):null}async storedDeferred(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(R));return t?(0,N.upgradeStoredDeepLink)(JSON.parse(t)):null}catch{return null}}async keepDeferred(e){var t;await this.storedDeferred()||(await((t=this.opts.storage)==null?void 0:t.setItem(R,JSON.stringify(e)).catch(()=>{})),this.deferred=Promise.resolve(e))}emitDeepLink(e){if(!this.deepLinkListeners.size){this.undelivered.push(e);return}for(let t of this.deepLinkListeners)try{t(e)}catch{}}wireDeepLinks(){try{let{Linking:e}=(x(),U(q));if(!e)return;e.getInitialURL().then(t=>t&&this.handleUrl(t)).catch(()=>{}),e.addEventListener("url",({url:t})=>{this.handleUrl(t)})}catch{}}get isWeb(){var e;return((e=this.opts)==null?void 0:e.platform)==="web"}get installSentKey(){return this.debug?Ts:ws}get adIdSentKey(){return this.debug?Rs:Ns}get adIdAnswerSentKey(){return this.debug?Ms:Os}get collectsAdvertisingId(){return this.adIdConsent?this.adIdConsent==="granted":this.opts.waitForAdvertisingIdConsent?!1:this.opts.collectAdvertisingId===!0}async restoreAdvertisingIdConsent(){var t,s;if(this.adIdConsent){await((t=this.opts.storage)==null?void 0:t.setItem(Se,this.adIdConsent).catch(()=>{}));return}let e=await((s=this.opts.storage)==null?void 0:s.getItem(Se).catch(()=>null));(e==="granted"||e==="denied")&&(this.adIdConsent=e)}debugField(){return this.debug?{debug:!0}:{}}wireLifecycle(){let e={background:()=>this.flush(),foreground:()=>this.appOpened()};if(this.opts.lifecycle){this.opts.lifecycle(e);return}try{let{AppState:t}=(x(),U(q));t.addEventListener("change",s=>{if(s!=="active"){this.scheduleFlush(0);return}this.maybeStartSession(),this.syncAdvertisingId()})}catch{}}async restoreErased(){var e;try{this.erased=await((e=this.opts.storage)==null?void 0:e.getItem(at))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var e;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,this.analyticsQueue=[],this.earlyAnalytics=[],this.superProps={},this.groups={},await this.persistSuperProps(),await this.persistGroups(),await this.persistQueue(),await this.persistAdQueue(),await this.persistAnalyticsQueue();try{await((e=this.opts.storage)==null?void 0:e.setItem(at,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>ht&&this.queue.splice(0,this.queue.length-ht),this.persistQueue(),this.scheduleFlush()}queueAnalytics(e){var s,i;if(this.erased)return;let t=e;if(!(0,h.isEntry)(e.kind)){let r=(i=(s=e.screen)!=null?s:this.currentScreen)!=null?i:void 0,o=(0,h.withSuperProps)(e.props,this.superProps),a=Object.keys(this.groups).length?{...this.groups}:void 0;t={...e,...r?{screen:r}:{},...o?{props:o}:{},...a?{groups:a}:{}}}if(!this.started){this.earlyAnalytics.length<Ds&&this.earlyAnalytics.push(t);return}this.isWeb||this.pushAnalytics(t)}pushAnalytics(e,t=!0){var s,i,r;(0,h.isEntry)(e.kind)?this.analyticsQueue.push({...e,sessionId:(i=(s=this.analyticsSession)==null?void 0:s.id)!=null?i:""}):(this.analyticsSession=(0,h.touchSession)(this.analyticsSession,e.ts,O),this.analyticsQueue.push({...e,id:(r=e.id)!=null?r:O(),sessionId:this.analyticsSession.id})),this.analyticsQueue.length>be&&this.analyticsQueue.splice(0,this.analyticsQueue.length-be),this.persistAnalyticsQueue(),t&&this.scheduleFlush()}async restoreAnalytics(){var e,t,s,i,r;try{let o=await((e=this.opts.storage)==null?void 0:e.getItem(ct)),a=o?JSON.parse(o):null;Array.isArray(a)&&(this.analyticsQueue=[...a,...this.analyticsQueue].slice(-be))}catch{}try{this.resetBeforeInit||(s=this.analyticsSession)!=null||(this.analyticsSession=(0,h.parseSession)(await((t=this.opts.storage)==null?void 0:t.getItem(_e))))}catch{}if(this.resetBeforeInit){this.resetBeforeInit=!1,await this.persistSuperProps(),await this.persistGroups(),await this.forgetAnalyticsSession();return}try{let o=await((i=this.opts.storage)==null?void 0:i.getItem(lt)),a=Object.keys(this.superProps).length>0;o&&(this.superProps=(0,h.cleanTraits)({...(0,h.cleanTraits)(JSON.parse(o)),...this.superProps})),a&&await this.persistSuperProps()}catch{}try{let o=await((r=this.opts.storage)==null?void 0:r.getItem(dt)),a=Object.keys(this.groups).length>0;o&&(this.groups=(0,h.cleanGroups)({...(0,h.cleanGroups)(JSON.parse(o)),...this.groups})),a&&await this.persistGroups()}catch{}}async forgetAnalyticsSession(){var e;if(this.opts)try{await((e=this.opts.storage)==null?void 0:e.setItem(_e,"")),await this.persistAnalyticsQueue()}catch{}}async persistGroups(){var e;if(this.opts)try{await((e=this.opts.storage)==null?void 0:e.setItem(dt,JSON.stringify(this.groups)))}catch{}}async persistSuperProps(){var e;if(this.opts)try{await((e=this.opts.storage)==null?void 0:e.setItem(lt,JSON.stringify(this.superProps)))}catch{}}async persistAnalyticsQueue(){var e,t;try{await((e=this.opts.storage)==null?void 0:e.setItem(ct,JSON.stringify(this.analyticsQueue))),this.analyticsSession&&await((t=this.opts.storage)==null?void 0:t.setItem(_e,JSON.stringify(this.analyticsSession)))}catch{}}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(nt));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(nt,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,s;try{let i=await((e=this.opts.storage)==null?void 0:e.getItem(it));if(!i)return;let r=JSON.parse(i);this.adQueue=(t=r.items)!=null?t:[],this.adBatchId=(s=r.batchId)!=null?s:null}catch{}}async persistAdQueue(){var e;try{let t={batchId:this.adBatchId,items:this.adQueue};await((e=this.opts.storage)==null?void 0:e.setItem(it,JSON.stringify(t)))}catch{}}async maybeStartSession(e=!1){var r,o,a;if(this.erased)return;let t=Date.now();if(!e){let l=Number(await((r=this.opts.storage)==null?void 0:r.getItem(ot).catch(()=>null)))||0;if(l&&t-l<Fs)return}let s=(o=this.context.deviceId)!=null?o:await this.getOrCreateDeviceId();if(await this.post({deviceId:s,appUserId:this.opts.userId,sessionId:O(),ts:Math.floor(t/1e3),context:this.context},"/ingest/session"))try{await((a=this.opts.storage)==null?void 0:a.setItem(ot,String(t)))}catch{}}async buildContext(){var t,s,i;if(!this.opts.collectContext){this.context={sdkVersion:u.SDK_VERSION};return}let e={};try{e=(i=await((s=(t=this.opts.native)==null?void 0:t.getContext)==null?void 0:s.call(t)))!=null?i:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:e.deviceModel,osVersion:e.osVersion,appVersion:this.opts.appVersion,locale:Bs(),sdkVersion:u.SDK_VERSION}}async getOrCreateDeviceId(){var t,s;try{let i=await((t=this.opts.storage)==null?void 0:t.getItem(rt));if(i)return i}catch{}let e=O();try{await((s=this.opts.storage)==null?void 0:s.setItem(rt,e))}catch{}return e}async readReferrer(){var s,i;if(this.referrer)return this.referrer;try{let r=await((s=this.opts.storage)==null?void 0:s.getItem(st));if(r)return this.referrer=JSON.parse(r)}catch{}let e=this.opts.native;if((e==null?void 0:e.platform)!=="android")return{status:e?"not_supported_platform":"unavailable",retryable:!1};let t=await e.getInstallReferrer().catch(()=>({status:"error",retryable:!0}));if(!t.retryable){this.referrer=t;try{await((i=this.opts.storage)==null?void 0:i.setItem(st,JSON.stringify(t)))}catch{}}return t}async readMetaInstallReferrers(e){var s,i;let t=(s=this.opts.native)==null?void 0:s.getMetaInstallReferrers;if(!(e!=="android"||!t))try{let r=((i=this.opts.metaAppId)==null?void 0:i.trim())||void 0,o=gt(await t.call(this.opts.native,r));return o.length?o:void 0}catch{return}}async readAdvertisingId(){var e;if(!(!this.collectsAdvertisingId||!((e=this.opts.native)!=null&&e.getAdvertisingId)))try{return yt(await this.opts.native.getAdvertisingId())}catch{return}}async sendInstallOnce(){let e=this.opts.storage;if(e&&await e.getItem(this.installSentKey))return;let t=this.hostPlatform;if(!t){console.warn("[traqio] unknown platform \u2014 no native bridge and not React Native: the install is not reported. Pass `native: getNativeBridge()` (React Native / Expo) or your SDK's bridge to init().");return}this.opts.native||console.warn(`[traqio] the Traqio native module is missing on ${t} (Expo Go, or not linked in this build): install reported without its attribution signals. Use a development / EAS build.`);let s=await this.readReferrer();if(s.retryable&&e){let a=Number(await e.getItem(tt))||0;if(a+1<Vs){await e.setItem(tt,String(a+1));return}}let i=await this.readAdvertisingId(),r=await this.readMetaInstallReferrers(t);await this.post({install:{platform:t,installReferrer:s.referrer,...r?{metaInstallReferrers:r}:{},appUserId:this.opts.userId,advertisingId:i,...this.opts.waitForAdvertisingIdConsent&&!this.adIdConsent?{advertisingIdPending:!0}:{},context:this.context}})&&(await(e==null?void 0:e.setItem(this.installSentKey,"1")),i&&await(e==null?void 0:e.setItem(this.adIdSentKey,i).catch(()=>{})))}syncAdvertisingId(){return this.adIdSync?this.adIdSync:(this.adIdSync=this.postAdvertisingIdIfChanged().finally(()=>{this.adIdSync=null}),this.adIdSync)}async postAdvertisingIdIfChanged(){var t;let e=this.opts.storage;if(!(this.isWeb||this.erased||!e))try{if(!await e.getItem(this.installSentKey))return;let s=this.adIdConsent,r={deviceId:(t=this.context.deviceId)!=null?t:await this.getOrCreateDeviceId(),appUserId:this.opts.userId};if(s==="denied"){if(await e.getItem(this.adIdAnswerSentKey)==="denied")return;await this.post({...r,advertisingIdConsent:"denied"},G)&&(await e.setItem(this.adIdAnswerSentKey,"denied"),await e.setItem(this.adIdSentKey,""));return}if(!this.collectsAdvertisingId)return;let o=s?{advertisingIdConsent:s}:{},a=await this.readAdvertisingId();if(a){if(await e.getItem(this.adIdSentKey)===a)return;await this.post({...r,advertisingId:a,...o},G)&&(await e.setItem(this.adIdSentKey,a),s&&await e.setItem(this.adIdAnswerSentKey,s));return}s==="granted"&&await e.getItem(this.adIdAnswerSentKey)!=="granted"&&await this.post({...r,advertisingIdConsent:"granted"},G)&&await e.setItem(this.adIdAnswerSentKey,"granted")}catch{}}scheduleFlush(e=Ks){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},e))}async drain(){var e,t;if(!this.erased&&!(this.flushing||!this.queue.length&&!this.adQueue.length&&!this.analyticsQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let s=this.queue.slice(0,Ls),i=await this.send({events:s,appUserId:this.opts.userId,deviceId:this.context.deviceId});if(i==="retry")return this.backOff();i==="refused"&&console.warn(`[traqio] the server refused ${s.length} event(s) as malformed \u2014 dropped, not retried`),this.queue.splice(0,s.length),await this.persistQueue(),this.retryMs=$}for(;this.adQueue.length;){let s=(e=this.adQueue[0].source)!=null?e:"admob",i=this.adQueue.findIndex(a=>{var l;return((l=a.source)!=null?l:"admob")!==s}),r=this.adQueue.slice(0,Math.min(qs,i===-1?this.adQueue.length:i));if(this.adBatchId||(this.adBatchId=O(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:s,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:r.map(({source:a,...l})=>l)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,r.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=$}for(;this.analyticsQueue.length;){let s=(0,h.nextAnalyticsBatch)(this.analyticsQueue,this.opts.userId,Cs),i=await this.send({anonymousId:(t=this.context.deviceId)!=null?t:await this.getOrCreateDeviceId(),userId:s.userId,platform:this.hostPlatform,events:s.events},xs);if(i==="retry")return this.backOff();i==="refused"&&console.warn(`[traqio] the server refused ${s.taken} analytics event(s) as malformed \u2014 dropped, not retried`),this.analyticsQueue.splice(0,s.taken),await this.persistAnalyticsQueue(),this.retryMs=$}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,Gs),this.scheduleFlush(this.retryMs)}async postJson(e,t){try{let s=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...this.debugField()}),...this.keepalive()});return s.ok?await s.json():null}catch{return null}}async restoreConsent(e){var s;if(e!==void 0)return this.setConsent(e);if(this.consent)return this.setConsent(this.consent==="granted");let t=await((s=this.opts.storage)==null?void 0:s.getItem(ut).catch(()=>null));(t==="granted"||t==="denied")&&(this.consent=t)}keepalive(){return this.isWeb?{keepalive:!0}:{}}get asksTrackingAuthorization(){var e;return((e=this.opts.native)==null?void 0:e.platform)==="ios"&&typeof this.opts.native.getTrackingAuthorization=="function"}async readTrackingAuthorization(){var e,t;try{let s=await((t=(e=this.opts.native)==null?void 0:e.getTrackingAuthorization)==null?void 0:t.call(e));Ys.includes(s)&&(this.att=s!=null?s:null)}catch{}return this.att}async post(e,t="/ingest"){return await this.send(e,t)==="ok"}async send(e,t="/ingest"){let s=this.consent&&(t==="/ingest"||t==="/ingest/session"||t===G)?{consent:this.consent}:{},i=(t==="/ingest"||t===G)&&this.asksTrackingAuthorization?await this.readTrackingAuthorization():null;try{let r=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...s,...i?{att:i}:{},...this.debugField()}),...this.keepalive()});return r.ok?"ok":Us.has(r.status)?"refused":"retry"}catch{return"retry"}}};u.Client=J;async function mt(n){var e,t;if(n.debug!==void 0)return n.debug;if(n.platform==="web")return St();if(globalThis.__DEV__===!0)return!0;try{return await((t=(e=n.native)==null?void 0:e.isDebugBuild)==null?void 0:t.call(e))===!0}catch{return!1}}function St(n=globalThis.location){if(!n)return!1;if(n.protocol==="file:")return!0;let e=n.hostname.toLowerCase().replace(/^\[|\]$/g,"");return e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e==="::1"||e==="0.0.0.0"||/^127\.\d+\.\d+\.\d+$/.test(e)}u.Traqio=new J});var Lt=Wt(vt(),1);var Ae="traq_";function Ee(){return typeof document=="undefined"?void 0:document}function K(n){let e=Ee();if(!e)return null;for(let t of e.cookie?e.cookie.split(";"):[]){let s=t.indexOf("=");if(!(s<0)&&t.slice(0,s).trim()===n)try{return decodeURIComponent(t.slice(s+1).trim())}catch{return null}}return null}function Ie(n,e,t,s){let i=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",r=s?`; Domain=${s}`:"";return`${n}=${encodeURIComponent(e)}; Max-Age=${Math.floor(t)}; Path=/${r}; SameSite=Lax${i}`}function _t(n){let e=Ee();if(!e||!n.includes(".")||/^[\d.]+$/.test(n)||n.includes(":"))return null;let t=n.split("."),s=`${Ae}probe`;for(let i=t.length-2;i>=0;i--){let r=t.slice(i).join(".");if(e.cookie=Ie(s,"1",10,r),K(s)==="1")return e.cookie=Ie(s,"",0,r),r}return null}function C(n,e,t,s){let i=Ee();if(i)try{i.cookie=Ie(n,e,t,s)}catch{}}function V(n,e){C(n,"",0,e)}var F="traq_device_id",j="traq_internal",ke=new Set([F,j]),Js=395*24*60*60;function z(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var Z=class{constructor(e,t,s){this.persistent=e;this.cookieDomain=t;this.cookies=s;this.memory=new Map}get isPersistent(){return this.persistent}async getItem(e){return this.getSync(e)}async setItem(e,t){this.setSync(e,t)}getSync(e){var s,i,r;if(this.memory.has(e))return(s=this.memory.get(e))!=null?s:null;if(!this.persistent)return null;let t=null;try{t=(r=(i=z())==null?void 0:i.getItem(e))!=null?r:null}catch{}return t===null&&this.cookies&&ke.has(e)&&(t=K(e)),t}setSync(e,t){if(!this.persistent){this.memory.set(e,t);return}let s=!1;try{let i=z();i&&(i.setItem(e,t),s=!0)}catch{}s||this.memory.set(e,t),this.cookies&&ke.has(e)&&C(e,t,Js,this.cookieDomain())}removeSync(e){var t;this.memory.delete(e);try{(t=z())==null||t.removeItem(e)}catch{}this.cookies&&V(e,this.cookieDomain())}enable(){if(this.persistent)return;this.persistent=!0;let e=[...this.memory];this.memory.clear();for(let[t,s]of e)this.setSync(t,s)}disable(){if(!this.persistent)return;let e=z(),t=[];try{for(let s=0;e&&s<e.length;s++){let i=e.key(s);i&&i.startsWith(Ae)&&t.push(i)}}catch{}for(let s of ke)t.includes(s)||t.push(s);for(let s of t){let i=this.getSync(s);i!==null&&this.memory.set(s,i)}this.persistent=!1;for(let s of t){try{e==null||e.removeItem(s)}catch{}this.cookies&&V(s,this.cookieDomain())}}};var D=class{constructor(e,t,s,i,r){this.store=e;this.key=t;this.cookieDomain=s;this.cookies=i;this.valid=r}get(e=Date.now()){let t=this.store.getSync(this.key);if(t)try{let s=JSON.parse(t);if(s&&typeof s.id=="string"&&s.exp>e)return s.id}catch{}if(this.cookies&&this.store.isPersistent){let s=K(this.key);if(s&&this.valid(s))return s}return null}set(e,t,s=Date.now()){let i={id:e,exp:s+t};this.store.setSync(this.key,JSON.stringify(i)),this.cookies&&this.store.isPersistent&&C(this.key,e,t/1e3,this.cookieDomain())}clear(){this.store.removeSync(this.key),this.cookies&&V(this.key,this.cookieDomain())}persistCookie(e=Date.now()){let t=this.store.getSync(this.key);if(!(!t||!this.cookies||!this.store.isPersistent))try{let s=JSON.parse(t);s.exp>e&&C(this.key,s.id,(s.exp-e)/1e3,this.cookieDomain())}catch{}}};var zs="traq_src",Zs=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","fbclid","ttclid"],en=200,tn={utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid",referrer:"referrer"},Ne=n=>{let e=n==null?void 0:n.trim();return e?e.slice(0,en):null},Te=n=>n.toLowerCase().replace(/^www\./,"");function sn(n,e){let t=Te(n),s=Te(e);return t===s||t.endsWith(`.${s}`)||s.endsWith(`.${t}`)}function nn(n,e){if(!n)return null;try{let t=new URL(n);return t.protocol!=="http:"&&t.protocol!=="https:"||sn(new URL(e).hostname,t.hostname)?null:Ne(Te(t.hostname))}catch{return null}}function rn(n,e,t){let s=new URLSearchParams;try{let o=new URL(n).searchParams;for(let a of Zs){let l=Ne(o.get(a));l&&s.set(a,l)}}catch{return null}let i=s.toString()!=="",r=nn(e,n);return r&&s.set("referrer",r),s.toString()===""?null:(s.set("ts",String(t)),{query:s.toString(),fromUrl:i})}function we(n){let e;try{e=new URLSearchParams(n)}catch{return null}let t={};for(let[i,r]of Object.entries(tn)){let o=Ne(e.get(i));o&&(t[r]=o)}if(!Object.keys(t).length)return null;let s=Number(e.get("ts"));return Number.isFinite(s)&&s>0&&(t.landedAt=s),t}var ee=class{constructor(e,t,s,i){this.maxAgeMs=t;this.kept=new D(e,zs,s,i,r=>we(r)!==null)}capture(e,t,s=Date.now()){let i=rn(e,t,s);return!i||!i.fromUrl&&this.kept.get(s)!==null?null:(this.kept.set(i.query,this.maxAgeMs,s),we(i.query))}get(e=Date.now()){let t=this.kept.get(e);return t===null?null:we(t)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var on="traq_click",an="traq_click",bt=/^[A-Za-z0-9_-]{8,64}$/;function un(n){try{let e=new URL(n).searchParams.get(on);return e&&bt.test(e)?e:null}catch{return null}}var te=class{constructor(e,t,s,i){this.maxAgeMs=t;this.kept=new D(e,an,s,i,r=>bt.test(r))}capture(e,t=Date.now()){let s=un(e);return s&&this.kept.set(s,this.maxAgeMs,t),s}get(e=Date.now()){return this.kept.get(e)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};function It(n,e=Math.random){let t=typeof n=="number"&&Number.isFinite(n)&&n>=0&&n<=1?n:.5;return t<=0?!1:t>=1||e()<t}var cn=1e3,ln=5e3,dn=10,se=class{constructor(){this.clsMax=0;this.clsSeen=!1;this.clsWindow={value:0,first:0,last:0};this.longest=new Map;this.interactions=new Set;this.inpSeen=!1}addLcp(e){Number.isFinite(e)&&e>=0&&(this.lcp=e)}addFcp(e){this.fcp===void 0&&Number.isFinite(e)&&e>=0&&(this.fcp=e)}setTtfb(e){Number.isFinite(e)&&e>=0&&(this.ttfb=e)}addShift(e,t,s){if(this.clsSeen=!0,s||!Number.isFinite(e)||e<0)return;let i=this.clsWindow;i.value>0&&t-i.last<cn&&t-i.first<ln?(i.value+=e,i.last=t):this.clsWindow={value:e,first:t,last:t},this.clsMax=Math.max(this.clsMax,this.clsWindow.value)}clsObserved(){this.clsSeen=!0}addInteraction(e,t){if(!e||!Number.isFinite(t)||t<0)return;this.inpSeen=!0,this.interactions.add(e);let s=this.longest.get(e);if(!(s!==void 0&&s>=t)&&(this.longest.set(e,t),this.longest.size>dn)){let i=0,r=1/0;for(let[o,a]of this.longest)a<r&&(r=a,i=o);this.longest.delete(i)}}inp(){if(!this.inpSeen||!this.longest.size)return;let e=[...this.longest.values()].sort((t,s)=>s-t);return e[Math.min(e.length-1,Math.floor(this.interactions.size/50))]}snapshot(){let e={};this.lcp!==void 0&&(e.lcp=Math.round(this.lcp));let t=this.inp();return t!==void 0&&(e.inp=Math.round(t)),this.clsSeen&&(e.cls=Math.round(this.clsMax*1e4)/1e4),this.fcp!==void 0&&(e.fcp=Math.round(this.fcp)),this.ttfb!==void 0&&(e.ttfb=Math.round(this.ttfb)),Object.keys(e).length?e:null}};function Y(n,e,t={}){var s;try{let i=globalThis.PerformanceObserver;return!i||!((s=i.supportedEntryTypes)!=null&&s.includes(n))?!1:(new i(o=>e(o.getEntries())).observe({type:n,buffered:!0,...t}),!0)}catch{return!1}}function At(n){var s;let e=typeof document=="undefined"||document.visibilityState!=="hidden",t=0;try{let i=performance.getEntriesByType("navigation")[0];i&&(t=Math.max(0,(s=i.activationStart)!=null?s:0),typeof i.responseStart=="number"&&i.responseStart>0&&n.setTtfb(Math.max(0,i.responseStart-t)))}catch{}if(e){let i=!1,r=()=>{i=!0};for(let o of["keydown","click","pointerdown"])window.addEventListener(o,r,{once:!0,capture:!0});Y("largest-contentful-paint",o=>{if(!i)for(let a of o)n.addLcp(Math.max(0,a.startTime-t))}),Y("paint",o=>{for(let a of o)a.name==="first-contentful-paint"&&n.addFcp(Math.max(0,a.startTime-t))})}Y("layout-shift",i=>i.forEach(r=>{var o;return n.addShift((o=r.value)!=null?o:0,r.startTime,!!r.hadRecentInput)}))&&n.clsObserved(),Y("event",i=>i.forEach(r=>{var o;return n.addInteraction((o=r.interactionId)!=null?o:0,r.duration)}),{durationThreshold:40}),Y("first-input",i=>i.forEach(r=>{var o;return n.addInteraction((o=r.interactionId)!=null?o:0,r.duration)}))}var Re=n=>n.kind==="identify"||n.kind==="group"||n.kind==="alias",fn=/^[a-z][a-z0-9_]{0,29}$/,Rt=5;function Ot(n){if(typeof n!="string")return null;let e=n.trim();return fn.test(e)?e:null}function Mt(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=256?e:null}function Pe(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=Rt)break;let i=Ot(t),r=Mt(s);i&&r&&(e[i]=r)}return e}function Pt(n,e,t){let s=Ot(e),i=Mt(t);return!s||!i||!(s in n)&&Object.keys(n).length>=Rt?null:{groups:{...n,[s]:i},type:s,key:i,changed:n[s]!==i}}var pn=/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/,gn=50,yn=4096;function w(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=gn)break;if(pn.test(t))if(typeof s=="string"){let i=s.trim();i&&(e[t]=i.slice(0,200))}else(typeof s=="number"&&Number.isFinite(s)||typeof s=="boolean")&&(e[t]=s)}return e}function mn(n,e){if(!Object.keys(e).length)return n;let t={...e,...n!=null?n:{}};try{return JSON.stringify(t).length<=yn?t:n}catch{return n}}var Oe="traq_session";function xt(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=256?e:null}function Et(n){let e=typeof n=="string"?n.trim():typeof n=="number"&&Number.isFinite(n)||typeof n=="boolean"?String(n):"";return e&&e.length<=200?e:null}function Ct(n,e,t){let s=Et(n),i=Et(e);return!s||!i?null:{...t&&typeof t=="object"&&!Array.isArray(t)?t:{},experiment:s,variant:i}}function Sn(n,e,t){let s=0,i=e,r=!1;for(let o of n){if(s>=t)break;if(!(o.kind==="identify"||o.kind==="group"||o.kind==="alias")){let l=o.asUser!==void 0?o.asUser||void 0:e;if(!r)i=l,r=!0;else if(l!==i)break}s++}return{events:n.splice(0,s),userId:i}}var vn=1800*1e3,_n=5e3,ne=20,W=200,kt=10,wt=/^Object Not Found Matching Id:\d+, MethodName:\w+, ParamCount:\d+$/,bn=[25,50,75,100],In=[["utm_source","utmSource"],["utm_medium","utmMedium"],["utm_campaign","utmCampaign"],["utm_content","utmContent"],["utm_term","utmTerm"],["gclid","gclid"],["fbclid","fbclid"],["ttclid","ttclid"]];function Tt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,12)}`}function An(n,e){var s;let t={};try{let i=new URL(n);for(let[r,o]of In){let a=(s=i.searchParams.get(r))==null?void 0:s.trim();a&&(t[o]=a.slice(0,200))}if(e){let r=new URL(e);r.hostname.replace(/^www\./,"")!==i.hostname.replace(/^www\./,"")&&(t.referrer=`${r.protocol}//${r.host}/`)}}catch{}return Object.keys(t).length?t:void 0}function L(n){if(n)try{let e=new URL(n,typeof location!="undefined"?location.href:void 0);return e.protocol!=="http:"&&e.protocol!=="https:"?void 0:`${e.origin}${e.pathname}`}catch{return}}var Nt=1e3,En=30,Dt=3,Me=class{constructor(){this.burst=null}hit(e,t,s){let i=this.burst;return!(i!==null&&s-i.last<=Nt&&Math.hypot(e-i.x,t-i.y)<=En)||!i.reported&&s-i.first>Nt?(this.burst={x:e,y:t,first:s,last:s,count:1,reported:!1},!1):(i.count++,i.last=s,i.reported||i.count<Dt?!1:(i.reported=!0,!0))}},ie=class{constructor(e){this.deps=e;this.queue=[];this.timer=null;this.lastPath=null;this.maxScroll=0;this.scrollUrl=null;this.errorsThisPage=0;this.stopped=!1;this.scanner=!1;this.rage=new Me;this.vitals=null;this.vitalsUrl=null}start(){var t;let e=this.deps.options;if(this.timer=setInterval(()=>this.flush(!1),_n),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.leave()}),window.addEventListener("pagehide",()=>this.leave()),e.pageviews!==!1&&(this.pageview(),this.watchRoutes()),e.clicks!==!1&&document.addEventListener("click",s=>this.onClick(s),!0),e.rageClicks!==!1&&document.addEventListener("click",s=>this.onRageClick(s),!0),e.scroll!==!1&&window.addEventListener("scroll",()=>this.onScroll(),{passive:!0}),e.errors!==!1&&(window.addEventListener("error",s=>this.onError(s)),window.addEventListener("unhandledrejection",s=>this.onRejection(s))),e.webVitals!==!1){let s=typeof e.webVitals=="object"?e.webVitals.sampleRate:.5;It(s)&&(this.vitals=new se,this.vitalsUrl=(t=L(location.href))!=null?t:null,At(this.vitals))}}capture(e,t){typeof e!="string"||!e.trim()||e.startsWith("$")&&e.trim()!=="$exposure"||this.enqueue({kind:"custom",name:e.trim(),props:t})}identify(e,t,s){if(this.stopped||!e)return;let i=Object.keys(t).length>0,r=Object.keys(s).length>0;!i&&!r||(this.queue.push({kind:"identify",ts:Date.now(),userId:e,...i?{set:t}:{},...r?{setOnce:s}:{}}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1))}group(e,t,s,i){if(this.stopped)return;let r=Object.keys(s).length>0,o=Object.keys(i).length>0;this.queue.push({kind:"group",ts:Date.now(),groupType:e,groupKey:t,...r?{set:s}:{},...o?{setOnce:i}:{}}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1)}alias(e,t){this.stopped||(this.queue.push({kind:"alias",ts:Date.now(),userId:e,previousId:t}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1))}reset(e){if(e)for(let t of this.queue)!Re(t)&&t.asUser===void 0&&(t.asUser=e);try{this.deps.store.removeSync(Oe)}catch{}}pageview(){let e=L(location.href);e&&e!==this.lastPath&&(this.sendScroll(),this.lastPath=e,this.scrollUrl=e,this.maxScroll=0,this.errorsThisPage=0,this.enqueue({kind:"pageview"}),this.onScroll())}flush(e){var a,l;if(!this.queue.length||this.stopped)return;if(this.deps.isForgotten()){this.stop();return}let t=this.deps.anonymousId();if(!t)return;let s=Sn(this.queue,this.deps.userId(),100),i=s.userId,r=i?s.events.map(f=>Re(f)||f.asUser!==void 0?f:{...f,asUser:i}):s.events,o=JSON.stringify({sdkKey:this.deps.sdkKey,anonymousId:t,userId:i,debug:this.deps.isDebug()||void 0,internal:((l=(a=this.deps).isInternal)==null?void 0:l.call(a))||void 0,scanner:this.scanner||void 0,events:r.map(f=>Re(f)?f:{...f,asUser:void 0})});try{fetch(`${this.deps.endpoint}/ingest/analytics`,{method:"POST",headers:{"content-type":"application/json"},body:o,keepalive:e}).then(f=>{!f.ok&&(f.status>=500||f.status===429)&&this.requeue(r)}).catch(()=>this.requeue(r))}catch{this.requeue(r)}}stop(){this.stopped=!0,this.queue=[],this.timer&&clearInterval(this.timer),this.timer=null}requeue(e){this.stopped||(this.queue=[...e,...this.queue].slice(-W))}session(){let e=Date.now(),t=null;try{let s=this.deps.store.getSync(Oe);t=s?JSON.parse(s):null}catch{t=null}!t||typeof t.id!="string"||typeof t.last!="number"||e-t.last>vn?t={id:Tt(),last:e,src:An(location.href,document.referrer)}:t.last=e;try{this.deps.store.setSync(Oe,JSON.stringify(t))}catch{}return t}enqueue(e){var a,l,f,T,p,m,S,d;if(this.stopped)return;let t=this.session(),s=typeof document.title=="string"&&document.title?document.title.slice(0,200):void 0,i=e.kind==="scroll"||e.kind==="vitals"?e.props:mn(e.props,(f=(l=(a=this.deps).superProps)==null?void 0:l.call(a))!=null?f:{}),r=(m=(p=(T=this.deps).groups)==null?void 0:p.call(T))!=null?m:{},o=Object.keys(r).length?{...r}:void 0;this.queue.push({...e,...i?{props:i}:{},...o?{groups:o}:{},id:Tt(),ts:Date.now(),url:(d=(S=e.url)!=null?S:L(location.href))!=null?d:"",title:s,sessionId:t.id,...t.src?{src:t.src}:{}}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1)}leave(){this.sendScroll(),this.sendVitals(),this.flush(!0)}sendVitals(){let e=this.vitals;if(!e||!this.vitalsUrl)return;this.vitals=null;let t=e.snapshot();t&&this.enqueue({kind:"vitals",url:this.vitalsUrl,props:{...t}})}watchRoutes(){if(typeof history=="undefined")return;let e=()=>{setTimeout(()=>this.pageview(),0)};for(let t of["pushState","replaceState"]){let s=history[t];typeof s=="function"&&(history[t]=function(...i){let r=s.apply(this,i);return e(),r})}window.addEventListener("popstate",e)}onScroll(){var o;if(typeof document.documentElement=="undefined"||!document.documentElement)return;let e=document.documentElement,t=window.innerHeight||e.clientHeight||0,s=Math.max(e.scrollHeight||0,((o=document.body)==null?void 0:o.scrollHeight)||0);if(!s)return;let i=s<=t?1:Math.min(1,((window.scrollY||e.scrollTop||0)+t)/s),r=Math.round(i*100);for(let a of bn)r>=a&&a>this.maxScroll&&(this.maxScroll=a)}sendScroll(){this.deps.options.scroll===!1||!this.scrollUrl||this.maxScroll<25||(this.enqueue({kind:"scroll",url:this.scrollUrl,props:{depth:this.maxScroll}}),this.scrollUrl=null,this.maxScroll=0)}onClick(e){let t=e.target,s=t&&typeof t.closest=="function"?t.closest("a, button, [role='button'], input[type='submit'], input[type='button']"):null;if(!s||s.closest("[data-traqio-ignore]"))return;let i=s,r=(s.tagName==="INPUT"?i.value:s.innerText||s.textContent||"").replace(/\s+/g," ").trim().slice(0,100),o=s.tagName==="A"?L(s.getAttribute("href")):void 0,a={tag:s.tagName.toLowerCase()};r&&(a.text=r),o&&(a.href=o),s.id&&(a.id=s.id.slice(0,100)),this.enqueue({kind:"click",props:a})}onRageClick(e){var f;let t=typeof e.clientX=="number"?e.clientX:0,s=typeof e.clientY=="number"?e.clientY:0;if(!this.rage.hit(t,s,Date.now()))return;let i=e.target;if(!i||typeof i.closest!="function"||i.closest("[data-traqio-ignore]"))return;let r=(f=i.closest("a, button, [role='button'], input[type='submit'], input[type='button']"))!=null?f:i,o=(r.tagName==="INPUT"?r.value:r.innerText||r.textContent||"").replace(/\s+/g," ").trim().slice(0,100),a={tag:r.tagName.toLowerCase(),count:Dt};o&&(a.text=o);let l=r.tagName==="A"?L(r.getAttribute("href")):void 0;l&&(a.href=l),r.id&&(a.id=r.id.slice(0,100)),this.enqueue({kind:"rageclick",props:a})}onError(e){if(this.errorsThisPage>=kt)return;let t=(e.message||(e.error instanceof Error?e.error.message:"")||"Script error").slice(0,300);wt.test(t.replace(/^Uncaught (?:Error: )?/,""))&&(this.scanner=!0),this.errorsThisPage++;let s=e.error instanceof Error&&typeof e.error.stack=="string"?e.error.stack.slice(0,1500):void 0;this.enqueue({kind:"error",props:{message:t,...s?{stack:s}:{},...e.filename?{source:L(e.filename)}:{},...e.lineno?{line:e.lineno}:{}}})}onRejection(e){if(this.errorsThisPage>=kt)return;let t=e.reason,s=(t instanceof Error?t.message:typeof t=="string"?t:"Unhandled promise rejection").slice(0,300);wt.test(s)&&(this.scanner=!0),this.errorsThisPage++;let i=t instanceof Error&&typeof t.stack=="string"?t.stack.slice(0,1500):void 0;this.enqueue({kind:"error",props:{message:s,unhandledRejection:!0,...i?{stack:i}:{}}})}};var kn="https://api.traqio.app",X="traq_super",Q="traq_groups",wn=30,Tn=1440*60*1e3;function Nn(){return typeof window!="undefined"&&typeof document!="undefined"}function Rn(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}function On(n){try{let e=new URL(n).searchParams.get("traqio_internal");if(e==="1"||e==="true")return!0;if(e==="0"||e==="false")return!1}catch{}return null}var xe=class{constructor(){this.core=new Lt.Client;this.store=null;this.trackIds=null;this.sources=null;this.waitForConsent=!1;this.started=!1;this.analytics=null;this.earlyCaptures=[];this.ready=!1;this.superProps={};this.earlyIdentifies=[];this.groups={};this.earlyGroups=[];this.earlyAliases=[];this.resetBeforeInit=!1}async init(e){var T,p,m,S;if(this.started||!Nn())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,s,i=()=>s===void 0?s=_t(location.hostname):s,r=(T=e.consent)!=null?T:this.earlyConsent,o=!this.waitForConsent||r===!0;this.store=new Z(o,i,t);let a=((p=e.trackIdDays)!=null?p:wn)*Tn;this.trackIds=new te(this.store,a,i,t),this.trackIds.capture(location.href),this.sources=new ee(this.store,a,i,t),this.sources.capture(location.href,document.referrer);let l=On(location.href);if(l!==null&&this.setInternal(l),!this.store.getSync(F)){let d=Rn();d&&this.store.setSync(F,d)}this.userId=(m=e.userId)!=null?m:this.userId,this.resetBeforeInit&&(this.store.removeSync(X),this.store.removeSync(Q));try{let d=this.store.getSync(X),y=Object.keys(this.superProps).length>0;d&&(this.superProps=w({...w(JSON.parse(d)),...this.superProps})),y&&this.store.setSync(X,JSON.stringify(this.superProps))}catch{}try{let d=this.store.getSync(Q),y=Object.keys(this.groups).length>0;d&&(this.groups=Pe({...Pe(JSON.parse(d)),...this.groups})),y&&this.store.setSync(Q,JSON.stringify(this.groups))}catch{}let f=((S=e.endpoint)!=null?S:kn).replace(/\/+$/,"");if(await this.core.init({sdkKey:e.sdkKey,endpoint:f,storage:this.store,platform:"web",userId:this.userId,consent:r,debug:e.debug,lifecycle:({background:d,foreground:y})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?d():y()),window.addEventListener("pagehide",d)}}),e.analytics){let d=this.store;this.analytics=new ie({store:d,endpoint:f,sdkKey:e.sdkKey,anonymousId:()=>d.getSync(F),userId:()=>this.userId,superProps:()=>this.superProps,groups:()=>this.groups,isDebug:()=>this.core.isDebug,isForgotten:()=>this.core.forgotten,isInternal:()=>this.isInternal,options:e.analytics===!0?{}:e.analytics}),this.analytics.start();for(let[y,_,re]of this.earlyIdentifies)this.analytics.identify(y,_,re);for(let[y,_,re,qt]of this.earlyGroups)this.analytics.group(y,_,re,qt);for(let[y,_]of this.earlyAliases)this.analytics.alias(y,_);for(let[y,_]of this.earlyCaptures)this.analytics.capture(y,_)}this.earlyCaptures=[],this.earlyIdentifies=[],this.earlyGroups=[],this.earlyAliases=[],this.ready=!0}setInternal(e){if(this.store)try{e?this.store.setSync(j,"1"):this.store.removeSync(j)}catch{}}get isInternal(){var e;try{return((e=this.store)==null?void 0:e.getSync(j))==="1"}catch{return!1}}get isDebug(){return this.core.isDebug}track(e,t){this.core.track(e,t)}capture(e,t){this.analytics?this.analytics.capture(e,t):!this.ready&&this.earlyCaptures.length<50&&this.earlyCaptures.push([e,t])}pageview(){var e;(e=this.analytics)==null||e.pageview()}setUserId(e){this.userId=e,this.core.setUserId(e)}identify(e,t,s){let i=typeof e=="string"?e.trim():"";if(!i)return;this.setUserId(i);let r=w(t),o=w(s);!Object.keys(r).length&&!Object.keys(o).length||(this.analytics?this.analytics.identify(i,r,o):!this.ready&&this.earlyIdentifies.length<10&&this.earlyIdentifies.push([i,r,o]))}register(e){this.superProps=w({...this.superProps,...w(e)}),this.persistSuperProps()}unregister(e){if(typeof e!="string"||!(e in this.superProps))return;let t={...this.superProps};delete t[e],this.superProps=t,this.persistSuperProps()}getSuperProperties(){return{...this.superProps}}group(e,t,s,i){let r=Pt(this.groups,e,t);if(!r)return;this.groups=r.groups,this.persistGroups();let o=w(s),a=w(i);!r.changed&&!Object.keys(o).length&&!Object.keys(a).length||(this.analytics?this.analytics.group(r.type,r.key,o,a):!this.ready&&this.earlyGroups.length<10&&this.earlyGroups.push([r.type,r.key,o,a]))}resetGroups(){this.groups={},this.persistGroups()}getGroups(){return{...this.groups}}alias(e){let t=xt(e),s=this.userId;!s||!t||t===s||(this.analytics?this.analytics.alias(s,t):!this.ready&&this.earlyAliases.length<10&&this.earlyAliases.push([s,t]))}reset(){var t;let e=this.userId;(t=this.analytics)==null||t.reset(e),this.userId=void 0,this.core.reset(),this.superProps={},this.groups={},this.earlyIdentifies=[],this.earlyGroups=[],this.earlyAliases=[],this.store?(this.persistSuperProps(),this.persistGroups()):this.resetBeforeInit=!0}exposure(e,t,s){let i=Ct(e,t,s);if(!i)return;let r=!1;try{r=JSON.stringify(i).length<=4096}catch{r=!1}this.capture("$exposure",r?i:{experiment:i.experiment,variant:i.variant})}persistGroups(){try{if(!this.store)return;Object.keys(this.groups).length?this.store.setSync(Q,JSON.stringify(this.groups)):this.store.removeSync(Q)}catch{}}persistSuperProps(){try{if(!this.store)return;Object.keys(this.superProps).length?this.store.setSync(X,JSON.stringify(this.superProps)):this.store.removeSync(X)}catch{}}async setConsent(e){var t,s;this.started||(this.earlyConsent=e),this.store&&this.waitForConsent&&(e?(this.store.enable(),(t=this.trackIds)==null||t.persistCookie(),(s=this.sources)==null||s.persistCookie()):this.store.disable()),await this.core.setConsent(e)}getTrackId(){var e,t;return(t=(e=this.trackIds)==null?void 0:e.get())!=null?t:null}getSource(){var e,t;return(t=(e=this.sources)==null?void 0:e.get())!=null?t:null}async forgetMe(){var t,s,i;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear(),(s=this.sources)==null||s.clear(),(i=this.analytics)==null||i.stop(),this.superProps={},this.persistSuperProps(),this.groups={},this.persistGroups()),e}flush(){var e;this.core.flush(),(e=this.analytics)==null||e.flush(!1)}get forgotten(){return this.core.forgotten}},Ce=new xe;window.Traqio=Ce;var A=document.currentScript,Ut=A==null?void 0:A.dataset.sdkKey;Ut&&Ce.init({sdkKey:Ut,endpoint:(A==null?void 0:A.dataset.endpoint)||void 0,waitForConsent:(A==null?void 0:A.dataset.waitForConsent)==="true",analytics:(A==null?void 0:A.dataset.analytics)==="true"});})();
1
+ "use strict";(()=>{var Kt=Object.create;var oe=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Ft=Object.getPrototypeOf,jt=Object.prototype.hasOwnProperty;var Yt=(n,e,t)=>()=>{if(t)throw t[0];try{return n&&(e=n(n=0)),e}catch(s){throw t=[s],s}};var P=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var De=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Vt(e))!jt.call(n,i)&&i!==t&&oe(n,i,{get:()=>e[i],enumerable:!(s=Gt(e,i))||s.enumerable});return n};var Wt=(n,e,t)=>(t=n!=null?Kt(Ft(n)):{},De(e||!n||!n.__esModule?oe(t,"default",{value:n,enumerable:!0}):t,n)),x=n=>De(oe({},"__esModule",{value:!0}),n);var ue=P(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});v.Skan=v.SKAN_STATE_KEY=v.CONVERSION_WINDOWS=void 0;v.windowForAge=Ue;v.shouldLockWindow=qe;v.fineValueForRevenue=Ke;v.fineValueForEvents=Ge;v.coarseValueForRevenue=Ve;v.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function Ue(n){let e=v.CONVERSION_WINDOWS.find(t=>n>=t.startHours&&n<t.endHours);return e?e.window:null}function qe(n,e){let t=Ue(e);if(t==null||!n||!n.length)return!1;let s=n.find(i=>i.window===t);return!s||!s.lock?!1:s.lockAfterHours==null?!0:e>=s.lockAfterHours}var Xt=63,Qt=6;function Ke(n,e){let t=0;for(let s=0;s<Math.min(e.length,Xt+1);s++)n>=e[s]&&(t=s);return t}function Ge(n,e){let t=new Set(n),s=0;return e.slice(0,Qt).forEach((i,r)=>{t.has(i)&&(s|=1<<r)}),s}function Ve(n,e){if(!e)return;let t,s=-1/0;for(let i of["low","medium","high"]){let r=e[i];r!=null&&n>=r&&r>=s&&(t=i,s=r)}return t}var Le={revenue:0,events:[],lastFine:null};v.SKAN_STATE_KEY="traq_skan_state";var ae=class{constructor(){this.mapping=null,this.state={...Le},this.enabled=!1}async init(e){this.opts=e,this.enabled=!!e.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(e){!this.enabled||!(e>0)||!Number.isFinite(e)||(this.state.revenue+=e,this.persist(),this.push())}markEvent(e){!this.enabled||this.state.events.includes(e)||(this.state.events.push(e),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var i,r;let e=this.mapping;if(!e||!this.opts.native)return;let t,s;if(e.mode==="events"){if(!((i=e.eventBits)!=null&&i.length))return;t=Ge(this.state.events,e.eventBits)}else{if(!((r=e.revenueBuckets)!=null&&r.length))return;t=Ke(this.state.revenue,e.revenueBuckets),s=Ve(this.state.revenue,e.coarseRevenue)}this.state.lastFine==null&&t===0||this.state.lastFine!=null&&t<=this.state.lastFine||(this.state.lastFine=t,this.persist(),this.opts.native.updateConversionValue(t,s,this.lockWindowNow()))}lockWindowNow(){var s;let e=this.state.firstSeenAt;if(e==null)return!1;let t=(this.now()-e)/36e5;return qe((s=this.mapping)==null?void 0:s.postbackWindows,t)}now(){return this.opts.nowFn?this.opts.nowFn():Date.now()}async fetchMapping(){var t;let e=(t=this.opts.fetchFn)!=null?t:typeof fetch=="function"?fetch:void 0;if(!e)return null;try{let s=await e(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!s.ok)return null;let i=await s.json();return i&&typeof i=="object"?i:null}catch{return null}}async restore(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(v.SKAN_STATE_KEY));t&&(this.state={...Le,...JSON.parse(t)})}catch{}}async persist(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(v.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};v.Skan=ae});var de=P(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.EXPOSURE_EVENT=c.MAX_PROPS_BYTES=c.MAX_SCREEN_NAME=c.MAX_EVENT_NAME=c.ANALYTICS_SESSION_IDLE_MS=c.MAX_TRAITS=c.MAX_GROUP_TYPES=void 0;c.cleanUserId=Bt;c.isEntry=je;c.nextAnalyticsBatch=$t;c.exposureProps=Jt;c.cleanGroupType=ce;c.cleanGroupKey=le;c.cleanGroups=es;c.withGroup=ts;c.cleanTraits=is;c.withSuperProps=rs;c.cleanEventName=os;c.cleanScreenName=as;c.cleanProps=Ye;c.touchSession=us;c.parseSession=cs;function Bt(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=256?e:null}function je(n){return n==="identify"||n==="group"||n==="alias"}function $t(n,e,t){let s,i=!1,r=[];for(let o of n){if(r.length>=t)break;if(!je(o.kind)){let f=o.asUser!==void 0?o.asUser||void 0:e;if(!i)s=f,i=!0;else if(f!==s)break}let{asUser:a,...l}=o;r.push(l)}return{events:r,userId:i?s:e,taken:r.length}}var Ht=200;function Fe(n){let e=typeof n=="string"?n.trim():typeof n=="number"&&Number.isFinite(n)||typeof n=="boolean"?String(n):"";return e&&e.length<=Ht?e:null}function Jt(n,e,t){let s=Fe(n),i=Fe(e);return!s||!i?null:{...t&&typeof t=="object"&&!Array.isArray(t)?t:{},experiment:s,variant:i}}var zt=/^[a-z][a-z0-9_]{0,29}$/;c.MAX_GROUP_TYPES=5;var Zt=256;function ce(n){if(typeof n!="string")return null;let e=n.trim();return zt.test(e)?e:null}function le(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=Zt?e:null}function es(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=c.MAX_GROUP_TYPES)break;let i=ce(t),r=le(s);i&&r&&(e[i]=r)}return e}function ts(n,e,t){let s=ce(e),i=le(t);return!s||!i||!(s in n)&&Object.keys(n).length>=c.MAX_GROUP_TYPES?null:{groups:{...n,[s]:i},type:s,key:i,changed:n[s]!==i}}var ss=/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;c.MAX_TRAITS=50;var ns=200;function is(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=c.MAX_TRAITS)break;if(ss.test(t))if(typeof s=="string"){let i=s.trim();i&&(e[t]=i.slice(0,ns))}else(typeof s=="number"&&Number.isFinite(s)||typeof s=="boolean")&&(e[t]=s)}return e}function rs(n,e){var t;return Object.keys(e).length&&(t=Ye({...e,...n!=null?n:{}}))!=null?t:n}c.ANALYTICS_SESSION_IDLE_MS=1800*1e3;c.MAX_EVENT_NAME=128;c.MAX_SCREEN_NAME=512;c.MAX_PROPS_BYTES=4096;c.EXPOSURE_EVENT="$exposure";function os(n){if(typeof n!="string")return null;let e=n.trim();return!e||e.length>c.MAX_EVENT_NAME||e.startsWith("$")&&e!==c.EXPOSURE_EVENT?null:e}function as(n){if(typeof n!="string")return null;let e=n.trim();return e?e.slice(0,c.MAX_SCREEN_NAME):null}function Ye(n){if(!(typeof n!="object"||n===null||Array.isArray(n)))try{let e=JSON.stringify(n);return!e||e==="{}"||e.length>c.MAX_PROPS_BYTES?void 0:JSON.parse(e)}catch{return}}function us(n,e,t){return n&&typeof n.id=="string"&&typeof n.last=="number"&&e-n.last<=c.ANALYTICS_SESSION_IDLE_MS&&e>=n.last-6e4?{id:n.id,last:Math.max(e,n.last)}:{id:t(),last:e}}function cs(n){if(!n)return null;try{let e=JSON.parse(n);return typeof e.id=="string"&&typeof e.last=="number"?{id:e.id,last:e.last}:null}catch{return null}}});var fe=P(b=>{"use strict";Object.defineProperty(b,"__esModule",{value:!0});b.ADSERVICES_ATTEMPTS_KEY=b.ADSERVICES_SENT_KEY=void 0;b.reportAdServicesToken=ds;b.ADSERVICES_SENT_KEY="traq_adservices_sent";b.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var ls=5;async function ds(n){var s,i;if(!((s=n.native)!=null&&s.getAttributionToken))return"unsupported";if(await We(n,b.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await n.native.getAttributionToken()}catch{}if(!e||!e.trim()){let r=Number(await We(n,b.ADSERVICES_ATTEMPTS_KEY))||0;return await he(n,b.ADSERVICES_ATTEMPTS_KEY,String(r+1)),r+1>=ls&&await he(n,b.ADSERVICES_SENT_KEY,"1"),"no-token"}let t=(i=n.fetchFn)!=null?i:typeof fetch=="function"?fetch:void 0;if(!t)return"post-failed";try{if(!(await t(`${n.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:n.sdkKey,token:e.trim(),deviceId:n.deviceId,appUserId:n.userId,...n.debug?{debug:!0}:{}})})).ok)return"post-failed"}catch{return"post-failed"}return await he(n,b.ADSERVICES_SENT_KEY,"1"),"sent"}async function We(n,e){var t,s;try{return(s=await((t=n.storage)==null?void 0:t.getItem(e)))!=null?s:null}catch{return null}}async function he(n,e,t){var s;try{await((s=n.storage)==null?void 0:s.setItem(e,t))}catch{}}});var pe=P(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.isTrackingUrl=fs;C.isOpenUrl=ps;C.toDeepLink=Be;C.upgradeStoredDeepLink=gs;var hs=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/,Xe=/^\/o\/[0-9a-fA-F-]{36}\/?$/;function Qe(n){var t;let e=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(n);return e?(t=e[1])!=null?t:"":null}function fs(n){let e=Qe(n);return e!==null&&(hs.test(e)||Xe.test(e))}function ps(n){let e=Qe(n);return e!==null&&Xe.test(e)}function Be(n,e,t){var r,o,a;if(!(n!=null&&n.matched)||!n.via)return null;let s=(r=n.matchType)!=null?r:n.via==="ip_match"?"probabilistic":n.via,i=(o=n.payload)!=null?o:{deepLink:n.deepLink,value:null,params:{}};return{payload:i,matchType:s,confidence:s==="probabilistic"?(a=n.confidence)!=null?a:"low":null,deferred:e,code:n.code,deepLink:i.deepLink,via:n.via,...t?{url:t}:{}}}function gs(n){var t,s,i;if(!n||typeof n!="object")return null;let e=n;return e.payload&&e.matchType?e:e.via?Be({matched:!0,via:e.via,code:(t=e.code)!=null?t:null,deepLink:(s=e.deepLink)!=null?s:null},(i=e.deferred)!=null?i:!0,e.url):null}});var D={};var N=Yt(()=>{"use strict"});var me=P(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.CAPACITOR_ADMOB_PAID_EVENTS=g.MAX_RN_MIN_VERSION=g.MAX_RN_REVENUE_EVENTS=g.GMA_MIN_VERSION=g.GMA_FULLSCREEN_CHANNELS=g.AdRevenueGate=void 0;g.fromGoogleMobileAdsPaid=ye;g.fromGoogleMobileAdsChannel=ze;g.fromGoogleMobileAdsNativeAd=Ze;g.fromMaxAdInfo=et;g.fromCapacitorAdMob=Ss;g.watchReactNativeAds=_s;function ys(n){return Array.isArray(n)?n.length>0:n===!0}var ge=class{constructor(e=t=>console.warn(t)){this.warn=e,this.coverage={},this.warned=new Set,this.seen=new WeakSet}arm(e){this.coverage={...e}}captures(e){return ys(this.coverage[e])}capturesFormat(e,t){let s=this.coverage[e];return s===!0?!0:Array.isArray(s)&&t!==void 0&&s.includes(t)}manual(e,t){return this.captures(e)?(this.warnOnce(`manual:${e}`,`[traqio] adRevenue.${e} is on: manual ${t}() ignored \u2014 Traqio already captures this network, remove the call.`),!1):!0}helper(e,t,s,i){return this.capturesFormat(e,t)?(this.warnOnce(`helper:${e}:${t}`,`[traqio] adRevenue.${e} already captures ${t} ads: ${i} ignored for them, keep it on the formats it is documented for.`),!1):this.first(s)}first(e){return!e||typeof e!="object"?!0:this.seen.has(e)?!1:(this.seen.add(e),!0)}warnOnce(e,t){if(!this.warned.has(e)){this.warned.add(e);try{this.warn(t)}catch{}}}};g.AdRevenueGate=ge;var ms=["unknown","estimated","publisher_provided","precise"];function He(n){var e;return typeof n=="number"&&(e=ms[n])!=null?e:"unknown"}function E(n){return typeof n=="string"&&n.trim()?n:void 0}function k(n){return n&&typeof n=="object"?n:void 0}function Je(n){let e=typeof n=="string"&&/^\d+$/.test(n.trim())?Number(n):n;return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}g.GMA_FULLSCREEN_CHANNELS={rnapp_google_mobile_ads_app_open_event:"app_open",rnapp_google_mobile_ads_interstitial_event:"interstitial",rnapp_google_mobile_ads_rewarded_event:"rewarded",rnapp_google_mobile_ads_rewarded_interstitial_event:"rewarded_interstitial"};g.GMA_MIN_VERSION="12.4.0";function ye(n,e={}){var o;let t=k(n);if(!t)return;let s=E(t.currency);if(!s)return;let i=Je(t.valueMicros);if(i===void 0){if(!(typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=0))return;i=Math.round(t.value*1e6)}let r=k((o=k(t.responseInfo))==null?void 0:o.loadedAdapterResponse);return{valueMicros:i,currency:s,precision:He(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:E(r==null?void 0:r.adSourceName)}}function ze(n,e){let t=k(e),s=k(t==null?void 0:t.body);if(!(!t||(s==null?void 0:s.type)!=="paid"))return ye(s.data,{adUnitId:E(t.adUnitId),adFormat:g.GMA_FULLSCREEN_CHANNELS[n]})}function Ze(n){let e=k(n);if((e==null?void 0:e.type)==="paid")return ye(e,{adFormat:"native"})}g.MAX_RN_REVENUE_EVENTS=["OnBannerAdRevenuePaid","OnMRecAdRevenuePaid","OnInterstitialAdRevenuePaid","OnRewardedAdRevenuePaid","OnAppOpenAdRevenuePaid"];g.MAX_RN_MIN_VERSION="5.0.0";function et(n){let e=k(n);if(!(!e||typeof e.revenue!="number"))return{revenue:e.revenue,revenuePrecision:E(e.revenuePrecision),adUnitId:E(e.adUnitId),format:E(e.adFormat),networkName:E(e.networkName)}}g.CAPACITOR_ADMOB_PAID_EVENTS={bannerAdPaid:"banner",nativeAdPaid:"native",interstitialAdImpression:"interstitial",onRewardedVideoAdImpression:"rewarded",onRewardedInterstitialAdImpression:"rewarded_interstitial",appOpenAdImpression:"app_open"};function Ss(n,e){let t=k(n),s=Je(t==null?void 0:t.valueMicros),i=E(t==null?void 0:t.currencyCode);if(!(!t||s===void 0||!i))return{valueMicros:s,currency:i,precision:He(t.precision),adUnitId:E(t.adUnitId),adFormat:e,adSourceName:E(t.networkName)}}function $e(n,e){var t,s,i,r,o;try{return(r=(s=(t=n.TurboModuleRegistry)==null?void 0:t.get)==null?void 0:s.call(t,e))!=null?r:(i=n.NativeModules)==null?void 0:i[e]}catch{return(o=n.NativeModules)==null?void 0:o[e]}}var vs=["interstitial","rewarded","rewarded_interstitial","app_open"];function _s(n,e,t){var a,l,f,T;if(!t)try{t=(N(),x(D))}catch{return{coverage:{},stop:()=>{}}}let s=[],i={},r=(p,m,S=d=>d)=>d=>{try{let y=p(d);y&&m(y,S(d))}catch{}},o=p=>{var m,S;return(S=k((m=k(p))==null?void 0:m.body))==null?void 0:S.data};if(n.admob){i.admob=[];for(let[S,d]of Object.entries(g.GMA_FULLSCREEN_CHANNELS)){let y=(a=t.DeviceEventEmitter)==null?void 0:a.addListener(S,r(_=>ze(S,_),e.admob,o));y&&(s.push(y),i.admob.push(d))}let p=$e(t,"RNGoogleMobileAdsNativeModule"),m=r(Ze,e.admob);try{if(p&&typeof p.onAdEvent=="function")s.push(p.onAdEvent(m)),i.admob.push("native");else if(p&&t.NativeEventEmitter){let S=new t.NativeEventEmitter(((l=t.Platform)==null?void 0:l.OS)==="ios"?p:void 0);s.push(S.addListener("RNGMANativeAdEvent",m)),i.admob.push("native")}}catch{}}if(n.applovinMax){let p=$e(t,"AppLovinMAX");if(p&&t.NativeEventEmitter)try{let m=[...g.MAX_RN_REVENUE_EVENTS];try{let d=(T=(f=p.getConstants)==null?void 0:f.call(p))!=null?T:{},y=Object.keys(d).filter(_=>/^ON_.*_AD_REVENUE_PAID$/.test(_)).map(_=>d[_]).filter(_=>typeof _=="string");y.length&&(m=[...new Set([...y,...m])])}catch{}let S=new t.NativeEventEmitter(p);for(let d of m)s.push(S.addListener(d,r(et,e.applovinMax)));i.applovinMax=[...vs]}catch{}}return{coverage:i,stop:()=>{for(let p of s.splice(0))try{p.remove()}catch{}}}}});var vt=P(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u.Traqio=u.Client=u.AdRevenueGate=u.watchReactNativeAds=u.fromMaxAdInfo=u.fromGoogleMobileAdsPaid=u.fromGoogleMobileAdsNativeAd=u.fromGoogleMobileAdsChannel=u.fromCapacitorAdMob=u.MAX_RN_REVENUE_EVENTS=u.MAX_RN_MIN_VERSION=u.GMA_MIN_VERSION=u.GMA_FULLSCREEN_CHANNELS=u.CAPACITOR_ADMOB_PAID_EVENTS=u.isTrackingUrl=u.isOpenUrl=u.ANALYTICS_SESSION_IDLE_MS=u.reportAdServicesToken=u.Skan=u.SDK_VERSION=void 0;u.normalizeMetaInstallReferrers=gt;u.normalizeAdvertisingId=yt;u.fromMaxAd=H;u.detectDebug=mt;u.isLocalPage=St;var bs=ue(),h=de(),Is=fe(),R=pe(),B=me();u.SDK_VERSION="0.12.0";var As=ue();Object.defineProperty(u,"Skan",{enumerable:!0,get:function(){return As.Skan}});var Es=fe();Object.defineProperty(u,"reportAdServicesToken",{enumerable:!0,get:function(){return Es.reportAdServicesToken}});var ks=de();Object.defineProperty(u,"ANALYTICS_SESSION_IDLE_MS",{enumerable:!0,get:function(){return ks.ANALYTICS_SESSION_IDLE_MS}});var pt=pe();Object.defineProperty(u,"isOpenUrl",{enumerable:!0,get:function(){return pt.isOpenUrl}});Object.defineProperty(u,"isTrackingUrl",{enumerable:!0,get:function(){return pt.isTrackingUrl}});var I=me();Object.defineProperty(u,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return I.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(u,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return I.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(u,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return I.GMA_MIN_VERSION}});Object.defineProperty(u,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return I.MAX_RN_MIN_VERSION}});Object.defineProperty(u,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return I.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(u,"fromCapacitorAdMob",{enumerable:!0,get:function(){return I.fromCapacitorAdMob}});Object.defineProperty(u,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return I.fromGoogleMobileAdsChannel}});Object.defineProperty(u,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return I.fromGoogleMobileAdsNativeAd}});Object.defineProperty(u,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return I.fromGoogleMobileAdsPaid}});Object.defineProperty(u,"fromMaxAdInfo",{enumerable:!0,get:function(){return I.fromMaxAdInfo}});Object.defineProperty(u,"watchReactNativeAds",{enumerable:!0,get:function(){return I.watchReactNativeAds}});Object.defineProperty(u,"AdRevenueGate",{enumerable:!0,get:function(){return I.AdRevenueGate}});var ws="traq_install_sent",Ts="traq_install_sent_debug",tt="traq_install_attempts",Rs="traq_ad_id_sent",Ns="traq_ad_id_sent_debug",K="/ingest/advertising-id",Se="traq_ad_id_consent",Os="traq_ad_id_answer_sent",Ms="traq_ad_id_answer_sent_debug",st="traq_referrer",nt="traq_queue",it="traq_ad_queue",rt="traq_device_id",ot="traq_last_session",at="traq_erased",O="traq_deferred_link",ve="traq_deferred_consent_retry_until",Ps=60*6e4,ut="traq_consent",ct="traq_analytics_queue",_e="traq_analytics_session",lt="traq_super_props",dt="traq_groups",xs="/ingest/analytics",Cs=50,be=1e3,Ds=100,Ls=20,Us=new Set([400,413,422]),qs=new Set([401,403]),ht=500,Ks=100,ft=1e3,$=1e3,Gs=300*1e3,Vs=3e3,Fs=3,js=1800*1e3,Ys=["facebook","instagram","facebook_lite"];function gt(n){if(!Array.isArray(n))return[];let e=[];for(let t of n){if(!t||typeof t!="object")continue;let s=t;if(typeof s.provider!="string"||!Ys.includes(s.provider)||typeof s.installReferrer!="string"||!s.installReferrer.trim())continue;let i=s.isCt===1||s.isCt===!0?1:s.isCt===0||s.isCt===!1?0:null;if(i===null)continue;let r=typeof s.actualTimestamp=="number"&&Number.isFinite(s.actualTimestamp)&&s.actualTimestamp>0?s.actualTimestamp:void 0;e.push({provider:s.provider,installReferrer:s.installReferrer,isCt:i,...r!==void 0?{actualTimestamp:r}:{}})}return e}var Ws=["not_determined","restricted","denied","authorized"],Xs={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},Qs={BANNER:"banner",LEADER:"banner",MREC:"banner",INTER:"interstitial",INTERSTITIAL:"interstitial",REWARDED:"rewarded",REWARDED_INTER:"rewarded_interstitial",NATIVE:"native",APPOPEN:"app_open",APP_OPEN:"app_open"},Bs="00000000-0000-0000-0000-000000000000";function yt(n){if(typeof n!="string")return;let e=n.trim();if(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(e))return e===Bs?void 0:e}function H(n){var e,t,s;if(typeof n.revenue=="number"&&Number.isFinite(n.revenue)&&n.revenue>=0)return{valueMicros:Math.round(n.revenue*1e6),currency:"USD",precision:(t=Xs[(e=n.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:n.adUnitId,adFormat:Qs[((s=n.format)!=null?s:"").toUpperCase()],adSourceName:n.networkName,ts:n.ts}}function M(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)})}function $s(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Hs(){var n;try{let e=(N(),x(D)),t=(n=e==null?void 0:e.default)!=null?n:e;if(typeof(t==null?void 0:t.getItem)=="function"&&typeof(t==null?void 0:t.setItem)=="function")return{getItem:s=>t.getItem(s),setItem:(s,i)=>t.setItem(s,i)}}catch{}}function Js(){var n,e;try{let t=(e=(n=(N(),x(D)))==null?void 0:n.Platform)==null?void 0:e.OS;return t==="ios"||t==="android"?t:void 0}catch{return}}function zs(){var n,e;if(typeof window!="undefined")return!1;try{return((e=(n=(N(),x(D)))==null?void 0:n.Platform)==null?void 0:e.OS)==="web"}catch{return!1}}var J=class{constructor(){this.queue=[],this.adQueue=[],this.adGate=new B.AdRevenueGate,this.adBatchId=null,this.context={sdkVersion:u.SDK_VERSION},this.referrer=null,this.started=!1,this.flushing=!1,this.flushTimer=null,this.retryMs=$,this.keyRejected=null,this.skan=new bs.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null,this.att=null,this.adIdConsent=null,this.adIdSync=null,this.debug=!1,this.contextReady=!1,this.analyticsQueue=[],this.analyticsSession=null,this.earlyAnalytics=[],this.currentScreen=null,this.superProps={},this.groups={},this.resetBeforeInit=!1,this.maxRevenuePaid=e=>{try{let t=(0,B.fromMaxAdInfo)(e),s=t&&H(t);s&&this.adGate.helper("applovinMax",s.adFormat,e,"Traqio.maxRevenuePaid")&&this.queueAdRevenue(s,"applovin_max","auto")}catch{}}}get isDebug(){return this.debug}async init(e){var t,s;if(!this.started&&!zs()){if(this.started=!0,this.opts={collectContext:!0,...e,userId:(t=e.userId)!=null?t:this.earlyUserId,storage:(s=e.storage)!=null?s:Hs()},this.opts.storage||console.warn("[traqio] no storage available \u2014 pass `storage` to init() or install @react-native-async-storage/async-storage, otherwise the install is re-sent at every launch."),this.debug=await mt(e),await this.restoreConsent(e.consent),await this.restoreAdvertisingIdConsent(),await this.restoreQueue(),await this.restoreAdQueue(),await this.restoreAnalytics(),await this.buildContext(),this.contextReady=!0,await this.restoreErased()){this.earlyAnalytics=[];return}if(this.isWeb)this.earlyAnalytics=[];else for(let i of this.earlyAnalytics.splice(0))this.pushAnalytics(i,!1);if(!this.isWeb){let i=!!this.opts.storage&&!await this.opts.storage.getItem(this.installSentKey).catch(()=>"1");await this.sendInstallOnce(),this.syncAdvertisingId(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(i).then(r=>r!=null?r:this.retryDeferredWithConsent()),this.wireDeepLinks())}this.isWeb?this.maybeStartSession(!1):await this.maybeStartSession(!0),await this.initSkan(),await this.initAppleAds(),this.wireLifecycle(),this.wireAdRevenue(),(this.queue.length||this.adQueue.length||this.analyticsQueue.length)&&this.scheduleFlush(0)}}wireAdRevenue(){var s,i;let e=this.opts.adRevenue;if(!e||this.isWeb||!(e.admob||e.applovinMax))return;let t={admob:(r,o)=>{this.adGate.first(o)&&this.queueAdRevenue(r,"admob","auto")},applovinMax:(r,o)=>{let a=H(r);a&&this.adGate.first(o)&&this.queueAdRevenue(a,"applovin_max","auto")}};try{let r=(s=this.opts.native)!=null&&s.watchAdRevenue?(i=this.opts.native.watchAdRevenue(e,t))!=null?i:e:(0,B.watchReactNativeAds)(e,t).coverage;this.adGate.arm(r)}catch{}}track(e,t){var i,r;if(!this.started||this.erased)return;let s=((i=t==null?void 0:t.transactionId)==null?void 0:i.trim())||void 0;this.enqueue({name:e,eventId:M(),value:t==null?void 0:t.value,currency:t==null?void 0:t.currency,...s?{transactionId:s,store:(r=t==null?void 0:t.store)!=null?r:this.defaultStore()}:{}}),this.skan.markEvent(e),t!=null&&t.value&&this.skan.addRevenue(t.value)}capture(e,t){try{let s=(0,h.cleanEventName)(e);if(!s)return;let i=(0,h.cleanProps)(t);this.queueAnalytics({kind:"custom",name:s,ts:Date.now(),...i?{props:i}:{}})}catch{}}identify(e,t,s){try{let i=typeof e=="string"?e.trim():"";if(!i)return;this.opts?this.setUserId(i):this.earlyUserId=i;let r=(0,h.cleanTraits)(t),o=(0,h.cleanTraits)(s);if(!Object.keys(r).length&&!Object.keys(o).length)return;this.queueAnalytics({kind:"identify",ts:Date.now(),userId:i,...Object.keys(r).length?{set:r}:{},...Object.keys(o).length?{setOnce:o}:{}})}catch{}}register(e){try{this.superProps=(0,h.cleanTraits)({...this.superProps,...(0,h.cleanTraits)(e)}),this.persistSuperProps()}catch{}}unregister(e){if(typeof e!="string"||!(e in this.superProps))return;let t={...this.superProps};delete t[e],this.superProps=t,this.persistSuperProps()}getSuperProperties(){return{...this.superProps}}group(e,t,s,i){try{let r=(0,h.withGroup)(this.groups,e,t);if(!r)return;this.groups=r.groups,this.persistGroups();let o=(0,h.cleanTraits)(s),a=(0,h.cleanTraits)(i);if(!r.changed&&!Object.keys(o).length&&!Object.keys(a).length)return;this.queueAnalytics({kind:"group",ts:Date.now(),groupType:r.type,groupKey:r.key,...Object.keys(o).length?{set:o}:{},...Object.keys(a).length?{setOnce:a}:{}})}catch{}}resetGroups(){this.groups={},this.persistGroups()}getGroups(){return{...this.groups}}alias(e){try{let t=this.opts?this.opts.userId:this.earlyUserId,s=(0,h.cleanUserId)(e);if(!t||!s||s===t)return;this.queueAnalytics({kind:"alias",ts:Date.now(),userId:t,previousId:s})}catch{}}reset(){try{let e=this.opts?this.opts.userId:this.earlyUserId;if(e){for(let t of this.analyticsQueue)!(0,h.isEntry)(t.kind)&&t.asUser===void 0&&(t.asUser=e);for(let t of this.earlyAnalytics)!(0,h.isEntry)(t.kind)&&t.asUser===void 0&&(t.asUser=e)}if(this.opts?this.opts.userId=void 0:(this.earlyUserId=void 0,this.resetBeforeInit=!0),this.superProps={},this.groups={},this.analyticsSession=null,this.currentScreen=null,this.opts&&this.isWeb)return;this.persistSuperProps(),this.persistGroups(),this.forgetAnalyticsSession()}catch{}}exposure(e,t,s){var i;try{let r=(0,h.exposureProps)(e,t,s);r&&this.capture(h.EXPOSURE_EVENT,(i=(0,h.cleanProps)(r))!=null?i:{experiment:r.experiment,variant:r.variant})}catch{}}screen(e,t){try{let s=(0,h.cleanScreenName)(e);if(!s)return;let i=Date.now(),r=this.analyticsSession!==null&&i-this.analyticsSession.last<=h.ANALYTICS_SESSION_IDLE_MS;if(s===this.currentScreen&&r)return;this.currentScreen=s;let o=(0,h.cleanProps)(t);this.queueAnalytics({kind:"pageview",ts:i,screen:s,...o?{props:o}:{}})}catch{}}trackScreens(e){let t=()=>{try{let i=e.getCurrentRoute();i!=null&&i.name&&this.screen(i.name)}catch{}},s;try{s=e.addListener("state",t)}catch{s=void 0}return t(),()=>{try{typeof s=="function"&&s()}catch{}}}get hostPlatform(){var e,t;return(t=(e=this.opts.native)==null?void 0:e.platform)!=null?t:Js()}defaultStore(){let e=this.hostPlatform;return e==="ios"?"app_store":e==="android"?"play_store":void 0}trackAdRevenue(e){this.adGate.manual("admob","trackAdRevenue")&&this.queueAdRevenue(e,"admob","manual")}trackMaxAdRevenue(e){if(!this.adGate.manual("applovinMax","trackMaxAdRevenue"))return;let t=H(e);t&&this.queueAdRevenue(t,"applovin_max","manual")}admobPaid(e,t="banner"){return s=>{try{let i=(0,B.fromGoogleMobileAdsPaid)(s,{adUnitId:e,adFormat:t});i&&this.adGate.helper("admob",t,s,"Traqio.admobPaid()")&&this.queueAdRevenue(i,"admob","auto")}catch{}}}queueAdRevenue(e,t,s){var i;!this.started||this.erased||!(e.valueMicros>=0)||!e.currency||(this.adQueue.push({...e,source:t,origin:s,impressionId:M(),ts:(i=e.ts)!=null?i:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>ft&&this.adQueue.splice(0,this.adQueue.length-ft),this.persistAdQueue(),this.scheduleFlush())}getInstallReferrer(){return this.started?this.readReferrer():Promise.resolve({status:"unavailable",retryable:!1})}onDeepLink(e){this.deepLinkListeners.add(e);let t=this.undelivered.splice(0);for(let s of t)e(s);return()=>{this.deepLinkListeners.delete(e)}}async handleUrl(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,R.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),s=(0,R.isOpenUrl)(e),i=(0,R.toDeepLink)(t,s,e);return i&&s&&await this.keepDeferred(i),i&&this.emitDeepLink(i),i}getDeferredDeepLink(){var e;return(e=this.deferred)!=null?e:Promise.resolve(null)}async redeemDeepLinkCode(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!e.trim())return null;let t=await this.postJson({code:e},"/deeplink/code"),s=(0,R.toDeepLink)(t,!0);return s?(await this.keepDeferred(s),this.emitDeepLink(s),s):null}async forgetMe(){return this.started?this.erased?!0:await this.post({deviceId:this.context.deviceId,appUserId:this.opts.userId},"/privacy/forget")?(await this.markErased(),!0):!1:!1}async setConsent(e){var t,s;this.consent=e?"granted":"denied",await((s=(t=this.opts)==null?void 0:t.storage)==null?void 0:s.setItem(ut,this.consent).catch(()=>{})),e&&this.deferred&&!this.erased&&(this.deferred=this.deferred.then(i=>i!=null?i:this.retryDeferredWithConsent()),await this.deferred)}async setAdvertisingIdConsent(e){var t,s;this.adIdConsent=e?"granted":"denied",!(!this.started||!this.opts)&&(await((t=this.opts.storage)==null?void 0:t.setItem(Se,this.adIdConsent).catch(()=>{})),!(this.isWeb||this.erased)&&(await((s=this.adIdSync)==null?void 0:s.catch(()=>{})),await this.syncAdvertisingId()))}get forgotten(){return this.erased}setUserId(e){this.opts&&(this.opts.userId=e)}flush(){this.erased||(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.drain())}appOpened(){!this.started||this.erased||(this.maybeStartSession(),this.syncAdvertisingId())}get skanMapping(){return this.skan.activeMapping}async initAppleAds(){if(this.opts.appleAds===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.getAttributionToken||await(0,Is.reportAdServicesToken)({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,deviceId:this.context.deviceId,userId:this.opts.userId,storage:this.opts.storage,native:{getAttributionToken:()=>e.getAttributionToken()},debug:this.debug})}async initSkan(){if(this.opts.skan===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.updateConversionValue||await this.skan.init({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,storage:this.opts.storage,native:{updateConversionValue:(t,s,i)=>{var r;return(r=e.updateConversionValue)==null?void 0:r.call(e,t,s,i)}}})}async resolveDeferredOnce(e){let t=this.opts.storage;try{let l=await(t==null?void 0:t.getItem(O));if(l)return(0,R.upgradeStoredDeepLink)(JSON.parse(l))}catch{}if(!e&&!await(t==null?void 0:t.getItem(`${O}_pending`).catch(()=>null)))return null;let s=this.hostPlatform,i=s==="android"?await this.readReferrer():null;await(t==null?void 0:t.setItem(`${O}_pending`,"1").catch(()=>{}));let r=await this.askDeferred(s,i==null?void 0:i.referrer);if(!r)return null;let o=(0,R.toDeepLink)(r,!0),a=await this.storedDeferred();if(a)return a;try{await(t==null?void 0:t.setItem(O,JSON.stringify(o))),!o&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(ve,String(Date.now()+Ps)))}catch{}return o&&this.emitDeepLink(o),o}askDeferred(e,t){return this.postJson({platform:e,installReferrer:t,...this.consent?{consent:this.consent}:{},...this.context.osVersion?{osVersion:this.context.osVersion}:{},...this.context.deviceModel?{deviceModel:this.context.deviceModel}:{}},"/deeplink/deferred")}async retryDeferredWithConsent(){var r,o;let e=(r=this.opts)==null?void 0:r.storage;if(!e||this.consent!=="granted"||this.opts.deepLinking===!1||this.isWeb)return null;let t=Number(await e.getItem(ve).catch(()=>null));if(!t||(await e.setItem(ve,"").catch(()=>{}),Date.now()>t))return null;let s=await this.storedDeferred();if(s)return s;let i=(0,R.toDeepLink)(await this.askDeferred(this.hostPlatform,void 0),!0);return i?(await((o=this.opts.storage)==null?void 0:o.setItem(O,JSON.stringify(i)).catch(()=>{})),this.emitDeepLink(i),i):null}async storedDeferred(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(O));return t?(0,R.upgradeStoredDeepLink)(JSON.parse(t)):null}catch{return null}}async keepDeferred(e){var t;await this.storedDeferred()||(await((t=this.opts.storage)==null?void 0:t.setItem(O,JSON.stringify(e)).catch(()=>{})),this.deferred=Promise.resolve(e))}emitDeepLink(e){if(!this.deepLinkListeners.size){this.undelivered.push(e);return}for(let t of this.deepLinkListeners)try{t(e)}catch{}}wireDeepLinks(){try{let{Linking:e}=(N(),x(D));if(!e)return;e.getInitialURL().then(t=>t&&this.handleUrl(t)).catch(()=>{}),e.addEventListener("url",({url:t})=>{this.handleUrl(t)})}catch{}}get isWeb(){var e;return((e=this.opts)==null?void 0:e.platform)==="web"}get installSentKey(){return this.debug?Ts:ws}get adIdSentKey(){return this.debug?Ns:Rs}get adIdAnswerSentKey(){return this.debug?Ms:Os}get collectsAdvertisingId(){return this.adIdConsent?this.adIdConsent==="granted":this.opts.waitForAdvertisingIdConsent?!1:this.opts.collectAdvertisingId===!0}async restoreAdvertisingIdConsent(){var t,s;if(this.adIdConsent){await((t=this.opts.storage)==null?void 0:t.setItem(Se,this.adIdConsent).catch(()=>{}));return}let e=await((s=this.opts.storage)==null?void 0:s.getItem(Se).catch(()=>null));(e==="granted"||e==="denied")&&(this.adIdConsent=e)}debugField(){return this.debug?{debug:!0}:{}}wireLifecycle(){let e={background:()=>this.flush(),foreground:()=>this.appOpened()};if(this.opts.lifecycle){this.opts.lifecycle(e);return}try{let{AppState:t}=(N(),x(D));t.addEventListener("change",s=>{if(s!=="active"){this.scheduleFlush(0);return}this.maybeStartSession(),this.syncAdvertisingId()})}catch{}}async restoreErased(){var e;try{this.erased=await((e=this.opts.storage)==null?void 0:e.getItem(at))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var e;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,this.analyticsQueue=[],this.earlyAnalytics=[],this.superProps={},this.groups={},await this.persistSuperProps(),await this.persistGroups(),await this.persistQueue(),await this.persistAdQueue(),await this.persistAnalyticsQueue();try{await((e=this.opts.storage)==null?void 0:e.setItem(at,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>ht&&this.queue.splice(0,this.queue.length-ht),this.persistQueue(),this.scheduleFlush()}queueAnalytics(e){var s,i;if(this.erased)return;let t=e;if(!(0,h.isEntry)(e.kind)){let r=(i=(s=e.screen)!=null?s:this.currentScreen)!=null?i:void 0,o=(0,h.withSuperProps)(e.props,this.superProps),a=Object.keys(this.groups).length?{...this.groups}:void 0;t={...e,...r?{screen:r}:{},...o?{props:o}:{},...a?{groups:a}:{}}}if(!this.started){this.earlyAnalytics.length<Ds&&this.earlyAnalytics.push(t);return}this.isWeb||this.pushAnalytics(t)}pushAnalytics(e,t=!0){var s,i,r;(0,h.isEntry)(e.kind)?this.analyticsQueue.push({...e,sessionId:(i=(s=this.analyticsSession)==null?void 0:s.id)!=null?i:""}):(this.analyticsSession=(0,h.touchSession)(this.analyticsSession,e.ts,M),this.analyticsQueue.push({...e,id:(r=e.id)!=null?r:M(),sessionId:this.analyticsSession.id})),this.analyticsQueue.length>be&&this.analyticsQueue.splice(0,this.analyticsQueue.length-be),this.persistAnalyticsQueue(),t&&this.scheduleFlush()}async restoreAnalytics(){var e,t,s,i,r;try{let o=await((e=this.opts.storage)==null?void 0:e.getItem(ct)),a=o?JSON.parse(o):null;Array.isArray(a)&&(this.analyticsQueue=[...a,...this.analyticsQueue].slice(-be))}catch{}try{this.resetBeforeInit||(s=this.analyticsSession)!=null||(this.analyticsSession=(0,h.parseSession)(await((t=this.opts.storage)==null?void 0:t.getItem(_e))))}catch{}if(this.resetBeforeInit){this.resetBeforeInit=!1,await this.persistSuperProps(),await this.persistGroups(),await this.forgetAnalyticsSession();return}try{let o=await((i=this.opts.storage)==null?void 0:i.getItem(lt)),a=Object.keys(this.superProps).length>0;o&&(this.superProps=(0,h.cleanTraits)({...(0,h.cleanTraits)(JSON.parse(o)),...this.superProps})),a&&await this.persistSuperProps()}catch{}try{let o=await((r=this.opts.storage)==null?void 0:r.getItem(dt)),a=Object.keys(this.groups).length>0;o&&(this.groups=(0,h.cleanGroups)({...(0,h.cleanGroups)(JSON.parse(o)),...this.groups})),a&&await this.persistGroups()}catch{}}async forgetAnalyticsSession(){var e;if(this.opts)try{await((e=this.opts.storage)==null?void 0:e.setItem(_e,"")),await this.persistAnalyticsQueue()}catch{}}async persistGroups(){var e;if(this.opts)try{await((e=this.opts.storage)==null?void 0:e.setItem(dt,JSON.stringify(this.groups)))}catch{}}async persistSuperProps(){var e;if(this.opts)try{await((e=this.opts.storage)==null?void 0:e.setItem(lt,JSON.stringify(this.superProps)))}catch{}}async persistAnalyticsQueue(){var e,t;try{await((e=this.opts.storage)==null?void 0:e.setItem(ct,JSON.stringify(this.analyticsQueue))),this.analyticsSession&&await((t=this.opts.storage)==null?void 0:t.setItem(_e,JSON.stringify(this.analyticsSession)))}catch{}}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(nt));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(nt,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,s;try{let i=await((e=this.opts.storage)==null?void 0:e.getItem(it));if(!i)return;let r=JSON.parse(i);this.adQueue=(t=r.items)!=null?t:[],this.adBatchId=(s=r.batchId)!=null?s:null}catch{}}async persistAdQueue(){var e;try{let t={batchId:this.adBatchId,items:this.adQueue};await((e=this.opts.storage)==null?void 0:e.setItem(it,JSON.stringify(t)))}catch{}}async maybeStartSession(e=!1){var r,o,a;if(this.erased)return;let t=Date.now();if(!e){let l=Number(await((r=this.opts.storage)==null?void 0:r.getItem(ot).catch(()=>null)))||0;if(l&&t-l<js)return}let s=(o=this.context.deviceId)!=null?o:await this.getOrCreateDeviceId();if(await this.post({deviceId:s,appUserId:this.opts.userId,sessionId:M(),ts:Math.floor(t/1e3),context:this.context},"/ingest/session"))try{await((a=this.opts.storage)==null?void 0:a.setItem(ot,String(t)))}catch{}}async buildContext(){var t,s,i;if(!this.opts.collectContext){this.context={sdkVersion:u.SDK_VERSION};return}let e={};try{e=(i=await((s=(t=this.opts.native)==null?void 0:t.getContext)==null?void 0:s.call(t)))!=null?i:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:e.deviceModel,osVersion:e.osVersion,appVersion:this.opts.appVersion,locale:$s(),sdkVersion:u.SDK_VERSION}}async getOrCreateDeviceId(){var t,s;try{let i=await((t=this.opts.storage)==null?void 0:t.getItem(rt));if(i)return i}catch{}let e=M();try{await((s=this.opts.storage)==null?void 0:s.setItem(rt,e))}catch{}return e}async readReferrer(){var s,i;if(this.referrer)return this.referrer;try{let r=await((s=this.opts.storage)==null?void 0:s.getItem(st));if(r)return this.referrer=JSON.parse(r)}catch{}let e=this.opts.native;if((e==null?void 0:e.platform)!=="android")return{status:e?"not_supported_platform":"unavailable",retryable:!1};let t=await e.getInstallReferrer().catch(()=>({status:"error",retryable:!0}));if(!t.retryable){this.referrer=t;try{await((i=this.opts.storage)==null?void 0:i.setItem(st,JSON.stringify(t)))}catch{}}return t}async readMetaInstallReferrers(e){var s,i;let t=(s=this.opts.native)==null?void 0:s.getMetaInstallReferrers;if(!(e!=="android"||!t))try{let r=((i=this.opts.metaAppId)==null?void 0:i.trim())||void 0,o=gt(await t.call(this.opts.native,r));return o.length?o:void 0}catch{return}}async readAdvertisingId(){var e;if(!(!this.collectsAdvertisingId||!((e=this.opts.native)!=null&&e.getAdvertisingId)))try{return yt(await this.opts.native.getAdvertisingId())}catch{return}}async sendInstallOnce(){let e=this.opts.storage;if(e&&await e.getItem(this.installSentKey))return;let t=this.hostPlatform;if(!t){console.warn("[traqio] unknown platform \u2014 no native bridge and not React Native: the install is not reported. Pass `native: getNativeBridge()` (React Native / Expo) or your SDK's bridge to init().");return}this.opts.native||console.warn(`[traqio] the Traqio native module is missing on ${t} (Expo Go, or not linked in this build): install reported without its attribution signals. Use a development / EAS build.`);let s=await this.readReferrer();if(s.retryable&&e){let a=Number(await e.getItem(tt))||0;if(a+1<Fs){await e.setItem(tt,String(a+1));return}}let i=await this.readAdvertisingId(),r=await this.readMetaInstallReferrers(t);await this.post({install:{platform:t,installReferrer:s.referrer,...r?{metaInstallReferrers:r}:{},appUserId:this.opts.userId,advertisingId:i,...this.opts.waitForAdvertisingIdConsent&&!this.adIdConsent?{advertisingIdPending:!0}:{},context:this.context}})&&(await(e==null?void 0:e.setItem(this.installSentKey,"1")),i&&await(e==null?void 0:e.setItem(this.adIdSentKey,i).catch(()=>{})))}syncAdvertisingId(){return this.adIdSync?this.adIdSync:(this.adIdSync=this.postAdvertisingIdIfChanged().finally(()=>{this.adIdSync=null}),this.adIdSync)}async postAdvertisingIdIfChanged(){var t;let e=this.opts.storage;if(!(this.isWeb||this.erased||!e))try{if(!await e.getItem(this.installSentKey))return;let s=this.adIdConsent,r={deviceId:(t=this.context.deviceId)!=null?t:await this.getOrCreateDeviceId(),appUserId:this.opts.userId};if(s==="denied"){if(await e.getItem(this.adIdAnswerSentKey)==="denied")return;await this.post({...r,advertisingIdConsent:"denied"},K)&&(await e.setItem(this.adIdAnswerSentKey,"denied"),await e.setItem(this.adIdSentKey,""));return}if(!this.collectsAdvertisingId)return;let o=s?{advertisingIdConsent:s}:{},a=await this.readAdvertisingId();if(a){if(await e.getItem(this.adIdSentKey)===a)return;await this.post({...r,advertisingId:a,...o},K)&&(await e.setItem(this.adIdSentKey,a),s&&await e.setItem(this.adIdAnswerSentKey,s));return}s==="granted"&&await e.getItem(this.adIdAnswerSentKey)!=="granted"&&await this.post({...r,advertisingIdConsent:"granted"},K)&&await e.setItem(this.adIdAnswerSentKey,"granted")}catch{}}scheduleFlush(e=Vs){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},e))}async drain(){var e,t;if(!(this.erased||!this.contextReady)&&!(this.flushing||!this.queue.length&&!this.adQueue.length&&!this.analyticsQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let s=this.queue.slice(0,Ls),i=await this.send({events:s,appUserId:this.opts.userId,deviceId:this.context.deviceId});if(i==="retry")return this.backOff();i==="refused"&&console.warn(`[traqio] the server refused ${s.length} event(s) as malformed \u2014 dropped, not retried`),this.queue.splice(0,s.length),await this.persistQueue(),this.retryMs=$}for(;this.adQueue.length;){let s=(e=this.adQueue[0].source)!=null?e:"admob",i=this.adQueue.findIndex(a=>{var l;return((l=a.source)!=null?l:"admob")!==s}),r=this.adQueue.slice(0,Math.min(Ks,i===-1?this.adQueue.length:i));if(this.adBatchId||(this.adBatchId=M(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:s,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:r.map(({source:a,...l})=>l)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,r.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=$}for(;this.analyticsQueue.length;){let s=(0,h.nextAnalyticsBatch)(this.analyticsQueue,this.opts.userId,Cs),i=await this.send({anonymousId:(t=this.context.deviceId)!=null?t:await this.getOrCreateDeviceId(),userId:s.userId,platform:this.hostPlatform,events:s.events},xs);if(i==="retry")return this.backOff();i==="refused"&&console.warn(`[traqio] the server refused ${s.taken} analytics event(s) as malformed \u2014 dropped, not retried`),this.analyticsQueue.splice(0,s.taken),await this.persistAnalyticsQueue(),this.retryMs=$}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,Gs),this.scheduleFlush(this.retryMs)}async postJson(e,t){try{let s=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...this.debugField()}),...this.keepalive()});return this.noteStatus(s.status,s.ok),s.ok?await s.json():null}catch{return null}}noteStatus(e,t){var i,r;if(t){this.keyRejected=null;return}if(!qs.has(e)||this.keyRejected===e)return;this.keyRejected=e;let s=`[traqio] the server rejected the sdkKey (HTTP ${e}) \u2014 check the key in the console. Events are kept and retried with backoff until it is accepted.`;console.warn(s);try{(r=(i=this.opts).onError)==null||r.call(i,{code:"invalid_sdk_key",status:e,message:s})}catch{}}async restoreConsent(e){var s;if(e!==void 0)return this.setConsent(e);if(this.consent)return this.setConsent(this.consent==="granted");let t=await((s=this.opts.storage)==null?void 0:s.getItem(ut).catch(()=>null));(t==="granted"||t==="denied")&&(this.consent=t)}keepalive(){return this.isWeb?{keepalive:!0}:{}}get asksTrackingAuthorization(){var e;return((e=this.opts.native)==null?void 0:e.platform)==="ios"&&typeof this.opts.native.getTrackingAuthorization=="function"}async readTrackingAuthorization(){var e,t;try{let s=await((t=(e=this.opts.native)==null?void 0:e.getTrackingAuthorization)==null?void 0:t.call(e));Ws.includes(s)&&(this.att=s!=null?s:null)}catch{}return this.att}async post(e,t="/ingest"){return await this.send(e,t)==="ok"}async send(e,t="/ingest"){let s=this.consent&&(t==="/ingest"||t==="/ingest/session"||t===K)?{consent:this.consent}:{},i=(t==="/ingest"||t===K)&&this.asksTrackingAuthorization?await this.readTrackingAuthorization():null;try{let r=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...s,...i?{att:i}:{},...this.debugField()}),...this.keepalive()});return this.noteStatus(r.status,r.ok),r.ok?"ok":Us.has(r.status)?"refused":"retry"}catch{return"retry"}}};u.Client=J;async function mt(n){var e,t;if(n.debug!==void 0)return n.debug;if(n.platform==="web")return St();if(globalThis.__DEV__===!0)return!0;try{return await((t=(e=n.native)==null?void 0:e.isDebugBuild)==null?void 0:t.call(e))===!0}catch{return!1}}function St(n=globalThis.location){if(!n)return!1;if(n.protocol==="file:")return!0;let e=n.hostname.toLowerCase().replace(/^\[|\]$/g,"");return e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e==="::1"||e==="0.0.0.0"||/^127\.\d+\.\d+\.\d+$/.test(e)}u.Traqio=new J});var Lt=Wt(vt(),1);var Ae="traq_";function Ee(){return typeof document=="undefined"?void 0:document}function G(n){let e=Ee();if(!e)return null;for(let t of e.cookie?e.cookie.split(";"):[]){let s=t.indexOf("=");if(!(s<0)&&t.slice(0,s).trim()===n)try{return decodeURIComponent(t.slice(s+1).trim())}catch{return null}}return null}function Ie(n,e,t,s){let i=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",r=s?`; Domain=${s}`:"";return`${n}=${encodeURIComponent(e)}; Max-Age=${Math.floor(t)}; Path=/${r}; SameSite=Lax${i}`}function _t(n){let e=Ee();if(!e||!n.includes(".")||/^[\d.]+$/.test(n)||n.includes(":"))return null;let t=n.split("."),s=`${Ae}probe`;for(let i=t.length-2;i>=0;i--){let r=t.slice(i).join(".");if(e.cookie=Ie(s,"1",10,r),G(s)==="1")return e.cookie=Ie(s,"",0,r),r}return null}function L(n,e,t,s){let i=Ee();if(i)try{i.cookie=Ie(n,e,t,s)}catch{}}function V(n,e){L(n,"",0,e)}var F="traq_device_id",j="traq_internal",ke=new Set([F,j]),Zs=395*24*60*60;function z(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var Z=class{constructor(e,t,s){this.persistent=e;this.cookieDomain=t;this.cookies=s;this.memory=new Map}get isPersistent(){return this.persistent}async getItem(e){return this.getSync(e)}async setItem(e,t){this.setSync(e,t)}getSync(e){var s,i,r;if(this.memory.has(e))return(s=this.memory.get(e))!=null?s:null;if(!this.persistent)return null;let t=null;try{t=(r=(i=z())==null?void 0:i.getItem(e))!=null?r:null}catch{}return t===null&&this.cookies&&ke.has(e)&&(t=G(e)),t}setSync(e,t){if(!this.persistent){this.memory.set(e,t);return}let s=!1;try{let i=z();i&&(i.setItem(e,t),s=!0)}catch{}s||this.memory.set(e,t),this.cookies&&ke.has(e)&&L(e,t,Zs,this.cookieDomain())}removeSync(e){var t;this.memory.delete(e);try{(t=z())==null||t.removeItem(e)}catch{}this.cookies&&V(e,this.cookieDomain())}enable(){if(this.persistent)return;this.persistent=!0;let e=[...this.memory];this.memory.clear();for(let[t,s]of e)this.setSync(t,s)}disable(){if(!this.persistent)return;let e=z(),t=[];try{for(let s=0;e&&s<e.length;s++){let i=e.key(s);i&&i.startsWith(Ae)&&t.push(i)}}catch{}for(let s of ke)t.includes(s)||t.push(s);for(let s of t){let i=this.getSync(s);i!==null&&this.memory.set(s,i)}this.persistent=!1;for(let s of t){try{e==null||e.removeItem(s)}catch{}this.cookies&&V(s,this.cookieDomain())}}};var U=class{constructor(e,t,s,i,r){this.store=e;this.key=t;this.cookieDomain=s;this.cookies=i;this.valid=r}get(e=Date.now()){let t=this.store.getSync(this.key);if(t)try{let s=JSON.parse(t);if(s&&typeof s.id=="string"&&s.exp>e)return s.id}catch{}if(this.cookies&&this.store.isPersistent){let s=G(this.key);if(s&&this.valid(s))return s}return null}set(e,t,s=Date.now()){let i={id:e,exp:s+t};this.store.setSync(this.key,JSON.stringify(i)),this.cookies&&this.store.isPersistent&&L(this.key,e,t/1e3,this.cookieDomain())}clear(){this.store.removeSync(this.key),this.cookies&&V(this.key,this.cookieDomain())}persistCookie(e=Date.now()){let t=this.store.getSync(this.key);if(!(!t||!this.cookies||!this.store.isPersistent))try{let s=JSON.parse(t);s.exp>e&&L(this.key,s.id,(s.exp-e)/1e3,this.cookieDomain())}catch{}}};var en="traq_src",tn=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","fbclid","ttclid"],sn=200,nn={utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid",referrer:"referrer"},Re=n=>{let e=n==null?void 0:n.trim();return e?e.slice(0,sn):null},Te=n=>n.toLowerCase().replace(/^www\./,"");function rn(n,e){let t=Te(n),s=Te(e);return t===s||t.endsWith(`.${s}`)||s.endsWith(`.${t}`)}function on(n,e){if(!n)return null;try{let t=new URL(n);return t.protocol!=="http:"&&t.protocol!=="https:"||rn(new URL(e).hostname,t.hostname)?null:Re(Te(t.hostname))}catch{return null}}function an(n,e,t){let s=new URLSearchParams;try{let o=new URL(n).searchParams;for(let a of tn){let l=Re(o.get(a));l&&s.set(a,l)}}catch{return null}let i=s.toString()!=="",r=on(e,n);return r&&s.set("referrer",r),s.toString()===""?null:(s.set("ts",String(t)),{query:s.toString(),fromUrl:i})}function we(n){let e;try{e=new URLSearchParams(n)}catch{return null}let t={};for(let[i,r]of Object.entries(nn)){let o=Re(e.get(i));o&&(t[r]=o)}if(!Object.keys(t).length)return null;let s=Number(e.get("ts"));return Number.isFinite(s)&&s>0&&(t.landedAt=s),t}var ee=class{constructor(e,t,s,i){this.maxAgeMs=t;this.kept=new U(e,en,s,i,r=>we(r)!==null)}capture(e,t,s=Date.now()){let i=an(e,t,s);return!i||!i.fromUrl&&this.kept.get(s)!==null?null:(this.kept.set(i.query,this.maxAgeMs,s),we(i.query))}get(e=Date.now()){let t=this.kept.get(e);return t===null?null:we(t)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var un="traq_click",cn="traq_click",bt=/^[A-Za-z0-9_-]{8,64}$/;function ln(n){try{let e=new URL(n).searchParams.get(un);return e&&bt.test(e)?e:null}catch{return null}}var te=class{constructor(e,t,s,i){this.maxAgeMs=t;this.kept=new U(e,cn,s,i,r=>bt.test(r))}capture(e,t=Date.now()){let s=ln(e);return s&&this.kept.set(s,this.maxAgeMs,t),s}get(e=Date.now()){return this.kept.get(e)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};function It(n,e=Math.random){let t=typeof n=="number"&&Number.isFinite(n)&&n>=0&&n<=1?n:.5;return t<=0?!1:t>=1||e()<t}var dn=1e3,hn=5e3,fn=10,se=class{constructor(){this.clsMax=0;this.clsSeen=!1;this.clsWindow={value:0,first:0,last:0};this.longest=new Map;this.interactions=new Set;this.inpSeen=!1}addLcp(e){Number.isFinite(e)&&e>=0&&(this.lcp=e)}addFcp(e){this.fcp===void 0&&Number.isFinite(e)&&e>=0&&(this.fcp=e)}setTtfb(e){Number.isFinite(e)&&e>=0&&(this.ttfb=e)}addShift(e,t,s){if(this.clsSeen=!0,s||!Number.isFinite(e)||e<0)return;let i=this.clsWindow;i.value>0&&t-i.last<dn&&t-i.first<hn?(i.value+=e,i.last=t):this.clsWindow={value:e,first:t,last:t},this.clsMax=Math.max(this.clsMax,this.clsWindow.value)}clsObserved(){this.clsSeen=!0}addInteraction(e,t){if(!e||!Number.isFinite(t)||t<0)return;this.inpSeen=!0,this.interactions.add(e);let s=this.longest.get(e);if(!(s!==void 0&&s>=t)&&(this.longest.set(e,t),this.longest.size>fn)){let i=0,r=1/0;for(let[o,a]of this.longest)a<r&&(r=a,i=o);this.longest.delete(i)}}inp(){if(!this.inpSeen||!this.longest.size)return;let e=[...this.longest.values()].sort((t,s)=>s-t);return e[Math.min(e.length-1,Math.floor(this.interactions.size/50))]}snapshot(){let e={};this.lcp!==void 0&&(e.lcp=Math.round(this.lcp));let t=this.inp();return t!==void 0&&(e.inp=Math.round(t)),this.clsSeen&&(e.cls=Math.round(this.clsMax*1e4)/1e4),this.fcp!==void 0&&(e.fcp=Math.round(this.fcp)),this.ttfb!==void 0&&(e.ttfb=Math.round(this.ttfb)),Object.keys(e).length?e:null}};function Y(n,e,t={}){var s;try{let i=globalThis.PerformanceObserver;return!i||!((s=i.supportedEntryTypes)!=null&&s.includes(n))?!1:(new i(o=>e(o.getEntries())).observe({type:n,buffered:!0,...t}),!0)}catch{return!1}}function At(n){var s;let e=typeof document=="undefined"||document.visibilityState!=="hidden",t=0;try{let i=performance.getEntriesByType("navigation")[0];i&&(t=Math.max(0,(s=i.activationStart)!=null?s:0),typeof i.responseStart=="number"&&i.responseStart>0&&n.setTtfb(Math.max(0,i.responseStart-t)))}catch{}if(e){let i=!1,r=()=>{i=!0};for(let o of["keydown","click","pointerdown"])window.addEventListener(o,r,{once:!0,capture:!0});Y("largest-contentful-paint",o=>{if(!i)for(let a of o)n.addLcp(Math.max(0,a.startTime-t))}),Y("paint",o=>{for(let a of o)a.name==="first-contentful-paint"&&n.addFcp(Math.max(0,a.startTime-t))})}Y("layout-shift",i=>i.forEach(r=>{var o;return n.addShift((o=r.value)!=null?o:0,r.startTime,!!r.hadRecentInput)}))&&n.clsObserved(),Y("event",i=>i.forEach(r=>{var o;return n.addInteraction((o=r.interactionId)!=null?o:0,r.duration)}),{durationThreshold:40}),Y("first-input",i=>i.forEach(r=>{var o;return n.addInteraction((o=r.interactionId)!=null?o:0,r.duration)}))}var Ne=n=>n.kind==="identify"||n.kind==="group"||n.kind==="alias",gn=/^[a-z][a-z0-9_]{0,29}$/,Nt=5;function Ot(n){if(typeof n!="string")return null;let e=n.trim();return gn.test(e)?e:null}function Mt(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=256?e:null}function Pe(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=Nt)break;let i=Ot(t),r=Mt(s);i&&r&&(e[i]=r)}return e}function Pt(n,e,t){let s=Ot(e),i=Mt(t);return!s||!i||!(s in n)&&Object.keys(n).length>=Nt?null:{groups:{...n,[s]:i},type:s,key:i,changed:n[s]!==i}}var yn=/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/,mn=50,Sn=4096;function w(n){let e={};if(typeof n!="object"||n===null||Array.isArray(n))return e;for(let[t,s]of Object.entries(n)){if(Object.keys(e).length>=mn)break;if(yn.test(t))if(typeof s=="string"){let i=s.trim();i&&(e[t]=i.slice(0,200))}else(typeof s=="number"&&Number.isFinite(s)||typeof s=="boolean")&&(e[t]=s)}return e}function vn(n,e){if(!Object.keys(e).length)return n;let t={...e,...n!=null?n:{}};try{return JSON.stringify(t).length<=Sn?t:n}catch{return n}}var Oe="traq_session";function xt(n){if(typeof n=="number"&&Number.isFinite(n))return String(n);if(typeof n!="string")return null;let e=n.trim();return e&&e.length<=256?e:null}function Et(n){let e=typeof n=="string"?n.trim():typeof n=="number"&&Number.isFinite(n)||typeof n=="boolean"?String(n):"";return e&&e.length<=200?e:null}function Ct(n,e,t){let s=Et(n),i=Et(e);return!s||!i?null:{...t&&typeof t=="object"&&!Array.isArray(t)?t:{},experiment:s,variant:i}}function _n(n,e,t){let s=0,i=e,r=!1;for(let o of n){if(s>=t)break;if(!(o.kind==="identify"||o.kind==="group"||o.kind==="alias")){let l=o.asUser!==void 0?o.asUser||void 0:e;if(!r)i=l,r=!0;else if(l!==i)break}s++}return{events:n.splice(0,s),userId:i}}var bn=1800*1e3,In=5e3,ne=20,W=200,kt=10,wt=/^Object Not Found Matching Id:\d+, MethodName:\w+, ParamCount:\d+$/,An=[25,50,75,100],En=[["utm_source","utmSource"],["utm_medium","utmMedium"],["utm_campaign","utmCampaign"],["utm_content","utmContent"],["utm_term","utmTerm"],["gclid","gclid"],["fbclid","fbclid"],["ttclid","ttclid"]];function Tt(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,12)}`}function kn(n,e){var s;let t={};try{let i=new URL(n);for(let[r,o]of En){let a=(s=i.searchParams.get(r))==null?void 0:s.trim();a&&(t[o]=a.slice(0,200))}if(e){let r=new URL(e);r.hostname.replace(/^www\./,"")!==i.hostname.replace(/^www\./,"")&&(t.referrer=`${r.protocol}//${r.host}/`)}}catch{}return Object.keys(t).length?t:void 0}function q(n){if(n)try{let e=new URL(n,typeof location!="undefined"?location.href:void 0);return e.protocol!=="http:"&&e.protocol!=="https:"?void 0:`${e.origin}${e.pathname}`}catch{return}}var Rt=1e3,wn=30,Dt=3,Me=class{constructor(){this.burst=null}hit(e,t,s){let i=this.burst;return!(i!==null&&s-i.last<=Rt&&Math.hypot(e-i.x,t-i.y)<=wn)||!i.reported&&s-i.first>Rt?(this.burst={x:e,y:t,first:s,last:s,count:1,reported:!1},!1):(i.count++,i.last=s,i.reported||i.count<Dt?!1:(i.reported=!0,!0))}},ie=class{constructor(e){this.deps=e;this.queue=[];this.timer=null;this.lastPath=null;this.maxScroll=0;this.scrollUrl=null;this.errorsThisPage=0;this.stopped=!1;this.scanner=!1;this.rage=new Me;this.vitals=null;this.vitalsUrl=null}start(){var t;let e=this.deps.options;if(this.timer=setInterval(()=>this.flush(!1),In),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.leave()}),window.addEventListener("pagehide",()=>this.leave()),e.pageviews!==!1&&(this.pageview(),this.watchRoutes()),e.clicks!==!1&&document.addEventListener("click",s=>this.onClick(s),!0),e.rageClicks!==!1&&document.addEventListener("click",s=>this.onRageClick(s),!0),e.scroll!==!1&&window.addEventListener("scroll",()=>this.onScroll(),{passive:!0}),e.errors!==!1&&(window.addEventListener("error",s=>this.onError(s)),window.addEventListener("unhandledrejection",s=>this.onRejection(s))),e.webVitals!==!1){let s=typeof e.webVitals=="object"?e.webVitals.sampleRate:.5;It(s)&&(this.vitals=new se,this.vitalsUrl=(t=q(location.href))!=null?t:null,At(this.vitals))}}capture(e,t){typeof e!="string"||!e.trim()||e.startsWith("$")&&e.trim()!=="$exposure"||this.enqueue({kind:"custom",name:e.trim(),props:t})}identify(e,t,s){if(this.stopped||!e)return;let i=Object.keys(t).length>0,r=Object.keys(s).length>0;!i&&!r||(this.queue.push({kind:"identify",ts:Date.now(),userId:e,...i?{set:t}:{},...r?{setOnce:s}:{}}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1))}group(e,t,s,i){if(this.stopped)return;let r=Object.keys(s).length>0,o=Object.keys(i).length>0;this.queue.push({kind:"group",ts:Date.now(),groupType:e,groupKey:t,...r?{set:s}:{},...o?{setOnce:i}:{}}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1)}alias(e,t){this.stopped||(this.queue.push({kind:"alias",ts:Date.now(),userId:e,previousId:t}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1))}reset(e){if(e)for(let t of this.queue)!Ne(t)&&t.asUser===void 0&&(t.asUser=e);try{this.deps.store.removeSync(Oe)}catch{}}pageview(){let e=q(location.href);e&&e!==this.lastPath&&(this.sendScroll(),this.lastPath=e,this.scrollUrl=e,this.maxScroll=0,this.errorsThisPage=0,this.enqueue({kind:"pageview"}),this.onScroll())}flush(e){var a,l;if(!this.queue.length||this.stopped)return;if(this.deps.isForgotten()){this.stop();return}let t=this.deps.anonymousId();if(!t)return;let s=_n(this.queue,this.deps.userId(),100),i=s.userId,r=i?s.events.map(f=>Ne(f)||f.asUser!==void 0?f:{...f,asUser:i}):s.events,o=JSON.stringify({sdkKey:this.deps.sdkKey,anonymousId:t,userId:i,debug:this.deps.isDebug()||void 0,internal:((l=(a=this.deps).isInternal)==null?void 0:l.call(a))||void 0,scanner:this.scanner||void 0,events:r.map(f=>Ne(f)?f:{...f,asUser:void 0})});try{fetch(`${this.deps.endpoint}/ingest/analytics`,{method:"POST",headers:{"content-type":"application/json"},body:o,keepalive:e}).then(f=>{!f.ok&&(f.status>=500||f.status===429)&&this.requeue(r)}).catch(()=>this.requeue(r))}catch{this.requeue(r)}}stop(){this.stopped=!0,this.queue=[],this.timer&&clearInterval(this.timer),this.timer=null}requeue(e){this.stopped||(this.queue=[...e,...this.queue].slice(-W))}session(){let e=Date.now(),t=null;try{let s=this.deps.store.getSync(Oe);t=s?JSON.parse(s):null}catch{t=null}!t||typeof t.id!="string"||typeof t.last!="number"||e-t.last>bn?t={id:Tt(),last:e,src:kn(location.href,document.referrer)}:t.last=e;try{this.deps.store.setSync(Oe,JSON.stringify(t))}catch{}return t}enqueue(e){var a,l,f,T,p,m,S,d;if(this.stopped)return;let t=this.session(),s=typeof document.title=="string"&&document.title?document.title.slice(0,200):void 0,i=e.kind==="scroll"||e.kind==="vitals"?e.props:vn(e.props,(f=(l=(a=this.deps).superProps)==null?void 0:l.call(a))!=null?f:{}),r=(m=(p=(T=this.deps).groups)==null?void 0:p.call(T))!=null?m:{},o=Object.keys(r).length?{...r}:void 0;this.queue.push({...e,...i?{props:i}:{},...o?{groups:o}:{},id:Tt(),ts:Date.now(),url:(d=(S=e.url)!=null?S:q(location.href))!=null?d:"",title:s,sessionId:t.id,...t.src?{src:t.src}:{}}),this.queue.length>W&&this.queue.shift(),this.queue.length>=ne&&this.flush(!1)}leave(){this.sendScroll(),this.sendVitals(),this.flush(!0)}sendVitals(){let e=this.vitals;if(!e||!this.vitalsUrl)return;this.vitals=null;let t=e.snapshot();t&&this.enqueue({kind:"vitals",url:this.vitalsUrl,props:{...t}})}watchRoutes(){if(typeof history=="undefined")return;let e=()=>{setTimeout(()=>this.pageview(),0)};for(let t of["pushState","replaceState"]){let s=history[t];typeof s=="function"&&(history[t]=function(...i){let r=s.apply(this,i);return e(),r})}window.addEventListener("popstate",e)}onScroll(){var o;if(typeof document.documentElement=="undefined"||!document.documentElement)return;let e=document.documentElement,t=window.innerHeight||e.clientHeight||0,s=Math.max(e.scrollHeight||0,((o=document.body)==null?void 0:o.scrollHeight)||0);if(!s)return;let i=s<=t?1:Math.min(1,((window.scrollY||e.scrollTop||0)+t)/s),r=Math.round(i*100);for(let a of An)r>=a&&a>this.maxScroll&&(this.maxScroll=a)}sendScroll(){this.deps.options.scroll===!1||!this.scrollUrl||this.maxScroll<25||(this.enqueue({kind:"scroll",url:this.scrollUrl,props:{depth:this.maxScroll}}),this.scrollUrl=null,this.maxScroll=0)}onClick(e){let t=e.target,s=t&&typeof t.closest=="function"?t.closest("a, button, [role='button'], input[type='submit'], input[type='button']"):null;if(!s||s.closest("[data-traqio-ignore]"))return;let i=s,r=(s.tagName==="INPUT"?i.value:s.innerText||s.textContent||"").replace(/\s+/g," ").trim().slice(0,100),o=s.tagName==="A"?q(s.getAttribute("href")):void 0,a={tag:s.tagName.toLowerCase()};r&&(a.text=r),o&&(a.href=o),s.id&&(a.id=s.id.slice(0,100)),this.enqueue({kind:"click",props:a})}onRageClick(e){var f;let t=typeof e.clientX=="number"?e.clientX:0,s=typeof e.clientY=="number"?e.clientY:0;if(!this.rage.hit(t,s,Date.now()))return;let i=e.target;if(!i||typeof i.closest!="function"||i.closest("[data-traqio-ignore]"))return;let r=(f=i.closest("a, button, [role='button'], input[type='submit'], input[type='button']"))!=null?f:i,o=(r.tagName==="INPUT"?r.value:r.innerText||r.textContent||"").replace(/\s+/g," ").trim().slice(0,100),a={tag:r.tagName.toLowerCase(),count:Dt};o&&(a.text=o);let l=r.tagName==="A"?q(r.getAttribute("href")):void 0;l&&(a.href=l),r.id&&(a.id=r.id.slice(0,100)),this.enqueue({kind:"rageclick",props:a})}onError(e){if(this.errorsThisPage>=kt)return;let t=(e.message||(e.error instanceof Error?e.error.message:"")||"Script error").slice(0,300);wt.test(t.replace(/^Uncaught (?:Error: )?/,""))&&(this.scanner=!0),this.errorsThisPage++;let s=e.error instanceof Error&&typeof e.error.stack=="string"?e.error.stack.slice(0,1500):void 0;this.enqueue({kind:"error",props:{message:t,...s?{stack:s}:{},...e.filename?{source:q(e.filename)}:{},...e.lineno?{line:e.lineno}:{}}})}onRejection(e){if(this.errorsThisPage>=kt)return;let t=e.reason,s=(t instanceof Error?t.message:typeof t=="string"?t:"Unhandled promise rejection").slice(0,300);wt.test(s)&&(this.scanner=!0),this.errorsThisPage++;let i=t instanceof Error&&typeof t.stack=="string"?t.stack.slice(0,1500):void 0;this.enqueue({kind:"error",props:{message:s,unhandledRejection:!0,...i?{stack:i}:{}}})}};var Tn="https://api.traqio.app",X="traq_super",Q="traq_groups",Rn=30,Nn=1440*60*1e3;function On(){return typeof window!="undefined"&&typeof document!="undefined"}function Mn(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}function Pn(n){try{let e=new URL(n).searchParams.get("traqio_internal");if(e==="1"||e==="true")return!0;if(e==="0"||e==="false")return!1}catch{}return null}var xe=class{constructor(){this.core=new Lt.Client;this.store=null;this.trackIds=null;this.sources=null;this.waitForConsent=!1;this.started=!1;this.analytics=null;this.earlyCaptures=[];this.ready=!1;this.superProps={};this.earlyIdentifies=[];this.groups={};this.earlyGroups=[];this.earlyAliases=[];this.resetBeforeInit=!1}async init(e){var T,p,m,S;if(this.started||!On())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,s,i=()=>s===void 0?s=_t(location.hostname):s,r=(T=e.consent)!=null?T:this.earlyConsent,o=!this.waitForConsent||r===!0;this.store=new Z(o,i,t);let a=((p=e.trackIdDays)!=null?p:Rn)*Nn;this.trackIds=new te(this.store,a,i,t),this.trackIds.capture(location.href),this.sources=new ee(this.store,a,i,t),this.sources.capture(location.href,document.referrer);let l=Pn(location.href);if(l!==null&&this.setInternal(l),!this.store.getSync(F)){let d=Mn();d&&this.store.setSync(F,d)}this.userId=(m=e.userId)!=null?m:this.userId,this.resetBeforeInit&&(this.store.removeSync(X),this.store.removeSync(Q));try{let d=this.store.getSync(X),y=Object.keys(this.superProps).length>0;d&&(this.superProps=w({...w(JSON.parse(d)),...this.superProps})),y&&this.store.setSync(X,JSON.stringify(this.superProps))}catch{}try{let d=this.store.getSync(Q),y=Object.keys(this.groups).length>0;d&&(this.groups=Pe({...Pe(JSON.parse(d)),...this.groups})),y&&this.store.setSync(Q,JSON.stringify(this.groups))}catch{}let f=((S=e.endpoint)!=null?S:Tn).replace(/\/+$/,"");if(await this.core.init({sdkKey:e.sdkKey,endpoint:f,storage:this.store,platform:"web",userId:this.userId,consent:r,debug:e.debug,onError:e.onError,lifecycle:({background:d,foreground:y})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?d():y()),window.addEventListener("pagehide",d)}}),e.analytics){let d=this.store;this.analytics=new ie({store:d,endpoint:f,sdkKey:e.sdkKey,anonymousId:()=>d.getSync(F),userId:()=>this.userId,superProps:()=>this.superProps,groups:()=>this.groups,isDebug:()=>this.core.isDebug,isForgotten:()=>this.core.forgotten,isInternal:()=>this.isInternal,options:e.analytics===!0?{}:e.analytics}),this.analytics.start();for(let[y,_,re]of this.earlyIdentifies)this.analytics.identify(y,_,re);for(let[y,_,re,qt]of this.earlyGroups)this.analytics.group(y,_,re,qt);for(let[y,_]of this.earlyAliases)this.analytics.alias(y,_);for(let[y,_]of this.earlyCaptures)this.analytics.capture(y,_)}this.earlyCaptures=[],this.earlyIdentifies=[],this.earlyGroups=[],this.earlyAliases=[],this.ready=!0}setInternal(e){if(this.store)try{e?this.store.setSync(j,"1"):this.store.removeSync(j)}catch{}}get isInternal(){var e;try{return((e=this.store)==null?void 0:e.getSync(j))==="1"}catch{return!1}}get isDebug(){return this.core.isDebug}track(e,t){this.core.track(e,t)}capture(e,t){this.analytics?this.analytics.capture(e,t):!this.ready&&this.earlyCaptures.length<50&&this.earlyCaptures.push([e,t])}pageview(){var e;(e=this.analytics)==null||e.pageview()}setUserId(e){this.userId=e,this.core.setUserId(e)}identify(e,t,s){let i=typeof e=="string"?e.trim():"";if(!i)return;this.setUserId(i);let r=w(t),o=w(s);!Object.keys(r).length&&!Object.keys(o).length||(this.analytics?this.analytics.identify(i,r,o):!this.ready&&this.earlyIdentifies.length<10&&this.earlyIdentifies.push([i,r,o]))}register(e){this.superProps=w({...this.superProps,...w(e)}),this.persistSuperProps()}unregister(e){if(typeof e!="string"||!(e in this.superProps))return;let t={...this.superProps};delete t[e],this.superProps=t,this.persistSuperProps()}getSuperProperties(){return{...this.superProps}}group(e,t,s,i){let r=Pt(this.groups,e,t);if(!r)return;this.groups=r.groups,this.persistGroups();let o=w(s),a=w(i);!r.changed&&!Object.keys(o).length&&!Object.keys(a).length||(this.analytics?this.analytics.group(r.type,r.key,o,a):!this.ready&&this.earlyGroups.length<10&&this.earlyGroups.push([r.type,r.key,o,a]))}resetGroups(){this.groups={},this.persistGroups()}getGroups(){return{...this.groups}}alias(e){let t=xt(e),s=this.userId;!s||!t||t===s||(this.analytics?this.analytics.alias(s,t):!this.ready&&this.earlyAliases.length<10&&this.earlyAliases.push([s,t]))}reset(){var t;let e=this.userId;(t=this.analytics)==null||t.reset(e),this.userId=void 0,this.core.reset(),this.superProps={},this.groups={},this.earlyIdentifies=[],this.earlyGroups=[],this.earlyAliases=[],this.store?(this.persistSuperProps(),this.persistGroups()):this.resetBeforeInit=!0}exposure(e,t,s){let i=Ct(e,t,s);if(!i)return;let r=!1;try{r=JSON.stringify(i).length<=4096}catch{r=!1}this.capture("$exposure",r?i:{experiment:i.experiment,variant:i.variant})}persistGroups(){try{if(!this.store)return;Object.keys(this.groups).length?this.store.setSync(Q,JSON.stringify(this.groups)):this.store.removeSync(Q)}catch{}}persistSuperProps(){try{if(!this.store)return;Object.keys(this.superProps).length?this.store.setSync(X,JSON.stringify(this.superProps)):this.store.removeSync(X)}catch{}}async setConsent(e){var t,s;this.started||(this.earlyConsent=e),this.store&&this.waitForConsent&&(e?(this.store.enable(),(t=this.trackIds)==null||t.persistCookie(),(s=this.sources)==null||s.persistCookie()):this.store.disable()),await this.core.setConsent(e)}getTrackId(){var e,t;return(t=(e=this.trackIds)==null?void 0:e.get())!=null?t:null}getSource(){var e,t;return(t=(e=this.sources)==null?void 0:e.get())!=null?t:null}async forgetMe(){var t,s,i;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear(),(s=this.sources)==null||s.clear(),(i=this.analytics)==null||i.stop(),this.superProps={},this.persistSuperProps(),this.groups={},this.persistGroups()),e}flush(){var e;this.core.flush(),(e=this.analytics)==null||e.flush(!1)}get forgotten(){return this.core.forgotten}},Ce=new xe;window.Traqio=Ce;var A=document.currentScript,Ut=A==null?void 0:A.dataset.sdkKey;Ut&&Ce.init({sdkKey:Ut,endpoint:(A==null?void 0:A.dataset.endpoint)||void 0,waitForConsent:(A==null?void 0:A.dataset.waitForConsent)==="true",analytics:(A==null?void 0:A.dataset.analytics)==="true"});})();
2
2
  //# sourceMappingURL=traqio.min.js.map