@traqio/web 0.2.0 → 0.2.2

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