@traqio/web 0.3.2 → 0.4.1
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.
- package/README.md +26 -0
- package/build/analytics.d.ts +73 -0
- package/build/index.cjs +524 -11
- package/build/index.cjs.map +4 -4
- package/build/index.d.ts +27 -0
- package/build/index.js +524 -11
- package/build/index.js.map +4 -4
- package/build/traqio.min.js +1 -1
- package/build/traqio.min.js.map +4 -4
- package/package.json +2 -2
package/build/traqio.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var Qe=Object.create;var B=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var Je=Object.getPrototypeOf,ze=Object.prototype.hasOwnProperty;var Ze=(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 he=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of He(e))!ze.call(n,r)&&r!==t&&B(n,r,{get:()=>e[r],enumerable:!(i=Xe(e,r))||i.enumerable});return n};var et=(n,e,t)=>(t=n!=null?Qe(Je(n)):{},he(e||!n||!n.__esModule?B(t,"default",{value:n,enumerable:!0}):t,n)),O=n=>he(B({},"__esModule",{value:!0}),n);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=pe;l.shouldLockWindow=ge;l.fineValueForRevenue=me;l.fineValueForEvents=ve;l.coarseValueForRevenue=ye;l.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function pe(n){let e=l.CONVERSION_WINDOWS.find(t=>n>=t.startHours&&n<t.endHours);return e?e.window:null}function ge(n,e){let t=pe(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 tt=63,it=6;function me(n,e){let t=0;for(let i=0;i<Math.min(e.length,tt+1);i++)n>=e[i]&&(t=i);return t}function ve(n,e){let t=new Set(n),i=0;return e.slice(0,it).forEach((r,s)=>{t.has(r)&&(i|=1<<s)}),i}function ye(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 fe={revenue:0,events:[],lastFine:null};l.SKAN_STATE_KEY="traq_skan_state";var $=class{constructor(){this.mapping=null,this.state={...fe},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=ve(this.state.events,e.eventBits)}else{if(!((s=e.revenueBuckets)!=null&&s.length))return;t=me(this.state.revenue,e.revenueBuckets),i=ye(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 ge((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={...fe,...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(n){var i,r;if(!((i=n.native)!=null&&i.getAttributionToken))return"unsupported";if(await _e(n,p.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await n.native.getAttributionToken()}catch{}if(!e||!e.trim()){let s=Number(await _e(n,p.ADSERVICES_ATTEMPTS_KEY))||0;return await Q(n,p.ADSERVICES_ATTEMPTS_KEY,String(s+1)),s+1>=nt&&await Q(n,p.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 Q(n,p.ADSERVICES_SENT_KEY,"1"),"sent"}async function _e(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 Q(n,e,t){var i;try{await((i=n.storage)==null?void 0:i.setItem(e,t))}catch{}}});var H=D(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.isTrackingUrl=ot;k.isOpenUrl=at;k.toDeepLink=Se;k.upgradeStoredDeepLink=ut;var st=/^\/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 ot(n){let e=Ie(n);return e!==null&&(st.test(e)||Ae.test(e))}function at(n){let e=Ie(n);return e!==null&&Ae.test(e)}function Se(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 ut(n){var t,i,r;if(!n||typeof n!="object")return null;let e=n;return e.payload&&e.matchType?e:e.via?Se({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=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=we;d.fromGoogleMobileAdsNativeAd=Ne;d.fromMaxAdInfo=Re;d.fromCapacitorAdMob=lt;d.watchReactNativeAds=ft;function ct(n){return Array.isArray(n)?n.length>0:n===!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 ct(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=J;var dt=["unknown","estimated","publisher_provided","precise"];function be(n){var e;return typeof n=="number"&&(e=dt[n])!=null?e:"unknown"}function y(n){return typeof n=="string"&&n.trim()?n:void 0}function _(n){return n&&typeof n=="object"?n:void 0}function ke(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 z(n,e={}){var a;let t=_(n);if(!t)return;let i=y(t.currency);if(!i)return;let r=ke(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=_(t.responseInfo))==null?void 0:a.loadedAdapterResponse);return{valueMicros:r,currency:i,precision:be(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:y(s==null?void 0:s.adSourceName)}}function we(n,e){let t=_(e),i=_(t==null?void 0:t.body);if(!(!t||(i==null?void 0:i.type)!=="paid"))return z(i.data,{adUnitId:y(t.adUnitId),adFormat:d.GMA_FULLSCREEN_CHANNELS[n]})}function Ne(n){let e=_(n);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 Re(n){let e=_(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 lt(n,e){let t=_(n),i=ke(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:be(t.precision),adUnitId:y(t.adUnitId),adFormat:e,adSourceName:y(t.networkName)}}function Ee(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 ht=["interstitial","rewarded","rewarded_interstitial","app_open"];function ft(n,e,t){var u,h,M,T;if(!t)try{t=(w(),O(C))}catch{return{coverage:{},stop:()=>{}}}let i=[],r={},s=(c,f,m=v=>v)=>v=>{try{let I=c(v);I&&f(I,m(v))}catch{}},a=c=>{var f,m;return(m=_((f=_(c))==null?void 0:f.body))==null?void 0:m.data};if(n.admob){r.admob=[];for(let[m,v]of Object.entries(d.GMA_FULLSCREEN_CHANNELS)){let I=(u=t.DeviceEventEmitter)==null?void 0:u.addListener(m,s(E=>we(m,E),e.admob,a));I&&(i.push(I),r.admob.push(v))}let c=Ee(t,"RNGoogleMobileAdsNativeModule"),f=s(Ne,e.admob);try{if(c&&typeof c.onAdEvent=="function")i.push(c.onAdEvent(f)),r.admob.push("native");else if(c&&t.NativeEventEmitter){let m=new t.NativeEventEmitter(((h=t.Platform)==null?void 0:h.OS)==="ios"?c:void 0);i.push(m.addListener("RNGMANativeAdEvent",f)),r.admob.push("native")}}catch{}}if(n.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:{},I=Object.keys(v).filter(E=>/^ON_.*_AD_REVENUE_PAID$/.test(E)).map(E=>v[E]).filter(E=>typeof E=="string");I.length&&(f=[...new Set([...I,...f])])}catch{}let m=new t.NativeEventEmitter(c);for(let v of f)i.push(m.addListener(v,s(Re,e.applovinMax)));r.applovinMax=[...ht]}catch{}}return{coverage:r,stop:()=>{for(let c of i.splice(0))try{c.remove()}catch{}}}}});var We=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=Ge;var pt=j(),gt=X(),S=H(),U=Z();o.SDK_VERSION="0.6.0";var mt=j();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return mt.Skan}});var vt=X();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return vt.reportAdServicesToken}});var Ke=H();Object.defineProperty(o,"isOpenUrl",{enumerable:!0,get:function(){return Ke.isOpenUrl}});Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return Ke.isTrackingUrl}});var g=Z();Object.defineProperty(o,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return g.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(o,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return g.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(o,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return g.GMA_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return g.MAX_RN_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return g.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(o,"fromCapacitorAdMob",{enumerable:!0,get:function(){return g.fromCapacitorAdMob}});Object.defineProperty(o,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return g.fromGoogleMobileAdsChannel}});Object.defineProperty(o,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return g.fromGoogleMobileAdsNativeAd}});Object.defineProperty(o,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return g.fromGoogleMobileAdsPaid}});Object.defineProperty(o,"fromMaxAdInfo",{enumerable:!0,get:function(){return g.fromMaxAdInfo}});Object.defineProperty(o,"watchReactNativeAds",{enumerable:!0,get:function(){return g.watchReactNativeAds}});Object.defineProperty(o,"AdRevenueGate",{enumerable:!0,get:function(){return g.AdRevenueGate}});var yt="traq_install_sent",_t="traq_install_sent_debug",Me="traq_install_attempts",At="traq_ad_id_sent",It="traq_ad_id_sent_debug",ee="/ingest/advertising-id",Te="traq_referrer",De="traq_queue",Oe="traq_ad_queue",Ce="traq_device_id",xe="traq_last_session",Le="traq_erased",b="traq_deferred_link",te="traq_deferred_consent_retry_until",St=60*6e4,Pe="traq_consent",Et=20,bt=new Set([400,413,422]),Ue=500,kt=100,qe=1e3,ie=1e3,wt=300*1e3,Nt=3e3,Rt=3,Mt=1800*1e3,Tt=["not_determined","restricted","denied","authorized"],Dt={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},Ot={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"},Ct="00000000-0000-0000-0000-000000000000";function Ve(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===Ct?void 0:e}function q(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=Dt[(e=n.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:n.adUnitId,adFormat:Ot[((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 xt(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Lt(){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 Pt(){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 K=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=ie,this.skan=new pt.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,U.fromMaxAdInfo)(e),i=t&&q(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:Lt()},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 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,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=(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: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:Pt()}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 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:x(),ts:(r=e.ts)!=null?r:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>qe&&this.adQueue.splice(0,this.adQueue.length-qe),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,S.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),i=(0,S.isOpenUrl)(e),r=(0,S.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,S.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(Pe,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,gt.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 h=await(t==null?void 0:t.getItem(b));if(h)return(0,S.upgradeStoredDeepLink)(JSON.parse(h))}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 a=(0,S.toDeepLink)(s,!0),u=await this.storedDeferred();if(u)return u;try{await(t==null?void 0:t.setItem(b,JSON.stringify(a))),!a&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(te,String(Date.now()+St)))}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(te).catch(()=>null));if(!t||(await e.setItem(te,"").catch(()=>{}),Date.now()>t))return null;let i=await this.storedDeferred();if(i)return i;let r=(0,S.toDeepLink)(await this.askDeferred(this.hostPlatform,void 0),!0);return r?(await((a=this.opts.storage)==null?void 0:a.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,S.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?_t:yt}get adIdSentKey(){return this.debug?It:At}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(Le))==="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(Le,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>Ue&&this.queue.splice(0,this.queue.length-Ue),this.persistQueue(),this.scheduleFlush()}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(De));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(De,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,i;try{let r=await((e=this.opts.storage)==null?void 0:e.getItem(Oe));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(Oe,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(xe).catch(()=>null)))||0;if(h&&t-h<Mt)return}let i=(a=this.context.deviceId)!=null?a: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(xe,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:xt(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var t,i;try{let r=await((t=this.opts.storage)==null?void 0:t.getItem(Ce));if(r)return r}catch{}let e=x();try{await((i=this.opts.storage)==null?void 0:i.setItem(Ce,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(Te));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(Te,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 i=await this.readReferrer();if(i.retryable&&e){let a=Number(await e.getItem(Me))||0;if(a+1<Rt){await e.setItem(Me,String(a+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},ee)&&await e.setItem(this.adIdSentKey,i)}catch{}}scheduleFlush(e=Nt){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,Et),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=ie}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(kt,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:a,...u})=>u)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,r.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=ie}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,wt),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(Pe).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));Tt.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===ee)?{consent:this.consent}:{},r=(t==="/ingest"||t===ee)&&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":bt.has(s.status)?"refused":"retry"}catch{return"retry"}}};o.Client=K;async function Fe(n){var e,t;if(n.debug!==void 0)return n.debug;if(n.platform==="web")return Ge();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 Ge(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 K});var $e=et(We(),1);var re="traq_";function se(){return typeof document=="undefined"?void 0:document}function L(n){let e=se();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 ne(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 Ye(n){let e=se();if(!e||!n.includes(".")||/^[\d.]+$/.test(n)||n.includes(":"))return null;let t=n.split("."),i=`${re}probe`;for(let r=t.length-2;r>=0;r--){let s=t.slice(r).join(".");if(e.cookie=ne(i,"1",10,s),L(i)==="1")return e.cookie=ne(i,"",0,s),s}return null}function N(n,e,t,i){let r=se();if(r)try{r.cookie=ne(n,e,t,i)}catch{}}function P(n,e){N(n,"",0,e)}var G="traq_device_id",oe=new Set([G]),Ut=395*24*60*60;function V(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var F=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&&oe.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&&oe.has(e)&&N(e,t,Ut,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(re)&&t.push(r)}}catch{}for(let i of oe)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 R=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&&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 i=JSON.parse(t);i.exp>e&&N(this.key,i.id,(i.exp-e)/1e3,this.cookieDomain())}catch{}}};var qt="traq_src",Kt=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","fbclid","ttclid"],Vt=200,Ft={utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid",referrer:"referrer"},ce=n=>{let e=n==null?void 0:n.trim();return e?e.slice(0,Vt):null},ue=n=>n.toLowerCase().replace(/^www\./,"");function Gt(n,e){let t=ue(n),i=ue(e);return t===i||t.endsWith(`.${i}`)||i.endsWith(`.${t}`)}function Wt(n,e){if(!n)return null;try{let t=new URL(n);return t.protocol!=="http:"&&t.protocol!=="https:"||Gt(new URL(e).hostname,t.hostname)?null:ce(ue(t.hostname))}catch{return null}}function Yt(n,e,t){let i=new URLSearchParams;try{let a=new URL(n).searchParams;for(let u of Kt){let h=ce(a.get(u));h&&i.set(u,h)}}catch{return null}let r=i.toString()!=="",s=Wt(e,n);return s&&i.set("referrer",s),i.toString()===""?null:(i.set("ts",String(t)),{query:i.toString(),fromUrl:r})}function ae(n){let e;try{e=new URLSearchParams(n)}catch{return null}let t={};for(let[r,s]of Object.entries(Ft)){let a=ce(e.get(r));a&&(t[s]=a)}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 R(e,qt,i,r,s=>ae(s)!==null)}capture(e,t,i=Date.now()){let r=Yt(e,t,i);return!r||!r.fromUrl&&this.kept.get(i)!==null?null:(this.kept.set(r.query,this.maxAgeMs,i),ae(r.query))}get(e=Date.now()){let t=this.kept.get(e);return t===null?null:ae(t)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var Bt="traq_click",$t="traq_click",Be=/^[A-Za-z0-9_-]{8,64}$/;function jt(n){try{let e=new URL(n).searchParams.get(Bt);return e&&Be.test(e)?e:null}catch{return null}}var Y=class{constructor(e,t,i,r){this.maxAgeMs=t;this.kept=new R(e,$t,i,r,s=>Be.test(s))}capture(e,t=Date.now()){let i=jt(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 Qt="https://api.traqio.app",Xt=30,Ht=1440*60*1e3;function Jt(){return typeof window!="undefined"&&typeof document!="undefined"}function zt(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var de=class{constructor(){this.core=new $e.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||!Jt())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,i,r=()=>i===void 0?i=Ye(location.hostname):i,s=(h=e.consent)!=null?h:this.earlyConsent,a=!this.waitForConsent||s===!0;this.store=new F(a,r,t);let u=((M=e.trackIdDays)!=null?M:Xt)*Ht;if(this.trackIds=new Y(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(G)){let c=zt();c&&this.store.setSync(G,c)}await this.core.init({sdkKey:e.sdkKey,endpoint:((T=e.endpoint)!=null?T:Qt).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,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;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear(),(i=this.sources)==null||i.clear()),e}flush(){this.core.flush()}get forgotten(){return this.core.forgotten}},le=new de;window.Traqio=le;var A=document.currentScript,je=A==null?void 0:A.dataset.sdkKey;je&&le.init({sdkKey:je,endpoint:(A==null?void 0:A.dataset.endpoint)||void 0,waitForConsent:(A==null?void 0:A.dataset.waitForConsent)==="true"});})();
|
|
1
|
+
"use strict";(()=>{var nt=Object.create;var H=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var ut=(n,e,t)=>()=>{if(t)throw t[0];try{return n&&(e=n(n=0)),e}catch(i){throw t=[i],i}};var N=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var ve=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of rt(e))!at.call(n,s)&&s!==t&&H(n,s,{get:()=>e[s],enumerable:!(i=st(e,s))||i.enumerable});return n};var ct=(n,e,t)=>(t=n!=null?nt(ot(n)):{},ve(e||!n||!n.__esModule?H(t,"default",{value:n,enumerable:!0}):t,n)),P=n=>ve(H({},"__esModule",{value:!0}),n);var z=N(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.Skan=p.SKAN_STATE_KEY=p.CONVERSION_WINDOWS=void 0;p.windowForAge=_e;p.shouldLockWindow=Ae;p.fineValueForRevenue=Ee;p.fineValueForEvents=Ie;p.coarseValueForRevenue=be;p.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function _e(n){let e=p.CONVERSION_WINDOWS.find(t=>n>=t.startHours&&n<t.endHours);return e?e.window:null}function Ae(n,e){let t=_e(e);if(t==null||!n||!n.length)return!1;let i=n.find(s=>s.window===t);return!i||!i.lock?!1:i.lockAfterHours==null?!0:e>=i.lockAfterHours}var dt=63,lt=6;function Ee(n,e){let t=0;for(let i=0;i<Math.min(e.length,dt+1);i++)n>=e[i]&&(t=i);return t}function Ie(n,e){let t=new Set(n),i=0;return e.slice(0,lt).forEach((s,r)=>{t.has(s)&&(i|=1<<r)}),i}function be(n,e){if(!e)return;let t,i=-1/0;for(let s of["low","medium","high"]){let r=e[s];r!=null&&n>=r&&r>=i&&(t=s,i=r)}return t}var Se={revenue:0,events:[],lastFine:null};p.SKAN_STATE_KEY="traq_skan_state";var J=class{constructor(){this.mapping=null,this.state={...Se},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 s,r;let e=this.mapping;if(!e||!this.opts.native)return;let t,i;if(e.mode==="events"){if(!((s=e.eventBits)!=null&&s.length))return;t=Ie(this.state.events,e.eventBits)}else{if(!((r=e.revenueBuckets)!=null&&r.length))return;t=Ee(this.state.revenue,e.revenueBuckets),i=be(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 Ae((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 s=await i.json();return s&&typeof s=="object"?s:null}catch{return null}}async restore(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(p.SKAN_STATE_KEY));t&&(this.state={...Se,...JSON.parse(t)})}catch{}}async persist(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(p.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};p.Skan=J});var Z=N(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.MAX_PROPS_BYTES=f.MAX_SCREEN_NAME=f.MAX_EVENT_NAME=f.ANALYTICS_SESSION_IDLE_MS=void 0;f.cleanEventName=ht;f.cleanScreenName=ft;f.cleanProps=pt;f.touchSession=gt;f.parseSession=mt;f.ANALYTICS_SESSION_IDLE_MS=1800*1e3;f.MAX_EVENT_NAME=128;f.MAX_SCREEN_NAME=512;f.MAX_PROPS_BYTES=4096;function ht(n){if(typeof n!="string")return null;let e=n.trim();return!e||e.length>f.MAX_EVENT_NAME||e.startsWith("$")?null:e}function ft(n){if(typeof n!="string")return null;let e=n.trim();return e?e.slice(0,f.MAX_SCREEN_NAME):null}function pt(n){if(!(typeof n!="object"||n===null||Array.isArray(n)))try{let e=JSON.stringify(n);return!e||e==="{}"||e.length>f.MAX_PROPS_BYTES?void 0:JSON.parse(e)}catch{return}}function gt(n,e,t){return n&&typeof n.id=="string"&&typeof n.last=="number"&&e-n.last<=f.ANALYTICS_SESSION_IDLE_MS&&e>=n.last-6e4?{id:n.id,last:Math.max(e,n.last)}:{id:t(),last:e}}function mt(n){if(!n)return null;try{let e=JSON.parse(n);return typeof e.id=="string"&&typeof e.last=="number"?{id:e.id,last:e.last}:null}catch{return null}}});var te=N(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.ADSERVICES_ATTEMPTS_KEY=y.ADSERVICES_SENT_KEY=void 0;y.reportAdServicesToken=vt;y.ADSERVICES_SENT_KEY="traq_adservices_sent";y.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var yt=5;async function vt(n){var i,s;if(!((i=n.native)!=null&&i.getAttributionToken))return"unsupported";if(await we(n,y.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await n.native.getAttributionToken()}catch{}if(!e||!e.trim()){let r=Number(await we(n,y.ADSERVICES_ATTEMPTS_KEY))||0;return await ee(n,y.ADSERVICES_ATTEMPTS_KEY,String(r+1)),r+1>=yt&&await ee(n,y.ADSERVICES_SENT_KEY,"1"),"no-token"}let t=(s=n.fetchFn)!=null?s: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 ee(n,y.ADSERVICES_SENT_KEY,"1"),"sent"}async function we(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 ee(n,e,t){var i;try{await((i=n.storage)==null?void 0:i.setItem(e,t))}catch{}}});var ie=N(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.isTrackingUrl=_t;R.isOpenUrl=At;R.toDeepLink=Re;R.upgradeStoredDeepLink=Et;var St=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/,ke=/^\/o\/[0-9a-fA-F-]{36}\/?$/;function Ne(n){var t;let e=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(n);return e?(t=e[1])!=null?t:"":null}function _t(n){let e=Ne(n);return e!==null&&(St.test(e)||ke.test(e))}function At(n){let e=Ne(n);return e!==null&&ke.test(e)}function Re(n,e,t){var r,a,u;if(!(n!=null&&n.matched)||!n.via)return null;let i=(r=n.matchType)!=null?r:n.via==="ip_match"?"probabilistic":n.via,s=(a=n.payload)!=null?a:{deepLink:n.deepLink,value:null,params:{}};return{payload:s,matchType:i,confidence:i==="probabilistic"?(u=n.confidence)!=null?u:"low":null,deferred:e,code:n.code,deepLink:s.deepLink,via:n.via,...t?{url:t}:{}}}function Et(n){var t,i,s;if(!n||typeof n!="object")return null;let e=n;return e.payload&&e.matchType?e:e.via?Re({matched:!0,via:e.via,code:(t=e.code)!=null?t:null,deepLink:(i=e.deepLink)!=null?i:null},(s=e.deferred)!=null?s:!0,e.url):null}});var x={};var M=ut(()=>{"use strict"});var re=N(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=se;c.fromGoogleMobileAdsChannel=De;c.fromGoogleMobileAdsNativeAd=Ce;c.fromMaxAdInfo=Le;c.fromCapacitorAdMob=wt;c.watchReactNativeAds=Nt;function It(n){return Array.isArray(n)?n.length>0:n===!0}var ne=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 It(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,s){return this.capturesFormat(e,t)?(this.warnOnce(`helper:${e}:${t}`,`[traqio] adRevenue.${e} already captures ${t} ads: ${s} 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=ne;var bt=["unknown","estimated","publisher_provided","precise"];function Te(n){var e;return typeof n=="number"&&(e=bt[n])!=null?e:"unknown"}function _(n){return typeof n=="string"&&n.trim()?n:void 0}function A(n){return n&&typeof n=="object"?n:void 0}function Oe(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 se(n,e={}){var a;let t=A(n);if(!t)return;let i=_(t.currency);if(!i)return;let s=Oe(t.valueMicros);if(s===void 0){if(!(typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=0))return;s=Math.round(t.value*1e6)}let r=A((a=A(t.responseInfo))==null?void 0:a.loadedAdapterResponse);return{valueMicros:s,currency:i,precision:Te(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:_(r==null?void 0:r.adSourceName)}}function De(n,e){let t=A(e),i=A(t==null?void 0:t.body);if(!(!t||(i==null?void 0:i.type)!=="paid"))return se(i.data,{adUnitId:_(t.adUnitId),adFormat:c.GMA_FULLSCREEN_CHANNELS[n]})}function Ce(n){let e=A(n);if((e==null?void 0:e.type)==="paid")return se(e,{adFormat:"native"})}c.MAX_RN_REVENUE_EVENTS=["OnBannerAdRevenuePaid","OnMRecAdRevenuePaid","OnInterstitialAdRevenuePaid","OnRewardedAdRevenuePaid","OnAppOpenAdRevenuePaid"];c.MAX_RN_MIN_VERSION="5.0.0";function Le(n){let e=A(n);if(!(!e||typeof e.revenue!="number"))return{revenue:e.revenue,revenuePrecision:_(e.revenuePrecision),adUnitId:_(e.adUnitId),format:_(e.adFormat),networkName:_(e.networkName)}}c.CAPACITOR_ADMOB_PAID_EVENTS={bannerAdPaid:"banner",nativeAdPaid:"native",interstitialAdImpression:"interstitial",onRewardedVideoAdImpression:"rewarded",onRewardedInterstitialAdImpression:"rewarded_interstitial",appOpenAdImpression:"app_open"};function wt(n,e){let t=A(n),i=Oe(t==null?void 0:t.valueMicros),s=_(t==null?void 0:t.currencyCode);if(!(!t||i===void 0||!s))return{valueMicros:i,currency:s,precision:Te(t.precision),adUnitId:_(t.adUnitId),adFormat:e,adSourceName:_(t.networkName)}}function Me(n,e){var t,i,s,r,a;try{return(r=(i=(t=n.TurboModuleRegistry)==null?void 0:t.get)==null?void 0:i.call(t,e))!=null?r:(s=n.NativeModules)==null?void 0:s[e]}catch{return(a=n.NativeModules)==null?void 0:a[e]}}var kt=["interstitial","rewarded","rewarded_interstitial","app_open"];function Nt(n,e,t){var u,h,C,L;if(!t)try{t=(M(),P(x))}catch{return{coverage:{},stop:()=>{}}}let i=[],s={},r=(d,l,g=m=>m)=>m=>{try{let E=d(m);E&&l(E,g(m))}catch{}},a=d=>{var l,g;return(g=A((l=A(d))==null?void 0:l.body))==null?void 0:g.data};if(n.admob){s.admob=[];for(let[g,m]of Object.entries(c.GMA_FULLSCREEN_CHANNELS)){let E=(u=t.DeviceEventEmitter)==null?void 0:u.addListener(g,r(b=>De(g,b),e.admob,a));E&&(i.push(E),s.admob.push(m))}let d=Me(t,"RNGoogleMobileAdsNativeModule"),l=r(Ce,e.admob);try{if(d&&typeof d.onAdEvent=="function")i.push(d.onAdEvent(l)),s.admob.push("native");else if(d&&t.NativeEventEmitter){let g=new t.NativeEventEmitter(((h=t.Platform)==null?void 0:h.OS)==="ios"?d:void 0);i.push(g.addListener("RNGMANativeAdEvent",l)),s.admob.push("native")}}catch{}}if(n.applovinMax){let d=Me(t,"AppLovinMAX");if(d&&t.NativeEventEmitter)try{let l=[...c.MAX_RN_REVENUE_EVENTS];try{let m=(L=(C=d.getConstants)==null?void 0:C.call(d))!=null?L:{},E=Object.keys(m).filter(b=>/^ON_.*_AD_REVENUE_PAID$/.test(b)).map(b=>m[b]).filter(b=>typeof b=="string");E.length&&(l=[...new Set([...E,...l])])}catch{}let g=new t.NativeEventEmitter(d);for(let m of l)i.push(g.addListener(m,r(Le,e.applovinMax)));s.applovinMax=[...kt]}catch{}}return{coverage:s,stop:()=>{for(let d of i.splice(0))try{d.remove()}catch{}}}}});var Je=N(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.ANALYTICS_SESSION_IDLE_MS=o.reportAdServicesToken=o.Skan=o.SDK_VERSION=void 0;o.normalizeAdvertisingId=Xe;o.fromMaxAd=Y;o.detectDebug=Be;o.isLocalPage=He;var Rt=z(),w=Z(),Mt=te(),I=ie(),V=re();o.SDK_VERSION="0.7.0";var Tt=z();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return Tt.Skan}});var Ot=te();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return Ot.reportAdServicesToken}});var Dt=Z();Object.defineProperty(o,"ANALYTICS_SESSION_IDLE_MS",{enumerable:!0,get:function(){return Dt.ANALYTICS_SESSION_IDLE_MS}});var $e=ie();Object.defineProperty(o,"isOpenUrl",{enumerable:!0,get:function(){return $e.isOpenUrl}});Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return $e.isTrackingUrl}});var v=re();Object.defineProperty(o,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return v.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(o,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return v.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(o,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return v.GMA_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return v.MAX_RN_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return v.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(o,"fromCapacitorAdMob",{enumerable:!0,get:function(){return v.fromCapacitorAdMob}});Object.defineProperty(o,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return v.fromGoogleMobileAdsChannel}});Object.defineProperty(o,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return v.fromGoogleMobileAdsNativeAd}});Object.defineProperty(o,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return v.fromGoogleMobileAdsPaid}});Object.defineProperty(o,"fromMaxAdInfo",{enumerable:!0,get:function(){return v.fromMaxAdInfo}});Object.defineProperty(o,"watchReactNativeAds",{enumerable:!0,get:function(){return v.watchReactNativeAds}});Object.defineProperty(o,"AdRevenueGate",{enumerable:!0,get:function(){return v.AdRevenueGate}});var Ct="traq_install_sent",Lt="traq_install_sent_debug",Pe="traq_install_attempts",Pt="traq_ad_id_sent",xt="traq_ad_id_sent_debug",oe="/ingest/advertising-id",xe="traq_referrer",Ue="traq_queue",qe="traq_ad_queue",Ke="traq_device_id",Ve="traq_last_session",Fe="traq_erased",k="traq_deferred_link",ae="traq_deferred_consent_retry_until",Ut=60*6e4,Ye="traq_consent",Qe="traq_analytics_queue",Ge="traq_analytics_session",qt="/ingest/analytics",Kt=50,ue=1e3,Vt=100,Ft=20,Yt=new Set([400,413,422]),We=500,Qt=100,je=1e3,F=1e3,Gt=300*1e3,Wt=3e3,jt=3,$t=1800*1e3,Xt=["not_determined","restricted","denied","authorized"],Bt={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},Ht={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"},Jt="00000000-0000-0000-0000-000000000000";function Xe(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===Jt?void 0:e}function Y(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=Bt[(e=n.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:n.adUnitId,adFormat:Ht[((i=n.format)!=null?i:"").toUpperCase()],adSourceName:n.networkName,ts:n.ts}}function T(){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 zt(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Zt(){var n;try{let e=(M(),P(x)),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,s)=>t.setItem(i,s)}}catch{}}function ei(){var n,e;try{let t=(e=(n=(M(),P(x)))==null?void 0:n.Platform)==null?void 0:e.OS;return t==="ios"||t==="android"?t:void 0}catch{return}}var Q=class{constructor(){this.queue=[],this.adQueue=[],this.adGate=new V.AdRevenueGate,this.adBatchId=null,this.context={sdkVersion:o.SDK_VERSION},this.referrer=null,this.started=!1,this.flushing=!1,this.flushTimer=null,this.retryMs=F,this.skan=new Rt.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null,this.att=null,this.adIdSync=null,this.debug=!1,this.analyticsQueue=[],this.analyticsSession=null,this.earlyAnalytics=[],this.currentScreen=null,this.maxRevenuePaid=e=>{try{let t=(0,V.fromMaxAdInfo)(e),i=t&&Y(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){if(this.started=!0,this.opts={collectContext:!0,...e,storage:(t=e.storage)!=null?t:Zt()},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 Be(e),await this.restoreConsent(e.consent),await this.restoreQueue(),await this.restoreAdQueue(),await this.restoreAnalytics(),await this.buildContext(),await this.restoreErased()){this.earlyAnalytics=[];return}if(this.isWeb)this.earlyAnalytics=[];else for(let i of this.earlyAnalytics.splice(0))this.pushAnalytics(i,!1);if(!this.isWeb){let i=!!this.opts.storage&&!await this.opts.storage.getItem(this.installSentKey).catch(()=>"1");await this.sendInstallOnce(),this.syncAdvertisingId(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(i).then(s=>s!=null?s:this.retryDeferredWithConsent()),this.wireDeepLinks())}await this.maybeStartSession(!this.isWeb),await this.initSkan(),await this.initAppleAds(),this.wireLifecycle(),this.wireAdRevenue(),(this.queue.length||this.adQueue.length||this.analyticsQueue.length)&&this.scheduleFlush(0)}}wireAdRevenue(){var i,s;let e=this.opts.adRevenue;if(!e||this.isWeb||!(e.admob||e.applovinMax))return;let t={admob:(r,a)=>{this.adGate.first(a)&&this.queueAdRevenue(r,"admob","auto")},applovinMax:(r,a)=>{let u=Y(r);u&&this.adGate.first(a)&&this.queueAdRevenue(u,"applovin_max","auto")}};try{let r=(i=this.opts.native)!=null&&i.watchAdRevenue?(s=this.opts.native.watchAdRevenue(e,t))!=null?s:e:(0,V.watchReactNativeAds)(e,t).coverage;this.adGate.arm(r)}catch{}}track(e,t){var s,r;if(!this.started||this.erased)return;let i=((s=t==null?void 0:t.transactionId)==null?void 0:s.trim())||void 0;this.enqueue({name:e,eventId:T(),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)}capture(e,t){try{let i=(0,w.cleanEventName)(e);if(!i)return;let s=(0,w.cleanProps)(t);this.queueAnalytics({kind:"custom",name:i,ts:Date.now(),...s?{props:s}:{}})}catch{}}screen(e,t){try{let i=(0,w.cleanScreenName)(e);if(!i)return;let s=Date.now(),r=this.analyticsSession!==null&&s-this.analyticsSession.last<=w.ANALYTICS_SESSION_IDLE_MS;if(i===this.currentScreen&&r)return;this.currentScreen=i;let a=(0,w.cleanProps)(t);this.queueAnalytics({kind:"pageview",ts:s,screen:i,...a?{props:a}:{}})}catch{}}trackScreens(e){let t=()=>{try{let s=e.getCurrentRoute();s!=null&&s.name&&this.screen(s.name)}catch{}},i;try{i=e.addListener("state",t)}catch{i=void 0}return t(),()=>{try{typeof i=="function"&&i()}catch{}}}get hostPlatform(){var e,t;return(t=(e=this.opts.native)==null?void 0:e.platform)!=null?t:ei()}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=Y(e);t&&this.queueAdRevenue(t,"applovin_max","manual")}admobPaid(e,t="banner"){return i=>{try{let s=(0,V.fromGoogleMobileAdsPaid)(i,{adUnitId:e,adFormat:t});s&&this.adGate.helper("admob",t,i,"Traqio.admobPaid()")&&this.queueAdRevenue(s,"admob","auto")}catch{}}}queueAdRevenue(e,t,i){var s;!this.started||this.erased||!(e.valueMicros>=0)||!e.currency||(this.adQueue.push({...e,source:t,origin:i,impressionId:T(),ts:(s=e.ts)!=null?s:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>je&&this.adQueue.splice(0,this.adQueue.length-je),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,I.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),i=(0,I.isOpenUrl)(e),s=(0,I.toDeepLink)(t,i,e);return s&&i&&await this.keepDeferred(s),s&&this.emitDeepLink(s),s}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,I.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(Ye,this.consent).catch(()=>{})),e&&this.deferred&&!this.erased&&(this.deferred=this.deferred.then(s=>s!=null?s: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,Mt.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,s)=>{var r;return(r=e.updateConversionValue)==null?void 0:r.call(e,t,i,s)}}})}async resolveDeferredOnce(e){let t=this.opts.storage;try{let h=await(t==null?void 0:t.getItem(k));if(h)return(0,I.upgradeStoredDeepLink)(JSON.parse(h))}catch{}if(!e&&!await(t==null?void 0:t.getItem(`${k}_pending`).catch(()=>null)))return null;let i=this.hostPlatform,s=i==="android"?await this.readReferrer():null;await(t==null?void 0:t.setItem(`${k}_pending`,"1").catch(()=>{}));let r=await this.askDeferred(i,s==null?void 0:s.referrer);if(!r)return null;let a=(0,I.toDeepLink)(r,!0),u=await this.storedDeferred();if(u)return u;try{await(t==null?void 0:t.setItem(k,JSON.stringify(a))),!a&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(ae,String(Date.now()+Ut)))}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;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(ae).catch(()=>null));if(!t||(await e.setItem(ae,"").catch(()=>{}),Date.now()>t))return null;let i=await this.storedDeferred();if(i)return i;let s=(0,I.toDeepLink)(await this.askDeferred(this.hostPlatform,void 0),!0);return s?(await((a=this.opts.storage)==null?void 0:a.setItem(k,JSON.stringify(s)).catch(()=>{})),this.emitDeepLink(s),s):null}async storedDeferred(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(k));return t?(0,I.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(k,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}=(M(),P(x));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?Lt:Ct}get adIdSentKey(){return this.debug?xt:Pt}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}=(M(),P(x));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(Fe))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var e;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,this.analyticsQueue=[],this.earlyAnalytics=[],await this.persistQueue(),await this.persistAdQueue(),await this.persistAnalyticsQueue();try{await((e=this.opts.storage)==null?void 0:e.setItem(Fe,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>We&&this.queue.splice(0,this.queue.length-We),this.persistQueue(),this.scheduleFlush()}queueAnalytics(e){var s,r;if(this.erased)return;let t=(r=(s=e.screen)!=null?s:this.currentScreen)!=null?r:void 0,i=t?{...e,screen:t}:e;if(!this.started){this.earlyAnalytics.length<Vt&&this.earlyAnalytics.push(i);return}this.isWeb||this.pushAnalytics(i)}pushAnalytics(e,t=!0){this.analyticsSession=(0,w.touchSession)(this.analyticsSession,e.ts,T),this.analyticsQueue.push({...e,sessionId:this.analyticsSession.id}),this.analyticsQueue.length>ue&&this.analyticsQueue.splice(0,this.analyticsQueue.length-ue),this.persistAnalyticsQueue(),t&&this.scheduleFlush()}async restoreAnalytics(){var e,t,i;try{let s=await((e=this.opts.storage)==null?void 0:e.getItem(Qe)),r=s?JSON.parse(s):null;Array.isArray(r)&&(this.analyticsQueue=[...r,...this.analyticsQueue].slice(-ue))}catch{}try{(i=this.analyticsSession)!=null||(this.analyticsSession=(0,w.parseSession)(await((t=this.opts.storage)==null?void 0:t.getItem(Ge))))}catch{}}async persistAnalyticsQueue(){var e,t;try{await((e=this.opts.storage)==null?void 0:e.setItem(Qe,JSON.stringify(this.analyticsQueue))),this.analyticsSession&&await((t=this.opts.storage)==null?void 0:t.setItem(Ge,JSON.stringify(this.analyticsSession)))}catch{}}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(Ue));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(Ue,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,i;try{let s=await((e=this.opts.storage)==null?void 0:e.getItem(qe));if(!s)return;let r=JSON.parse(s);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(qe,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(Ve).catch(()=>null)))||0;if(h&&t-h<$t)return}let i=(a=this.context.deviceId)!=null?a:await this.getOrCreateDeviceId();if(await this.post({deviceId:i,appUserId:this.opts.userId,sessionId:T(),ts:Math.floor(t/1e3),context:this.context},"/ingest/session"))try{await((u=this.opts.storage)==null?void 0:u.setItem(Ve,String(t)))}catch{}}async buildContext(){var t,i,s;if(!this.opts.collectContext){this.context={sdkVersion:o.SDK_VERSION};return}let e={};try{e=(s=await((i=(t=this.opts.native)==null?void 0:t.getContext)==null?void 0:i.call(t)))!=null?s:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:e.deviceModel,osVersion:e.osVersion,appVersion:this.opts.appVersion,locale:zt(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var t,i;try{let s=await((t=this.opts.storage)==null?void 0:t.getItem(Ke));if(s)return s}catch{}let e=T();try{await((i=this.opts.storage)==null?void 0:i.setItem(Ke,e))}catch{}return e}async readReferrer(){var i,s;if(this.referrer)return this.referrer;try{let r=await((i=this.opts.storage)==null?void 0:i.getItem(xe));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((s=this.opts.storage)==null?void 0:s.setItem(xe,JSON.stringify(t)))}catch{}}return t}async readAdvertisingId(){var e;if(!(!this.opts.collectAdvertisingId||!((e=this.opts.native)!=null&&e.getAdvertisingId)))try{return Xe(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 a=Number(await e.getItem(Pe))||0;if(a+1<jt){await e.setItem(Pe,String(a+1));return}}let s=await this.readAdvertisingId();await this.post({install:{platform:t,installReferrer:i.referrer,appUserId:this.opts.userId,advertisingId:s,context:this.context}})&&(await(e==null?void 0:e.setItem(this.installSentKey,"1")),s&&await(e==null?void 0:e.setItem(this.adIdSentKey,s).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 s=(t=this.context.deviceId)!=null?t:await this.getOrCreateDeviceId();await this.post({deviceId:s,appUserId:this.opts.userId,advertisingId:i},oe)&&await e.setItem(this.adIdSentKey,i)}catch{}}scheduleFlush(e=Wt){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},e))}async drain(){var e,t;if(!this.erased&&!(this.flushing||!this.queue.length&&!this.adQueue.length&&!this.analyticsQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let i=this.queue.slice(0,Ft),s=await this.send({events:i,appUserId:this.opts.userId,deviceId:this.context.deviceId});if(s==="retry")return this.backOff();s==="refused"&&console.warn(`[traqio] the server refused ${i.length} event(s) as malformed \u2014 dropped, not retried`),this.queue.splice(0,i.length),await this.persistQueue(),this.retryMs=F}for(;this.adQueue.length;){let i=(e=this.adQueue[0].source)!=null?e:"admob",s=this.adQueue.findIndex(u=>{var h;return((h=u.source)!=null?h:"admob")!==i}),r=this.adQueue.slice(0,Math.min(Qt,s===-1?this.adQueue.length:s));if(this.adBatchId||(this.adBatchId=T(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:i,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:r.map(({source:u,...h})=>h)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,r.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=F}for(;this.analyticsQueue.length;){let i=this.analyticsQueue.slice(0,Kt),s=await this.send({anonymousId:(t=this.context.deviceId)!=null?t:await this.getOrCreateDeviceId(),userId:this.opts.userId,platform:this.hostPlatform,events:i},qt);if(s==="retry")return this.backOff();s==="refused"&&console.warn(`[traqio] the server refused ${i.length} analytics event(s) as malformed \u2014 dropped, not retried`),this.analyticsQueue.splice(0,i.length),await this.persistAnalyticsQueue(),this.retryMs=F}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,Gt),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(Ye).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));Xt.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===oe)?{consent:this.consent}:{},s=(t==="/ingest"||t===oe)&&this.asksTrackingAuthorization?await this.readTrackingAuthorization():null;try{let r=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...i,...s?{att:s}:{},...this.debugField()}),...this.keepalive()});return r.ok?"ok":Yt.has(r.status)?"refused":"retry"}catch{return"retry"}}};o.Client=Q;async function Be(n){var e,t;if(n.debug!==void 0)return n.debug;if(n.platform==="web")return He();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 He(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 Q});var tt=ct(Je(),1);var de="traq_";function le(){return typeof document=="undefined"?void 0:document}function U(n){let e=le();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 ce(n,e,t,i){let s=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",r=i?`; Domain=${i}`:"";return`${n}=${encodeURIComponent(e)}; Max-Age=${Math.floor(t)}; Path=/${r}; SameSite=Lax${s}`}function ze(n){let e=le();if(!e||!n.includes(".")||/^[\d.]+$/.test(n)||n.includes(":"))return null;let t=n.split("."),i=`${de}probe`;for(let s=t.length-2;s>=0;s--){let r=t.slice(s).join(".");if(e.cookie=ce(i,"1",10,r),U(i)==="1")return e.cookie=ce(i,"",0,r),r}return null}function O(n,e,t,i){let s=le();if(s)try{s.cookie=ce(n,e,t,i)}catch{}}function q(n,e){O(n,"",0,e)}var K="traq_device_id",he=new Set([K]),ti=395*24*60*60;function G(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var W=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,s,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=(s=G())==null?void 0:s.getItem(e))!=null?r:null}catch{}return t===null&&this.cookies&&he.has(e)&&(t=U(e)),t}setSync(e,t){if(!this.persistent){this.memory.set(e,t);return}let i=!1;try{let s=G();s&&(s.setItem(e,t),i=!0)}catch{}i||this.memory.set(e,t),this.cookies&&he.has(e)&&O(e,t,ti,this.cookieDomain())}removeSync(e){var t;this.memory.delete(e);try{(t=G())==null||t.removeItem(e)}catch{}this.cookies&&q(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=G(),t=[];try{for(let i=0;e&&i<e.length;i++){let s=e.key(i);s&&s.startsWith(de)&&t.push(s)}}catch{}for(let i of he)t.includes(i)||t.push(i);for(let i of t){let s=this.getSync(i);s!==null&&this.memory.set(i,s)}this.persistent=!1;for(let i of t){try{e==null||e.removeItem(i)}catch{}this.cookies&&q(i,this.cookieDomain())}}};var D=class{constructor(e,t,i,s,r){this.store=e;this.key=t;this.cookieDomain=i;this.cookies=s;this.valid=r}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=U(this.key);if(i&&this.valid(i))return i}return null}set(e,t,i=Date.now()){let s={id:e,exp:i+t};this.store.setSync(this.key,JSON.stringify(s)),this.cookies&&this.store.isPersistent&&O(this.key,e,t/1e3,this.cookieDomain())}clear(){this.store.removeSync(this.key),this.cookies&&q(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&&O(this.key,i.id,(i.exp-e)/1e3,this.cookieDomain())}catch{}}};var ii="traq_src",ni=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","fbclid","ttclid"],si=200,ri={utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid",referrer:"referrer"},ge=n=>{let e=n==null?void 0:n.trim();return e?e.slice(0,si):null},pe=n=>n.toLowerCase().replace(/^www\./,"");function oi(n,e){let t=pe(n),i=pe(e);return t===i||t.endsWith(`.${i}`)||i.endsWith(`.${t}`)}function ai(n,e){if(!n)return null;try{let t=new URL(n);return t.protocol!=="http:"&&t.protocol!=="https:"||oi(new URL(e).hostname,t.hostname)?null:ge(pe(t.hostname))}catch{return null}}function ui(n,e,t){let i=new URLSearchParams;try{let a=new URL(n).searchParams;for(let u of ni){let h=ge(a.get(u));h&&i.set(u,h)}}catch{return null}let s=i.toString()!=="",r=ai(e,n);return r&&i.set("referrer",r),i.toString()===""?null:(i.set("ts",String(t)),{query:i.toString(),fromUrl:s})}function fe(n){let e;try{e=new URLSearchParams(n)}catch{return null}let t={};for(let[s,r]of Object.entries(ri)){let a=ge(e.get(s));a&&(t[r]=a)}if(!Object.keys(t).length)return null;let i=Number(e.get("ts"));return Number.isFinite(i)&&i>0&&(t.landedAt=i),t}var j=class{constructor(e,t,i,s){this.maxAgeMs=t;this.kept=new D(e,ii,i,s,r=>fe(r)!==null)}capture(e,t,i=Date.now()){let s=ui(e,t,i);return!s||!s.fromUrl&&this.kept.get(i)!==null?null:(this.kept.set(s.query,this.maxAgeMs,i),fe(s.query))}get(e=Date.now()){let t=this.kept.get(e);return t===null?null:fe(t)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var ci="traq_click",di="traq_click",Ze=/^[A-Za-z0-9_-]{8,64}$/;function li(n){try{let e=new URL(n).searchParams.get(ci);return e&&Ze.test(e)?e:null}catch{return null}}var $=class{constructor(e,t,i,s){this.maxAgeMs=t;this.kept=new D(e,di,i,s,r=>Ze.test(r))}capture(e,t=Date.now()){let i=li(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 et="traq_session";var hi=[25,50,75,100],fi=[["utm_source","utmSource"],["utm_medium","utmMedium"],["utm_campaign","utmCampaign"],["utm_content","utmContent"],["utm_term","utmTerm"],["gclid","gclid"],["fbclid","fbclid"],["ttclid","ttclid"]];function pi(){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 gi(n,e){var i;let t={};try{let s=new URL(n);for(let[r,a]of fi){let u=(i=s.searchParams.get(r))==null?void 0:i.trim();u&&(t[a]=u.slice(0,200))}if(e){let r=new URL(e);r.hostname.replace(/^www\./,"")!==s.hostname.replace(/^www\./,"")&&(t.referrer=`${r.protocol}//${r.host}/`)}}catch{}return Object.keys(t).length?t:void 0}function X(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 B=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=X(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),s=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:s,keepalive:e}).then(r=>{!r.ok&&(r.status>=500||r.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(et);t=i?JSON.parse(i):null}catch{t=null}!t||typeof t.id!="string"||typeof t.last!="number"||e-t.last>18e5?t={id:pi(),last:e,src:gi(location.href,document.referrer)}:t.last=e;try{this.deps.store.setSync(et,JSON.stringify(t))}catch{}return t}enqueue(e){var s,r;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:(r=(s=e.url)!=null?s:X(location.href))!=null?r:"",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(...s){let r=i.apply(this,s);return e(),r})}window.addEventListener("popstate",e)}onScroll(){var a;if(typeof document.documentElement=="undefined"||!document.documentElement)return;let e=document.documentElement,t=window.innerHeight||e.clientHeight||0,i=Math.max(e.scrollHeight||0,((a=document.body)==null?void 0:a.scrollHeight)||0);if(!i)return;let s=i<=t?1:Math.min(1,((window.scrollY||e.scrollTop||0)+t)/i),r=Math.round(s*100);for(let u of hi)r>=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 s=i,r=(i.tagName==="INPUT"?s.value:i.innerText||i.textContent||"").replace(/\s+/g," ").trim().slice(0,100),a=i.tagName==="A"?X(i.getAttribute("href")):void 0,u={tag:i.tagName.toLowerCase()};r&&(u.text=r),a&&(u.href=a),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:X(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 s=t instanceof Error&&typeof t.stack=="string"?t.stack.slice(0,1500):void 0;this.enqueue({kind:"error",props:{message:i,unhandledRejection:!0,...s?{stack:s}:{}}})}};var mi="https://api.traqio.app",yi=30,vi=1440*60*1e3;function Si(){return typeof window!="undefined"&&typeof document!="undefined"}function _i(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var me=class{constructor(){this.core=new tt.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 C,L,d;if(this.started||!Si())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,i,s=()=>i===void 0?i=ze(location.hostname):i,r=(C=e.consent)!=null?C:this.earlyConsent,a=!this.waitForConsent||r===!0;this.store=new W(a,s,t);let u=((L=e.trackIdDays)!=null?L:yi)*vi;if(this.trackIds=new $(this.store,u,s,t),this.trackIds.capture(location.href),this.sources=new j(this.store,u,s,t),this.sources.capture(location.href,document.referrer),!this.store.getSync(K)){let l=_i();l&&this.store.setSync(K,l)}this.userId=e.userId;let h=((d=e.endpoint)!=null?d:mi).replace(/\/+$/,"");if(await this.core.init({sdkKey:e.sdkKey,endpoint:h,storage:this.store,platform:"web",userId:e.userId,consent:r,debug:e.debug,lifecycle:({background:l,foreground:g})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?l():g()),window.addEventListener("pagehide",l)}}),e.analytics){let l=this.store;this.analytics=new B({store:l,endpoint:h,sdkKey:e.sdkKey,anonymousId:()=>l.getSync(K),userId:()=>this.userId,isDebug:()=>this.core.isDebug,isForgotten:()=>this.core.forgotten,options:e.analytics===!0?{}:e.analytics}),this.analytics.start();for(let[g,m]of this.earlyCaptures)this.analytics.capture(g,m)}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,s;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear(),(i=this.sources)==null||i.clear(),(s=this.analytics)==null||s.stop()),e}flush(){var e;this.core.flush(),(e=this.analytics)==null||e.flush(!1)}get forgotten(){return this.core.forgotten}},ye=new me;window.Traqio=ye;var S=document.currentScript,it=S==null?void 0:S.dataset.sdkKey;it&&ye.init({sdkKey:it,endpoint:(S==null?void 0:S.dataset.endpoint)||void 0,waitForConsent:(S==null?void 0:S.dataset.waitForConsent)==="true",analytics:(S==null?void 0:S.dataset.analytics)==="true"});})();
|
|
2
2
|
//# sourceMappingURL=traqio.min.js.map
|