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