@traqio/web 0.3.1 → 0.4.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 B=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty;var ze=(r,e,t)=>()=>{if(t)throw t[0];try{return r&&(e=r(r=0)),e}catch(n){throw t=[n],n}};var D=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var le=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Xe(e))!Je.call(r,i)&&i!==t&&B(r,i,{get:()=>e[i],enumerable:!(n=Qe(e,i))||n.enumerable});return r};var Ze=(r,e,t)=>(t=r!=null?je(He(r)):{},le(e||!r||!r.__esModule?B(t,"default",{value:r,enumerable:!0}):t,r)),O=r=>le(B({},"__esModule",{value:!0}),r);var j=D(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});l.Skan=l.SKAN_STATE_KEY=l.CONVERSION_WINDOWS=void 0;l.windowForAge=fe;l.shouldLockWindow=pe;l.fineValueForRevenue=me;l.fineValueForEvents=ge;l.coarseValueForRevenue=ve;l.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function fe(r){let e=l.CONVERSION_WINDOWS.find(t=>r>=t.startHours&&r<t.endHours);return e?e.window:null}function pe(r,e){let t=fe(e);if(t==null||!r||!r.length)return!1;let n=r.find(i=>i.window===t);return!n||!n.lock?!1:n.lockAfterHours==null?!0:e>=n.lockAfterHours}var et=63,tt=6;function me(r,e){let t=0;for(let n=0;n<Math.min(e.length,et+1);n++)r>=e[n]&&(t=n);return t}function ge(r,e){let t=new Set(r),n=0;return e.slice(0,tt).forEach((i,s)=>{t.has(i)&&(n|=1<<s)}),n}function ve(r,e){if(!e)return;let t,n=-1/0;for(let i of["low","medium","high"]){let s=e[i];s!=null&&r>=s&&s>=n&&(t=i,n=s)}return t}var he={revenue:0,events:[],lastFine:null};l.SKAN_STATE_KEY="traq_skan_state";var $=class{constructor(){this.mapping=null,this.state={...he},this.enabled=!1}async init(e){this.opts=e,this.enabled=!!e.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(e){!this.enabled||!(e>0)||!Number.isFinite(e)||(this.state.revenue+=e,this.persist(),this.push())}markEvent(e){!this.enabled||this.state.events.includes(e)||(this.state.events.push(e),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var i,s;let e=this.mapping;if(!e||!this.opts.native)return;let t,n;if(e.mode==="events"){if(!((i=e.eventBits)!=null&&i.length))return;t=ge(this.state.events,e.eventBits)}else{if(!((s=e.revenueBuckets)!=null&&s.length))return;t=me(this.state.revenue,e.revenueBuckets),n=ve(this.state.revenue,e.coarseRevenue)}this.state.lastFine==null&&t===0||this.state.lastFine!=null&&t<=this.state.lastFine||(this.state.lastFine=t,this.persist(),this.opts.native.updateConversionValue(t,n,this.lockWindowNow()))}lockWindowNow(){var n;let e=this.state.firstSeenAt;if(e==null)return!1;let t=(this.now()-e)/36e5;return pe((n=this.mapping)==null?void 0:n.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 n=await e(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!n.ok)return null;let i=await n.json();return i&&typeof i=="object"?i:null}catch{return null}}async restore(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(l.SKAN_STATE_KEY));t&&(this.state={...he,...JSON.parse(t)})}catch{}}async persist(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(l.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};l.Skan=$});var X=D(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.ADSERVICES_ATTEMPTS_KEY=p.ADSERVICES_SENT_KEY=void 0;p.reportAdServicesToken=rt;p.ADSERVICES_SENT_KEY="traq_adservices_sent";p.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var nt=5;async function rt(r){var n,i;if(!((n=r.native)!=null&&n.getAttributionToken))return"unsupported";if(await ye(r,p.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await r.native.getAttributionToken()}catch{}if(!e||!e.trim()){let s=Number(await ye(r,p.ADSERVICES_ATTEMPTS_KEY))||0;return await Q(r,p.ADSERVICES_ATTEMPTS_KEY,String(s+1)),s+1>=nt&&await Q(r,p.ADSERVICES_SENT_KEY,"1"),"no-token"}let t=(i=r.fetchFn)!=null?i:typeof fetch=="function"?fetch:void 0;if(!t)return"post-failed";try{if(!(await t(`${r.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:r.sdkKey,token:e.trim(),deviceId:r.deviceId,appUserId:r.userId,...r.debug?{debug:!0}:{}})})).ok)return"post-failed"}catch{return"post-failed"}return await Q(r,p.ADSERVICES_SENT_KEY,"1"),"sent"}async function ye(r,e){var t,n;try{return(n=await((t=r.storage)==null?void 0:t.getItem(e)))!=null?n:null}catch{return null}}async function Q(r,e,t){var n;try{await((n=r.storage)==null?void 0:n.setItem(e,t))}catch{}}});var H=D(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.isTrackingUrl=st;k.isOpenUrl=ot;k.toDeepLink=Se;k.upgradeStoredDeepLink=at;var it=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/,_e=/^\/o\/[0-9a-fA-F-]{36}\/?$/;function Ae(r){var t;let e=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(r);return e?(t=e[1])!=null?t:"":null}function st(r){let e=Ae(r);return e!==null&&(it.test(e)||_e.test(e))}function ot(r){let e=Ae(r);return e!==null&&_e.test(e)}function Se(r,e,t){var s,a,u;if(!(r!=null&&r.matched)||!r.via)return null;let n=(s=r.matchType)!=null?s:r.via==="ip_match"?"probabilistic":r.via,i=(a=r.payload)!=null?a:{deepLink:r.deepLink,value:null,params:{}};return{payload:i,matchType:n,confidence:n==="probabilistic"?(u=r.confidence)!=null?u:"low":null,deferred:e,code:r.code,deepLink:i.deepLink,via:r.via,...t?{url:t}:{}}}function at(r){var t,n,i;if(!r||typeof r!="object")return null;let e=r;return e.payload&&e.matchType?e:e.via?Se({matched:!0,via:e.via,code:(t=e.code)!=null?t:null,deepLink:(n=e.deepLink)!=null?n:null},(i=e.deferred)!=null?i:!0,e.url):null}});var C={};var w=ze(()=>{"use strict"});var Z=D(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.CAPACITOR_ADMOB_PAID_EVENTS=d.MAX_RN_MIN_VERSION=d.MAX_RN_REVENUE_EVENTS=d.GMA_MIN_VERSION=d.GMA_FULLSCREEN_CHANNELS=d.AdRevenueGate=void 0;d.fromGoogleMobileAdsPaid=z;d.fromGoogleMobileAdsChannel=ke;d.fromGoogleMobileAdsNativeAd=we;d.fromMaxAdInfo=Ne;d.fromCapacitorAdMob=dt;d.watchReactNativeAds=ht;function ut(r){return Array.isArray(r)?r.length>0:r===!0}var J=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 ut(this.coverage[e])}capturesFormat(e,t){let n=this.coverage[e];return n===!0?!0:Array.isArray(n)&&t!==void 0&&n.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,n,i){return this.capturesFormat(e,t)?(this.warnOnce(`helper:${e}:${t}`,`[traqio] adRevenue.${e} already captures ${t} ads: ${i} ignored for them, keep it on the formats it is documented for.`),!1):this.first(n)}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{}}}};d.AdRevenueGate=J;var ct=["unknown","estimated","publisher_provided","precise"];function be(r){var e;return typeof r=="number"&&(e=ct[r])!=null?e:"unknown"}function y(r){return typeof r=="string"&&r.trim()?r:void 0}function _(r){return r&&typeof r=="object"?r:void 0}function Ie(r){let e=typeof r=="string"&&/^\d+$/.test(r.trim())?Number(r):r;return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}d.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"};d.GMA_MIN_VERSION="12.4.0";function z(r,e={}){var a;let t=_(r);if(!t)return;let n=y(t.currency);if(!n)return;let i=Ie(t.valueMicros);if(i===void 0){if(!(typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=0))return;i=Math.round(t.value*1e6)}let s=_((a=_(t.responseInfo))==null?void 0:a.loadedAdapterResponse);return{valueMicros:i,currency:n,precision:be(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:y(s==null?void 0:s.adSourceName)}}function ke(r,e){let t=_(e),n=_(t==null?void 0:t.body);if(!(!t||(n==null?void 0:n.type)!=="paid"))return z(n.data,{adUnitId:y(t.adUnitId),adFormat:d.GMA_FULLSCREEN_CHANNELS[r]})}function we(r){let e=_(r);if((e==null?void 0:e.type)==="paid")return z(e,{adFormat:"native"})}d.MAX_RN_REVENUE_EVENTS=["OnBannerAdRevenuePaid","OnMRecAdRevenuePaid","OnInterstitialAdRevenuePaid","OnRewardedAdRevenuePaid","OnAppOpenAdRevenuePaid"];d.MAX_RN_MIN_VERSION="5.0.0";function Ne(r){let e=_(r);if(!(!e||typeof e.revenue!="number"))return{revenue:e.revenue,revenuePrecision:y(e.revenuePrecision),adUnitId:y(e.adUnitId),format:y(e.adFormat),networkName:y(e.networkName)}}d.CAPACITOR_ADMOB_PAID_EVENTS={bannerAdPaid:"banner",nativeAdPaid:"native",interstitialAdImpression:"interstitial",onRewardedVideoAdImpression:"rewarded",onRewardedInterstitialAdImpression:"rewarded_interstitial",appOpenAdImpression:"app_open"};function dt(r,e){let t=_(r),n=Ie(t==null?void 0:t.valueMicros),i=y(t==null?void 0:t.currencyCode);if(!(!t||n===void 0||!i))return{valueMicros:n,currency:i,precision:be(t.precision),adUnitId:y(t.adUnitId),adFormat:e,adSourceName:y(t.networkName)}}function Ee(r,e){var t,n,i,s,a;try{return(s=(n=(t=r.TurboModuleRegistry)==null?void 0:t.get)==null?void 0:n.call(t,e))!=null?s:(i=r.NativeModules)==null?void 0:i[e]}catch{return(a=r.NativeModules)==null?void 0:a[e]}}var lt=["interstitial","rewarded","rewarded_interstitial","app_open"];function ht(r,e,t){var u,h,M,T;if(!t)try{t=(w(),O(C))}catch{return{coverage:{},stop:()=>{}}}let n=[],i={},s=(c,f,g=v=>v)=>v=>{try{let S=c(v);S&&f(S,g(v))}catch{}},a=c=>{var f,g;return(g=_((f=_(c))==null?void 0:f.body))==null?void 0:g.data};if(r.admob){i.admob=[];for(let[g,v]of Object.entries(d.GMA_FULLSCREEN_CHANNELS)){let S=(u=t.DeviceEventEmitter)==null?void 0:u.addListener(g,s(b=>ke(g,b),e.admob,a));S&&(n.push(S),i.admob.push(v))}let c=Ee(t,"RNGoogleMobileAdsNativeModule"),f=s(we,e.admob);try{if(c&&typeof c.onAdEvent=="function")n.push(c.onAdEvent(f)),i.admob.push("native");else if(c&&t.NativeEventEmitter){let g=new t.NativeEventEmitter(((h=t.Platform)==null?void 0:h.OS)==="ios"?c:void 0);n.push(g.addListener("RNGMANativeAdEvent",f)),i.admob.push("native")}}catch{}}if(r.applovinMax){let c=Ee(t,"AppLovinMAX");if(c&&t.NativeEventEmitter)try{let f=[...d.MAX_RN_REVENUE_EVENTS];try{let v=(T=(M=c.getConstants)==null?void 0:M.call(c))!=null?T:{},S=Object.keys(v).filter(b=>/^ON_.*_AD_REVENUE_PAID$/.test(b)).map(b=>v[b]).filter(b=>typeof b=="string");S.length&&(f=[...new Set([...S,...f])])}catch{}let g=new t.NativeEventEmitter(c);for(let v of f)n.push(g.addListener(v,s(Ne,e.applovinMax)));i.applovinMax=[...lt]}catch{}}return{coverage:i,stop:()=>{for(let c of n.splice(0))try{c.remove()}catch{}}}}});var Ge=D(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.Traqio=o.Client=o.AdRevenueGate=o.watchReactNativeAds=o.fromMaxAdInfo=o.fromGoogleMobileAdsPaid=o.fromGoogleMobileAdsNativeAd=o.fromGoogleMobileAdsChannel=o.fromCapacitorAdMob=o.MAX_RN_REVENUE_EVENTS=o.MAX_RN_MIN_VERSION=o.GMA_MIN_VERSION=o.GMA_FULLSCREEN_CHANNELS=o.CAPACITOR_ADMOB_PAID_EVENTS=o.isTrackingUrl=o.isOpenUrl=o.reportAdServicesToken=o.Skan=o.SDK_VERSION=void 0;o.normalizeAdvertisingId=Ve;o.fromMaxAd=q;o.detectDebug=Fe;o.isLocalPage=Ke;var ft=j(),pt=X(),E=H(),U=Z();o.SDK_VERSION="0.5.1";var mt=j();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return mt.Skan}});var gt=X();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return gt.reportAdServicesToken}});var qe=H();Object.defineProperty(o,"isOpenUrl",{enumerable:!0,get:function(){return qe.isOpenUrl}});Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return qe.isTrackingUrl}});var m=Z();Object.defineProperty(o,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return m.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(o,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return m.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(o,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return m.GMA_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return m.MAX_RN_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return m.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(o,"fromCapacitorAdMob",{enumerable:!0,get:function(){return m.fromCapacitorAdMob}});Object.defineProperty(o,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return m.fromGoogleMobileAdsChannel}});Object.defineProperty(o,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return m.fromGoogleMobileAdsNativeAd}});Object.defineProperty(o,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return m.fromGoogleMobileAdsPaid}});Object.defineProperty(o,"fromMaxAdInfo",{enumerable:!0,get:function(){return m.fromMaxAdInfo}});Object.defineProperty(o,"watchReactNativeAds",{enumerable:!0,get:function(){return m.watchReactNativeAds}});Object.defineProperty(o,"AdRevenueGate",{enumerable:!0,get:function(){return m.AdRevenueGate}});var vt="traq_install_sent",yt="traq_install_sent_debug",Re="traq_install_attempts",Me="traq_referrer",Te="traq_queue",De="traq_ad_queue",Oe="traq_device_id",Ce="traq_last_session",xe="traq_erased",I="traq_deferred_link",ee="traq_deferred_consent_retry_until",_t=60*6e4,Le="traq_consent",At=20,St=new Set([400,413,422]),Pe=500,Et=100,Ue=1e3,te=1e3,bt=300*1e3,It=3e3,kt=3,wt=1800*1e3,Nt=["not_determined","restricted","denied","authorized"],Rt={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},Mt={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"},Tt="00000000-0000-0000-0000-000000000000";function Ve(r){if(typeof r!="string")return;let e=r.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===Tt?void 0:e}function q(r){var e,t,n;if(typeof r.revenue=="number"&&Number.isFinite(r.revenue)&&r.revenue>=0)return{valueMicros:Math.round(r.revenue*1e6),currency:"USD",precision:(t=Rt[(e=r.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:r.adUnitId,adFormat:Mt[((n=r.format)!=null?n:"").toUpperCase()],adSourceName:r.networkName,ts:r.ts}}function x(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})}function Dt(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Ot(){var r;try{let e=(w(),O(C)),t=(r=e==null?void 0:e.default)!=null?r:e;if(typeof(t==null?void 0:t.getItem)=="function"&&typeof(t==null?void 0:t.setItem)=="function")return{getItem:n=>t.getItem(n),setItem:(n,i)=>t.setItem(n,i)}}catch{}}function Ct(){var r,e;try{let t=(e=(r=(w(),O(C)))==null?void 0:r.Platform)==null?void 0:e.OS;return t==="ios"||t==="android"?t:void 0}catch{return}}var V=class{constructor(){this.queue=[],this.adQueue=[],this.adGate=new U.AdRevenueGate,this.adBatchId=null,this.context={sdkVersion:o.SDK_VERSION},this.referrer=null,this.started=!1,this.flushing=!1,this.flushTimer=null,this.retryMs=te,this.skan=new ft.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null,this.att=null,this.debug=!1,this.maxRevenuePaid=e=>{try{let t=(0,U.fromMaxAdInfo)(e),n=t&&q(t);n&&this.adGate.helper("applovinMax",n.adFormat,e,"Traqio.maxRevenuePaid")&&this.queueAdRevenue(n,"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:Ot()},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 Fe(e),await this.restoreConsent(e.consent),await this.restoreQueue(),await this.restoreAdQueue(),await this.buildContext(),!await this.restoreErased())){if(!this.isWeb){let n=!!this.opts.storage&&!await this.opts.storage.getItem(this.installSentKey).catch(()=>"1");await this.sendInstallOnce(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(n).then(i=>i!=null?i: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 n,i;let e=this.opts.adRevenue;if(!e||this.isWeb||!(e.admob||e.applovinMax))return;let t={admob:(s,a)=>{this.adGate.first(a)&&this.queueAdRevenue(s,"admob","auto")},applovinMax:(s,a)=>{let u=q(s);u&&this.adGate.first(a)&&this.queueAdRevenue(u,"applovin_max","auto")}};try{let s=(n=this.opts.native)!=null&&n.watchAdRevenue?(i=this.opts.native.watchAdRevenue(e,t))!=null?i:e:(0,U.watchReactNativeAds)(e,t).coverage;this.adGate.arm(s)}catch{}}track(e,t){var i,s;if(!this.started||this.erased)return;let n=((i=t==null?void 0:t.transactionId)==null?void 0:i.trim())||void 0;this.enqueue({name:e,eventId:x(),value:t==null?void 0:t.value,currency:t==null?void 0:t.currency,...n?{transactionId:n,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:Ct()}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=q(e);t&&this.queueAdRevenue(t,"applovin_max","manual")}admobPaid(e,t="banner"){return n=>{try{let i=(0,U.fromGoogleMobileAdsPaid)(n,{adUnitId:e,adFormat:t});i&&this.adGate.helper("admob",t,n,"Traqio.admobPaid()")&&this.queueAdRevenue(i,"admob","auto")}catch{}}}queueAdRevenue(e,t,n){var i;!this.started||this.erased||!(e.valueMicros>=0)||!e.currency||(this.adQueue.push({...e,source:t,origin:n,impressionId:x(),ts:(i=e.ts)!=null?i:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>Ue&&this.adQueue.splice(0,this.adQueue.length-Ue),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 n of t)e(n);return()=>{this.deepLinkListeners.delete(e)}}async handleUrl(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,E.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),n=(0,E.isOpenUrl)(e),i=(0,E.toDeepLink)(t,n,e);return i&&n&&await this.keepDeferred(i),i&&this.emitDeepLink(i),i}getDeferredDeepLink(){var e;return(e=this.deferred)!=null?e:Promise.resolve(null)}async redeemDeepLinkCode(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!e.trim())return null;let t=await this.postJson({code:e},"/deeplink/code"),n=(0,E.toDeepLink)(t,!0);return n?(await this.keepDeferred(n),this.emitDeepLink(n),n):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,n;this.consent=e?"granted":"denied",await((n=(t=this.opts)==null?void 0:t.storage)==null?void 0:n.setItem(Le,this.consent).catch(()=>{})),e&&this.deferred&&!this.erased&&(this.deferred=this.deferred.then(i=>i!=null?i: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()}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,pt.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,n,i)=>{var s;return(s=e.updateConversionValue)==null?void 0:s.call(e,t,n,i)}}})}async resolveDeferredOnce(e){let t=this.opts.storage;try{let h=await(t==null?void 0:t.getItem(I));if(h)return(0,E.upgradeStoredDeepLink)(JSON.parse(h))}catch{}if(!e&&!await(t==null?void 0:t.getItem(`${I}_pending`).catch(()=>null)))return null;let n=this.hostPlatform,i=n==="android"?await this.readReferrer():null;await(t==null?void 0:t.setItem(`${I}_pending`,"1").catch(()=>{}));let s=await this.askDeferred(n,i==null?void 0:i.referrer);if(!s)return null;let a=(0,E.toDeepLink)(s,!0),u=await this.storedDeferred();if(u)return u;try{await(t==null?void 0:t.setItem(I,JSON.stringify(a))),!a&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(ee,String(Date.now()+_t)))}catch{}return a&&this.emitDeepLink(a),a}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,a;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(ee).catch(()=>null));if(!t||(await e.setItem(ee,"").catch(()=>{}),Date.now()>t))return null;let n=await this.storedDeferred();if(n)return n;let i=(0,E.toDeepLink)(await this.askDeferred(this.hostPlatform,void 0),!0);return i?(await((a=this.opts.storage)==null?void 0:a.setItem(I,JSON.stringify(i)).catch(()=>{})),this.emitDeepLink(i),i):null}async storedDeferred(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(I));return t?(0,E.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(I,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?yt:vt}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",n=>{if(n!=="active"){this.scheduleFlush(0);return}this.maybeStartSession()})}catch{}}async restoreErased(){var e;try{this.erased=await((e=this.opts.storage)==null?void 0:e.getItem(xe))==="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(xe,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>Pe&&this.queue.splice(0,this.queue.length-Pe),this.persistQueue(),this.scheduleFlush()}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(Te));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(Te,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,n;try{let i=await((e=this.opts.storage)==null?void 0:e.getItem(De));if(!i)return;let s=JSON.parse(i);this.adQueue=(t=s.items)!=null?t:[],this.adBatchId=(n=s.batchId)!=null?n: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(De,JSON.stringify(t)))}catch{}}async maybeStartSession(e=!1){var s,a,u;if(this.erased)return;let t=Date.now();if(!e){let h=Number(await((s=this.opts.storage)==null?void 0:s.getItem(Ce).catch(()=>null)))||0;if(h&&t-h<wt)return}let n=(a=this.context.deviceId)!=null?a:await this.getOrCreateDeviceId();if(await this.post({deviceId:n,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(Ce,String(t)))}catch{}}async buildContext(){var t,n,i;if(!this.opts.collectContext){this.context={sdkVersion:o.SDK_VERSION};return}let e={};try{e=(i=await((n=(t=this.opts.native)==null?void 0:t.getContext)==null?void 0:n.call(t)))!=null?i:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:e.deviceModel,osVersion:e.osVersion,appVersion:this.opts.appVersion,locale:Dt(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var t,n;try{let i=await((t=this.opts.storage)==null?void 0:t.getItem(Oe));if(i)return i}catch{}let e=x();try{await((n=this.opts.storage)==null?void 0:n.setItem(Oe,e))}catch{}return e}async readReferrer(){var n,i;if(this.referrer)return this.referrer;try{let s=await((n=this.opts.storage)==null?void 0:n.getItem(Me));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((i=this.opts.storage)==null?void 0:i.setItem(Me,JSON.stringify(t)))}catch{}}return t}async readAdvertisingId(){var e;if(!(!this.opts.collectAdvertisingId||!((e=this.opts.native)!=null&&e.getAdvertisingId)))try{return Ve(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 n=await this.readReferrer();if(n.retryable&&e){let s=Number(await e.getItem(Re))||0;if(s+1<kt){await e.setItem(Re,String(s+1));return}}await this.post({install:{platform:t,installReferrer:n.referrer,appUserId:this.opts.userId,advertisingId:await this.readAdvertisingId(),context:this.context}})&&await(e==null?void 0:e.setItem(this.installSentKey,"1"))}scheduleFlush(e=It){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,At),n=await this.send({events:t,appUserId:this.opts.userId,deviceId:this.context.deviceId});if(n==="retry")return this.backOff();n==="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=te}for(;this.adQueue.length;){let t=(e=this.adQueue[0].source)!=null?e:"admob",n=this.adQueue.findIndex(a=>{var u;return((u=a.source)!=null?u:"admob")!==t}),i=this.adQueue.slice(0,Math.min(Et,n===-1?this.adQueue.length:n));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:i.map(({source:a,...u})=>u)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,i.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=te}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,bt),this.scheduleFlush(this.retryMs)}async postJson(e,t){try{let n=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 n.ok?await n.json():null}catch{return null}}async restoreConsent(e){var n;if(e!==void 0)return this.setConsent(e);if(this.consent)return this.setConsent(this.consent==="granted");let t=await((n=this.opts.storage)==null?void 0:n.getItem(Le).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 n=await((t=(e=this.opts.native)==null?void 0:e.getTrackingAuthorization)==null?void 0:t.call(e));Nt.includes(n)&&(this.att=n!=null?n:null)}catch{}return this.att}async post(e,t="/ingest"){return await this.send(e,t)==="ok"}async send(e,t="/ingest"){let n=this.consent&&(t==="/ingest"||t==="/ingest/session")?{consent:this.consent}:{},i=t==="/ingest"&&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,...n,...i?{att:i}:{},...this.debugField()}),...this.keepalive()});return s.ok?"ok":St.has(s.status)?"refused":"retry"}catch{return"retry"}}};o.Client=V;async function Fe(r){var e,t;if(r.debug!==void 0)return r.debug;if(r.platform==="web")return Ke();if(globalThis.__DEV__===!0)return!0;try{return await((t=(e=r.native)==null?void 0:e.isDebugBuild)==null?void 0:t.call(e))===!0}catch{return!1}}function Ke(r=globalThis.location){if(!r)return!1;if(r.protocol==="file:")return!0;let e=r.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)}o.Traqio=new V});var Be=Ze(Ge(),1);var re="traq_";function ie(){return typeof document=="undefined"?void 0:document}function L(r){let e=ie();if(!e)return null;for(let t of e.cookie?e.cookie.split(";"):[]){let n=t.indexOf("=");if(!(n<0)&&t.slice(0,n).trim()===r)try{return decodeURIComponent(t.slice(n+1).trim())}catch{return null}}return null}function ne(r,e,t,n){let i=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",s=n?`; Domain=${n}`:"";return`${r}=${encodeURIComponent(e)}; Max-Age=${Math.floor(t)}; Path=/${s}; SameSite=Lax${i}`}function We(r){let e=ie();if(!e||!r.includes(".")||/^[\d.]+$/.test(r)||r.includes(":"))return null;let t=r.split("."),n=`${re}probe`;for(let i=t.length-2;i>=0;i--){let s=t.slice(i).join(".");if(e.cookie=ne(n,"1",10,s),L(n)==="1")return e.cookie=ne(n,"",0,s),s}return null}function N(r,e,t,n){let i=ie();if(i)try{i.cookie=ne(r,e,t,n)}catch{}}function P(r,e){N(r,"",0,e)}var G="traq_device_id",se=new Set([G]),xt=395*24*60*60;function F(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var K=class{constructor(e,t,n){this.persistent=e;this.cookieDomain=t;this.cookies=n;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 n,i,s;if(this.memory.has(e))return(n=this.memory.get(e))!=null?n:null;if(!this.persistent)return null;let t=null;try{t=(s=(i=F())==null?void 0:i.getItem(e))!=null?s:null}catch{}return t===null&&this.cookies&&se.has(e)&&(t=L(e)),t}setSync(e,t){if(!this.persistent){this.memory.set(e,t);return}let n=!1;try{let i=F();i&&(i.setItem(e,t),n=!0)}catch{}n||this.memory.set(e,t),this.cookies&&se.has(e)&&N(e,t,xt,this.cookieDomain())}removeSync(e){var t;this.memory.delete(e);try{(t=F())==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,n]of e)this.setSync(t,n)}disable(){if(!this.persistent)return;let e=F(),t=[];try{for(let n=0;e&&n<e.length;n++){let i=e.key(n);i&&i.startsWith(re)&&t.push(i)}}catch{}for(let n of se)t.includes(n)||t.push(n);for(let n of t){let i=this.getSync(n);i!==null&&this.memory.set(n,i)}this.persistent=!1;for(let n of t){try{e==null||e.removeItem(n)}catch{}this.cookies&&P(n,this.cookieDomain())}}};var R=class{constructor(e,t,n,i,s){this.store=e;this.key=t;this.cookieDomain=n;this.cookies=i;this.valid=s}get(e=Date.now()){let t=this.store.getSync(this.key);if(t)try{let n=JSON.parse(t);if(n&&typeof n.id=="string"&&n.exp>e)return n.id}catch{}if(this.cookies&&this.store.isPersistent){let n=L(this.key);if(n&&this.valid(n))return n}return null}set(e,t,n=Date.now()){let i={id:e,exp:n+t};this.store.setSync(this.key,JSON.stringify(i)),this.cookies&&this.store.isPersistent&&N(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 n=JSON.parse(t);n.exp>e&&N(this.key,n.id,(n.exp-e)/1e3,this.cookieDomain())}catch{}}};var Lt="traq_src",Pt=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","fbclid","ttclid"],Ut=200,qt={utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid",referrer:"referrer"},ue=r=>{let e=r==null?void 0:r.trim();return e?e.slice(0,Ut):null},ae=r=>r.toLowerCase().replace(/^www\./,"");function Vt(r,e){let t=ae(r),n=ae(e);return t===n||t.endsWith(`.${n}`)||n.endsWith(`.${t}`)}function Ft(r,e){if(!r)return null;try{let t=new URL(r);return t.protocol!=="http:"&&t.protocol!=="https:"||Vt(new URL(e).hostname,t.hostname)?null:ue(ae(t.hostname))}catch{return null}}function Kt(r,e,t){let n=new URLSearchParams;try{let a=new URL(r).searchParams;for(let u of Pt){let h=ue(a.get(u));h&&n.set(u,h)}}catch{return null}let i=n.toString()!=="",s=Ft(e,r);return s&&n.set("referrer",s),n.toString()===""?null:(n.set("ts",String(t)),{query:n.toString(),fromUrl:i})}function oe(r){let e;try{e=new URLSearchParams(r)}catch{return null}let t={};for(let[i,s]of Object.entries(qt)){let a=ue(e.get(i));a&&(t[s]=a)}if(!Object.keys(t).length)return null;let n=Number(e.get("ts"));return Number.isFinite(n)&&n>0&&(t.landedAt=n),t}var W=class{constructor(e,t,n,i){this.maxAgeMs=t;this.kept=new R(e,Lt,n,i,s=>oe(s)!==null)}capture(e,t,n=Date.now()){let i=Kt(e,t,n);return!i||!i.fromUrl&&this.kept.get(n)!==null?null:(this.kept.set(i.query,this.maxAgeMs,n),oe(i.query))}get(e=Date.now()){let t=this.kept.get(e);return t===null?null:oe(t)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var Gt="traq_click",Wt="traq_click",Ye=/^[A-Za-z0-9_-]{8,64}$/;function Yt(r){try{let e=new URL(r).searchParams.get(Gt);return e&&Ye.test(e)?e:null}catch{return null}}var Y=class{constructor(e,t,n,i){this.maxAgeMs=t;this.kept=new R(e,Wt,n,i,s=>Ye.test(s))}capture(e,t=Date.now()){let n=Yt(e);return n&&this.kept.set(n,this.maxAgeMs,t),n}get(e=Date.now()){return this.kept.get(e)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var Bt="https://api.traqio.app",$t=30,jt=1440*60*1e3;function Qt(){return typeof window!="undefined"&&typeof document!="undefined"}function Xt(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var ce=class{constructor(){this.core=new Be.Client;this.store=null;this.trackIds=null;this.sources=null;this.waitForConsent=!1;this.started=!1}async init(e){var h,M,T;if(this.started||!Qt())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,n,i=()=>n===void 0?n=We(location.hostname):n,s=(h=e.consent)!=null?h:this.earlyConsent,a=!this.waitForConsent||s===!0;this.store=new K(a,i,t);let u=((M=e.trackIdDays)!=null?M:$t)*jt;if(this.trackIds=new Y(this.store,u,i,t),this.trackIds.capture(location.href),this.sources=new W(this.store,u,i,t),this.sources.capture(location.href,document.referrer),!this.store.getSync(G)){let c=Xt();c&&this.store.setSync(G,c)}await this.core.init({sdkKey:e.sdkKey,endpoint:((T=e.endpoint)!=null?T:Bt).replace(/\/+$/,""),storage:this.store,platform:"web",userId:e.userId,consent:s,debug:e.debug,lifecycle:({background:c,foreground:f})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?c():f()),window.addEventListener("pagehide",c)}})}get isDebug(){return this.core.isDebug}track(e,t){this.core.track(e,t)}setUserId(e){this.core.setUserId(e)}async setConsent(e){var t,n;this.started||(this.earlyConsent=e),this.store&&this.waitForConsent&&(e?(this.store.enable(),(t=this.trackIds)==null||t.persistCookie(),(n=this.sources)==null||n.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,n;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear(),(n=this.sources)==null||n.clear()),e}flush(){this.core.flush()}get forgotten(){return this.core.forgotten}},de=new ce;window.Traqio=de;var A=document.currentScript,$e=A==null?void 0:A.dataset.sdkKey;$e&&de.init({sdkKey:$e,endpoint:(A==null?void 0:A.dataset.endpoint)||void 0,waitForConsent:(A==null?void 0:A.dataset.waitForConsent)==="true"});})();
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"});})();
2
2
  //# sourceMappingURL=traqio.min.js.map