@traqio/web 0.1.0 → 0.1.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/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/traqio.min.js +1 -1
- package/build/traqio.min.js.map +1 -1
- package/package.json +7 -3
package/build/traqio.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var vt=Object.create;var x=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var _t=(i,t,e)=>()=>{if(e)throw e[0];try{return i&&(t=i(i=0)),t}catch(s){throw e=[s],s}};var k=(i,t)=>()=>{try{return t||i((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}};var $=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of kt(t))!wt.call(i,n)&&n!==e&&x(i,n,{get:()=>t[n],enumerable:!(s=It(t,n))||s.enumerable});return i};var Et=(i,t,e)=>(e=i!=null?vt(St(i)):{},$(t||!i||!i.__esModule?x(e,"default",{value:i,enumerable:!0}):e,i)),C=i=>$(x({},"__esModule",{value:!0}),i);var O=k(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Skan=c.SKAN_STATE_KEY=c.CONVERSION_WINDOWS=void 0;c.windowForAge=H;c.shouldLockWindow=j;c.fineValueForRevenue=X;c.fineValueForEvents=z;c.coarseValueForRevenue=Z;c.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function H(i){let t=c.CONVERSION_WINDOWS.find(e=>i>=e.startHours&&i<e.endHours);return t?t.window:null}function j(i,t){let e=H(t);if(e==null||!i||!i.length)return!1;let s=i.find(n=>n.window===e);return!s||!s.lock?!1:s.lockAfterHours==null?!0:t>=s.lockAfterHours}var At=63,Tt=6;function X(i,t){let e=0;for(let s=0;s<Math.min(t.length,At+1);s++)i>=t[s]&&(e=s);return e}function z(i,t){let e=new Set(i),s=0;return t.slice(0,Tt).forEach((n,r)=>{e.has(n)&&(s|=1<<r)}),s}function Z(i,t){if(!t)return;let e,s=-1/0;for(let n of["low","medium","high"]){let r=t[n];r!=null&&i>=r&&r>=s&&(e=n,s=r)}return e}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(t){this.opts=t,this.enabled=!!t.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(t){!this.enabled||!(t>0)||!Number.isFinite(t)||(this.state.revenue+=t,this.persist(),this.push())}markEvent(t){!this.enabled||this.state.events.includes(t)||(this.state.events.push(t),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var n,r;let t=this.mapping;if(!t||!this.opts.native)return;let e,s;if(t.mode==="events"){if(!((n=t.eventBits)!=null&&n.length))return;e=z(this.state.events,t.eventBits)}else{if(!((r=t.revenueBuckets)!=null&&r.length))return;e=X(this.state.revenue,t.revenueBuckets),s=Z(this.state.revenue,t.coarseRevenue)}this.state.lastFine==null&&e===0||this.state.lastFine!=null&&e<=this.state.lastFine||(this.state.lastFine=e,this.persist(),this.opts.native.updateConversionValue(e,s,this.lockWindowNow()))}lockWindowNow(){var s;let t=this.state.firstSeenAt;if(t==null)return!1;let e=(this.now()-t)/36e5;return j((s=this.mapping)==null?void 0:s.postbackWindows,e)}now(){return this.opts.nowFn?this.opts.nowFn():Date.now()}async fetchMapping(){var e;let t=(e=this.opts.fetchFn)!=null?e:typeof fetch=="function"?fetch:void 0;if(!t)return null;try{let s=await t(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!s.ok)return null;let n=await s.json();return n&&typeof n=="object"?n:null}catch{return null}}async restore(){var t;try{let e=await((t=this.opts.storage)==null?void 0:t.getItem(c.SKAN_STATE_KEY));e&&(this.state={...J,...JSON.parse(e)})}catch{}}async persist(){var t;try{await((t=this.opts.storage)==null?void 0:t.setItem(c.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};c.Skan=R});var M=k(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.ADSERVICES_ATTEMPTS_KEY=d.ADSERVICES_SENT_KEY=void 0;d.reportAdServicesToken=Dt;d.ADSERVICES_SENT_KEY="traq_adservices_sent";d.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var bt=5;async function Dt(i){var s,n;if(!((s=i.native)!=null&&s.getAttributionToken))return"unsupported";if(await G(i,d.ADSERVICES_SENT_KEY))return"already-sent";let t=null;try{t=await i.native.getAttributionToken()}catch{}if(!t||!t.trim()){let r=Number(await G(i,d.ADSERVICES_ATTEMPTS_KEY))||0;return await N(i,d.ADSERVICES_ATTEMPTS_KEY,String(r+1)),r+1>=bt&&await N(i,d.ADSERVICES_SENT_KEY,"1"),"no-token"}let e=(n=i.fetchFn)!=null?n:typeof fetch=="function"?fetch:void 0;if(!e)return"post-failed";try{if(!(await e(`${i.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:i.sdkKey,token:t.trim(),deviceId:i.deviceId,appUserId:i.userId})})).ok)return"post-failed"}catch{return"post-failed"}return await N(i,d.ADSERVICES_SENT_KEY,"1"),"sent"}async function G(i,t){var e,s;try{return(s=await((e=i.storage)==null?void 0:e.getItem(t)))!=null?s:null}catch{return null}}async function N(i,t,e){var s;try{await((s=i.storage)==null?void 0:s.setItem(t,e))}catch{}}});var K=k(S=>{"use strict";Object.defineProperty(S,"__esModule",{value:!0});S.isTrackingUrl=Ct;S.toDeepLink=Rt;var xt=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/;function Ct(i){var e;let t=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(i);return!!(t&&xt.test((e=t[1])!=null?e:""))}function Rt(i,t,e){return!(i!=null&&i.matched)||!i.via?null:{deepLink:i.deepLink,code:i.code,deferred:t,via:i.via,...e?{url:e}:{}}}});var q={};var w=_t(()=>{"use strict"});var lt=k(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.Traqio=o.Client=o.isTrackingUrl=o.reportAdServicesToken=o.Skan=o.SDK_VERSION=void 0;o.normalizeAdvertisingId=dt;o.fromMaxAd=ht;var Ot=O(),Nt=M(),L=K();o.SDK_VERSION="0.1.0";var Mt=O();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return Mt.Skan}});var Kt=M();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return Kt.reportAdServicesToken}});var qt=K();Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return qt.isTrackingUrl}});var F="traq_install_sent",tt="traq_install_attempts",et="traq_referrer",st="traq_queue",it="traq_ad_queue",nt="traq_device_id",rt="traq_last_session",ot="traq_erased",_="traq_deferred_link",at="traq_consent",Lt=20,ct=500,Ft=100,ut=1e3,P=1e3,Pt=300*1e3,Ut=3e3,Vt=3,Qt=1800*1e3,Yt={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"},Wt="00000000-0000-0000-0000-000000000000";function dt(i){if(typeof i!="string")return;let t=i.trim();if(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(t))return t===Wt?void 0:t}function ht(i){var t,e,s;if(typeof i.revenue=="number"&&Number.isFinite(i.revenue)&&i.revenue>=0)return{valueMicros:Math.round(i.revenue*1e6),currency:"USD",precision:(e=Yt[(t=i.revenuePrecision)!=null?t:""])!=null?e:"unknown",adUnitId:i.adUnitId,adFormat:Bt[((s=i.format)!=null?s:"").toUpperCase()],adSourceName:i.networkName,ts:i.ts}}function y(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let t=Math.random()*16|0;return(i==="x"?t:t&3|8).toString(16)})}function $t(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Jt(){var i;try{let t=(w(),C(q)),e=(i=t==null?void 0:t.default)!=null?i:t;if(typeof(e==null?void 0:e.getItem)=="function"&&typeof(e==null?void 0:e.setItem)=="function")return{getItem:s=>e.getItem(s),setItem:(s,n)=>e.setItem(s,n)}}catch{}}var E=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 Ot.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null}async init(t){var e;if(!this.started&&(this.started=!0,this.opts={collectContext:!0,...t,storage:(e=t.storage)!=null?e:Jt()},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."),await this.restoreConsent(t.consent),await this.restoreQueue(),await this.restoreAdQueue(),await this.buildContext(),!await this.restoreErased())){if(!this.isWeb){let s=!!this.opts.storage&&!await this.opts.storage.getItem(F).catch(()=>"1");await this.sendInstallOnce(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(s),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(t,e){var n,r;if(!this.started||this.erased)return;let s=((n=e==null?void 0:e.transactionId)==null?void 0:n.trim())||void 0;this.enqueue({name:t,eventId:y(),value:e==null?void 0:e.value,currency:e==null?void 0:e.currency,...s?{transactionId:s,store:(r=e==null?void 0:e.store)!=null?r:this.defaultStore()}:{}}),this.skan.markEvent(t),e!=null&&e.value&&this.skan.addRevenue(e.value)}defaultStore(){var e;let t=(e=this.opts.native)==null?void 0:e.platform;return t==="ios"?"app_store":t==="android"?"play_store":void 0}trackAdRevenue(t){this.queueAdRevenue(t,"admob")}trackMaxAdRevenue(t){let e=ht(t);e&&this.queueAdRevenue(e,"applovin_max")}queueAdRevenue(t,e){var s;!this.started||this.erased||!(t.valueMicros>=0)||!t.currency||(this.adQueue.push({...t,source:e,impressionId:y(),ts:(s=t.ts)!=null?s:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(t.valueMicros/1e6),this.adQueue.length>ut&&this.adQueue.splice(0,this.adQueue.length-ut),this.persistAdQueue(),this.scheduleFlush())}getInstallReferrer(){return this.started?this.readReferrer():Promise.resolve({status:"unavailable",retryable:!1})}onDeepLink(t){this.deepLinkListeners.add(t);let e=this.undelivered.splice(0);for(let s of e)t(s);return()=>{this.deepLinkListeners.delete(t)}}async handleUrl(t){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,L.isTrackingUrl)(t))return null;let e=await this.postJson({url:t},"/deeplink/open"),s=(0,L.toDeepLink)(e,!1,t);return s&&this.emitDeepLink(s),s}getDeferredDeepLink(){var t;return(t=this.deferred)!=null?t:Promise.resolve(null)}async forgetMe(){return this.started?this.erased?!0:await this.post({deviceId:this.context.deviceId,appUserId:this.opts.userId},"/privacy/forget")?(await this.markErased(),!0):!1:!1}async setConsent(t){var e,s;this.consent=t?"granted":"denied",await((s=(e=this.opts)==null?void 0:e.storage)==null?void 0:s.setItem(at,this.consent).catch(()=>{}))}get forgotten(){return this.erased}setUserId(t){this.opts&&(this.opts.userId=t)}flush(){this.erased||(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.drain())}appOpened(){!this.started||this.erased||this.maybeStartSession()}get skanMapping(){return this.skan.activeMapping}async initAppleAds(){if(this.opts.appleAds===!1)return;let t=this.opts.native;(t==null?void 0:t.platform)!=="ios"||!t.getAttributionToken||await(0,Nt.reportAdServicesToken)({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,deviceId:this.context.deviceId,userId:this.opts.userId,storage:this.opts.storage,native:{getAttributionToken:()=>t.getAttributionToken()}})}async initSkan(){if(this.opts.skan===!1)return;let t=this.opts.native;(t==null?void 0:t.platform)!=="ios"||!t.updateConversionValue||await this.skan.init({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,storage:this.opts.storage,native:{updateConversionValue:(e,s,n)=>{var r;return(r=t.updateConversionValue)==null?void 0:r.call(t,e,s,n)}}})}async resolveDeferredOnce(t){var a,l;let e=this.opts.storage;try{let g=await(e==null?void 0:e.getItem(_));if(g)return JSON.parse(g)}catch{}if(!t&&!await(e==null?void 0:e.getItem(`${_}_pending`).catch(()=>null)))return null;let s=(l=(a=this.opts.native)==null?void 0:a.platform)!=null?l:"android",n=s==="android"?await this.readReferrer():null;await(e==null?void 0:e.setItem(`${_}_pending`,"1").catch(()=>{}));let r=await this.postJson({platform:s,installReferrer:n==null?void 0:n.referrer},"/deeplink/deferred");if(!r)return null;let u=(0,L.toDeepLink)(r,!0);try{await(e==null?void 0:e.setItem(_,JSON.stringify(u)))}catch{}return u&&this.emitDeepLink(u),u}emitDeepLink(t){if(!this.deepLinkListeners.size){this.undelivered.push(t);return}for(let e of this.deepLinkListeners)try{e(t)}catch{}}wireDeepLinks(){try{let{Linking:t}=(w(),C(q));if(!t)return;t.getInitialURL().then(e=>e&&this.handleUrl(e)).catch(()=>{}),t.addEventListener("url",({url:e})=>{this.handleUrl(e)})}catch{}}get isWeb(){var t;return((t=this.opts)==null?void 0:t.platform)==="web"}wireLifecycle(){let t={background:()=>this.flush(),foreground:()=>this.appOpened()};if(this.opts.lifecycle){this.opts.lifecycle(t);return}try{let{AppState:e}=(w(),C(q));e.addEventListener("change",s=>{if(s!=="active"){this.scheduleFlush(0);return}this.maybeStartSession()})}catch{}}async restoreErased(){var t;try{this.erased=await((t=this.opts.storage)==null?void 0:t.getItem(ot))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var t;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,await this.persistQueue(),await this.persistAdQueue();try{await((t=this.opts.storage)==null?void 0:t.setItem(ot,"1"))}catch{}}enqueue(t){this.queue.push(t),this.queue.length>ct&&this.queue.splice(0,this.queue.length-ct),this.persistQueue(),this.scheduleFlush()}async restoreQueue(){var t;try{let e=await((t=this.opts.storage)==null?void 0:t.getItem(st));e&&(this.queue=JSON.parse(e))}catch{}}async persistQueue(){var t;try{await((t=this.opts.storage)==null?void 0:t.setItem(st,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var t,e,s;try{let n=await((t=this.opts.storage)==null?void 0:t.getItem(it));if(!n)return;let r=JSON.parse(n);this.adQueue=(e=r.items)!=null?e:[],this.adBatchId=(s=r.batchId)!=null?s:null}catch{}}async persistAdQueue(){var t;try{let e={batchId:this.adBatchId,items:this.adQueue};await((t=this.opts.storage)==null?void 0:t.setItem(it,JSON.stringify(e)))}catch{}}async maybeStartSession(t=!1){var r,u,a;if(this.erased)return;let e=Date.now();if(!t){let l=Number(await((r=this.opts.storage)==null?void 0:r.getItem(rt).catch(()=>null)))||0;if(l&&e-l<Qt)return}let s=(u=this.context.deviceId)!=null?u:await this.getOrCreateDeviceId();if(await this.post({deviceId:s,appUserId:this.opts.userId,sessionId:y(),ts:Math.floor(e/1e3),context:this.context},"/ingest/session"))try{await((a=this.opts.storage)==null?void 0:a.setItem(rt,String(e)))}catch{}}async buildContext(){var e,s,n;if(!this.opts.collectContext){this.context={sdkVersion:o.SDK_VERSION};return}let t={};try{t=(n=await((s=(e=this.opts.native)==null?void 0:e.getContext)==null?void 0:s.call(e)))!=null?n:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:t.deviceModel,osVersion:t.osVersion,appVersion:this.opts.appVersion,locale:$t(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var e,s;try{let n=await((e=this.opts.storage)==null?void 0:e.getItem(nt));if(n)return n}catch{}let t=y();try{await((s=this.opts.storage)==null?void 0:s.setItem(nt,t))}catch{}return t}async readReferrer(){var s,n;if(this.referrer)return this.referrer;try{let r=await((s=this.opts.storage)==null?void 0:s.getItem(et));if(r)return this.referrer=JSON.parse(r)}catch{}let t=this.opts.native;if((t==null?void 0:t.platform)!=="android")return{status:t?"not_supported_platform":"unavailable",retryable:!1};let e=await t.getInstallReferrer().catch(()=>({status:"error",retryable:!0}));if(!e.retryable){this.referrer=e;try{await((n=this.opts.storage)==null?void 0:n.setItem(et,JSON.stringify(e)))}catch{}}return e}async readAdvertisingId(){var t;if(!(!this.opts.collectAdvertisingId||!((t=this.opts.native)!=null&&t.getAdvertisingId)))try{return dt(await this.opts.native.getAdvertisingId())}catch{return}}async sendInstallOnce(){var r,u;let t=this.opts.storage;if(t&&await t.getItem(F))return;let e=(u=(r=this.opts.native)==null?void 0:r.platform)!=null?u:"android",s=await this.readReferrer();if(s.retryable&&t){let a=Number(await t.getItem(tt))||0;if(a+1<Vt){await t.setItem(tt,String(a+1));return}}await this.post({install:{platform:e,installReferrer:s.referrer,appUserId:this.opts.userId,advertisingId:await this.readAdvertisingId(),context:this.context}})&&await(t==null?void 0:t.setItem(F,"1"))}scheduleFlush(t=Ut){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},t))}async drain(){var t;if(!this.erased&&!(this.flushing||!this.queue.length&&!this.adQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let e=this.queue.slice(0,Lt);if(!await this.post({events:e,appUserId:this.opts.userId,deviceId:this.context.deviceId}))return this.backOff();this.queue.splice(0,e.length),await this.persistQueue(),this.retryMs=P}for(;this.adQueue.length;){let e=(t=this.adQueue[0].source)!=null?t:"admob",s=this.adQueue.findIndex(u=>{var a;return((a=u.source)!=null?a:"admob")!==e}),n=this.adQueue.slice(0,Math.min(Ft,s===-1?this.adQueue.length:s));if(this.adBatchId||(this.adBatchId=y(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:e,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:n.map(({source:u,...a})=>a)},"/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,Pt),this.scheduleFlush(this.retryMs)}async postJson(t,e){try{let s=await fetch(`${this.opts.endpoint}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...t}),...this.keepalive()});return s.ok?await s.json():null}catch{return null}}async restoreConsent(t){var s;if(t!==void 0)return this.setConsent(t);if(this.consent)return this.setConsent(this.consent==="granted");let e=await((s=this.opts.storage)==null?void 0:s.getItem(at).catch(()=>null));(e==="granted"||e==="denied")&&(this.consent=e)}keepalive(){return this.isWeb?{keepalive:!0}:{}}async post(t,e="/ingest"){let s=this.consent&&(e==="/ingest"||e==="/ingest/session")?{consent:this.consent}:{};try{return(await fetch(`${this.opts.endpoint}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...t,...s}),...this.keepalive()})).ok}catch{return!1}}};o.Client=E;o.Traqio=new E});var gt=Et(lt(),1);var V="traq_";function Q(){return typeof document=="undefined"?void 0:document}function v(i){let t=Q();if(!t)return null;for(let e of t.cookie?t.cookie.split(";"):[]){let s=e.indexOf("=");if(!(s<0)&&e.slice(0,s).trim()===i)try{return decodeURIComponent(e.slice(s+1).trim())}catch{return null}}return null}function U(i,t,e,s){let n=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",r=s?`; Domain=${s}`:"";return`${i}=${encodeURIComponent(t)}; Max-Age=${Math.floor(e)}; Path=/${r}; SameSite=Lax${n}`}function ft(i){let t=Q();if(!t||!i.includes(".")||/^[\d.]+$/.test(i)||i.includes(":"))return null;let e=i.split("."),s=`${V}probe`;for(let n=e.length-2;n>=0;n--){let r=e.slice(n).join(".");if(t.cookie=U(s,"1",10,r),v(s)==="1")return t.cookie=U(s,"",0,r),r}return null}function p(i,t,e,s){let n=Q();if(n)try{n.cookie=U(i,t,e,s)}catch{}}function I(i,t){p(i,"",0,t)}var b="traq_device_id",Y=new Set([b]),Ht=395*24*60*60;function A(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var T=class{constructor(t,e,s){this.persistent=t;this.cookieDomain=e;this.cookies=s;this.memory=new Map}get isPersistent(){return this.persistent}async getItem(t){return this.getSync(t)}async setItem(t,e){this.setSync(t,e)}getSync(t){var s,n,r;if(this.memory.has(t))return(s=this.memory.get(t))!=null?s:null;if(!this.persistent)return null;let e=null;try{e=(r=(n=A())==null?void 0:n.getItem(t))!=null?r:null}catch{}return e===null&&this.cookies&&Y.has(t)&&(e=v(t)),e}setSync(t,e){if(!this.persistent){this.memory.set(t,e);return}let s=!1;try{let n=A();n&&(n.setItem(t,e),s=!0)}catch{}s||this.memory.set(t,e),this.cookies&&Y.has(t)&&p(t,e,Ht,this.cookieDomain())}removeSync(t){var e;this.memory.delete(t);try{(e=A())==null||e.removeItem(t)}catch{}this.cookies&&I(t,this.cookieDomain())}enable(){if(this.persistent)return;this.persistent=!0;let t=[...this.memory];this.memory.clear();for(let[e,s]of t)this.setSync(e,s)}disable(){if(!this.persistent)return;let t=A(),e=[];try{for(let s=0;t&&s<t.length;s++){let n=t.key(s);n&&n.startsWith(V)&&e.push(n)}}catch{}for(let s of Y)e.includes(s)||e.push(s);for(let s of e){let n=this.getSync(s);n!==null&&this.memory.set(s,n)}this.persistent=!1;for(let s of e){try{t==null||t.removeItem(s)}catch{}this.cookies&&I(s,this.cookieDomain())}}};var jt="traq_click",f="traq_click",pt=/^[A-Za-z0-9_-]{8,64}$/;function Xt(i){try{let t=new URL(i).searchParams.get(jt);return t&&pt.test(t)?t:null}catch{return null}}var D=class{constructor(t,e,s,n){this.store=t;this.maxAgeMs=e;this.cookieDomain=s;this.cookies=n}capture(t,e=Date.now()){let s=Xt(t);return s&&this.write(s,e),s}get(t=Date.now()){let e=this.store.getSync(f);if(e)try{let s=JSON.parse(e);if(s&&typeof s.id=="string"&&s.exp>t)return s.id}catch{}if(this.cookies&&this.store.isPersistent){let s=v(f);if(s&&pt.test(s))return s}return null}clear(){this.store.removeSync(f),this.cookies&&I(f,this.cookieDomain())}persistCookie(t=Date.now()){let e=this.store.getSync(f);if(!(!e||!this.cookies||!this.store.isPersistent))try{let s=JSON.parse(e);s.exp>t&&p(f,s.id,(s.exp-t)/1e3,this.cookieDomain())}catch{}}write(t,e){let s={id:t,exp:e+this.maxAgeMs};this.store.setSync(f,JSON.stringify(s)),this.cookies&&this.store.isPersistent&&p(f,t,this.maxAgeMs/1e3,this.cookieDomain())}};var zt="https://api.traqio.app",Zt=30,Gt=1440*60*1e3;function te(){return typeof window!="undefined"&&typeof document!="undefined"}function ee(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var B=class{constructor(){this.core=new gt.Client;this.store=null;this.trackIds=null;this.waitForConsent=!1;this.started=!1}async init(t){var a,l,g;if(this.started||!te())return;this.started=!0,this.waitForConsent=t.waitForConsent===!0;let e=t.cookies!==!1,s,n=()=>s===void 0?s=ft(location.hostname):s,r=(a=t.consent)!=null?a:this.earlyConsent,u=!this.waitForConsent||r===!0;if(this.store=new T(u,n,e),this.trackIds=new D(this.store,((l=t.trackIdDays)!=null?l:Zt)*Gt,n,e),this.trackIds.capture(location.href),!this.store.getSync(b)){let m=ee();m&&this.store.setSync(b,m)}await this.core.init({sdkKey:t.sdkKey,endpoint:((g=t.endpoint)!=null?g:zt).replace(/\/+$/,""),storage:this.store,platform:"web",userId:t.userId,consent:r,lifecycle:({background:m,foreground:yt})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?m():yt()),window.addEventListener("pagehide",m)}})}track(t,e){this.core.track(t,e)}setUserId(t){this.core.setUserId(t)}async setConsent(t){var e;this.started||(this.earlyConsent=t),this.store&&this.waitForConsent&&(t?(this.store.enable(),(e=this.trackIds)==null||e.persistCookie()):this.store.disable()),await this.core.setConsent(t)}getTrackId(){var t,e;return(e=(t=this.trackIds)==null?void 0:t.get())!=null?e:null}async forgetMe(){var e;let t=await this.core.forgetMe();return t&&((e=this.trackIds)==null||e.clear()),t}flush(){this.core.flush()}get forgotten(){return this.core.forgotten}},W=new B;window.Traqio=W;var h=document.currentScript,mt=h==null?void 0:h.dataset.sdkKey;mt&&W.init({sdkKey:mt,endpoint:(h==null?void 0:h.dataset.endpoint)||void 0,waitForConsent:(h==null?void 0:h.dataset.waitForConsent)==="true"});})();
|
|
1
|
+
"use strict";(()=>{var vt=Object.create;var x=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var _t=(i,t,e)=>()=>{if(e)throw e[0];try{return i&&(t=i(i=0)),t}catch(s){throw e=[s],s}};var k=(i,t)=>()=>{try{return t||i((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}};var $=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of kt(t))!wt.call(i,n)&&n!==e&&x(i,n,{get:()=>t[n],enumerable:!(s=It(t,n))||s.enumerable});return i};var Et=(i,t,e)=>(e=i!=null?vt(St(i)):{},$(t||!i||!i.__esModule?x(e,"default",{value:i,enumerable:!0}):e,i)),C=i=>$(x({},"__esModule",{value:!0}),i);var O=k(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Skan=c.SKAN_STATE_KEY=c.CONVERSION_WINDOWS=void 0;c.windowForAge=H;c.shouldLockWindow=j;c.fineValueForRevenue=X;c.fineValueForEvents=z;c.coarseValueForRevenue=Z;c.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function H(i){let t=c.CONVERSION_WINDOWS.find(e=>i>=e.startHours&&i<e.endHours);return t?t.window:null}function j(i,t){let e=H(t);if(e==null||!i||!i.length)return!1;let s=i.find(n=>n.window===e);return!s||!s.lock?!1:s.lockAfterHours==null?!0:t>=s.lockAfterHours}var At=63,Tt=6;function X(i,t){let e=0;for(let s=0;s<Math.min(t.length,At+1);s++)i>=t[s]&&(e=s);return e}function z(i,t){let e=new Set(i),s=0;return t.slice(0,Tt).forEach((n,r)=>{e.has(n)&&(s|=1<<r)}),s}function Z(i,t){if(!t)return;let e,s=-1/0;for(let n of["low","medium","high"]){let r=t[n];r!=null&&i>=r&&r>=s&&(e=n,s=r)}return e}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(t){this.opts=t,this.enabled=!!t.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(t){!this.enabled||!(t>0)||!Number.isFinite(t)||(this.state.revenue+=t,this.persist(),this.push())}markEvent(t){!this.enabled||this.state.events.includes(t)||(this.state.events.push(t),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var n,r;let t=this.mapping;if(!t||!this.opts.native)return;let e,s;if(t.mode==="events"){if(!((n=t.eventBits)!=null&&n.length))return;e=z(this.state.events,t.eventBits)}else{if(!((r=t.revenueBuckets)!=null&&r.length))return;e=X(this.state.revenue,t.revenueBuckets),s=Z(this.state.revenue,t.coarseRevenue)}this.state.lastFine==null&&e===0||this.state.lastFine!=null&&e<=this.state.lastFine||(this.state.lastFine=e,this.persist(),this.opts.native.updateConversionValue(e,s,this.lockWindowNow()))}lockWindowNow(){var s;let t=this.state.firstSeenAt;if(t==null)return!1;let e=(this.now()-t)/36e5;return j((s=this.mapping)==null?void 0:s.postbackWindows,e)}now(){return this.opts.nowFn?this.opts.nowFn():Date.now()}async fetchMapping(){var e;let t=(e=this.opts.fetchFn)!=null?e:typeof fetch=="function"?fetch:void 0;if(!t)return null;try{let s=await t(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!s.ok)return null;let n=await s.json();return n&&typeof n=="object"?n:null}catch{return null}}async restore(){var t;try{let e=await((t=this.opts.storage)==null?void 0:t.getItem(c.SKAN_STATE_KEY));e&&(this.state={...J,...JSON.parse(e)})}catch{}}async persist(){var t;try{await((t=this.opts.storage)==null?void 0:t.setItem(c.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};c.Skan=R});var M=k(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.ADSERVICES_ATTEMPTS_KEY=d.ADSERVICES_SENT_KEY=void 0;d.reportAdServicesToken=Dt;d.ADSERVICES_SENT_KEY="traq_adservices_sent";d.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var bt=5;async function Dt(i){var s,n;if(!((s=i.native)!=null&&s.getAttributionToken))return"unsupported";if(await G(i,d.ADSERVICES_SENT_KEY))return"already-sent";let t=null;try{t=await i.native.getAttributionToken()}catch{}if(!t||!t.trim()){let r=Number(await G(i,d.ADSERVICES_ATTEMPTS_KEY))||0;return await N(i,d.ADSERVICES_ATTEMPTS_KEY,String(r+1)),r+1>=bt&&await N(i,d.ADSERVICES_SENT_KEY,"1"),"no-token"}let e=(n=i.fetchFn)!=null?n:typeof fetch=="function"?fetch:void 0;if(!e)return"post-failed";try{if(!(await e(`${i.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:i.sdkKey,token:t.trim(),deviceId:i.deviceId,appUserId:i.userId})})).ok)return"post-failed"}catch{return"post-failed"}return await N(i,d.ADSERVICES_SENT_KEY,"1"),"sent"}async function G(i,t){var e,s;try{return(s=await((e=i.storage)==null?void 0:e.getItem(t)))!=null?s:null}catch{return null}}async function N(i,t,e){var s;try{await((s=i.storage)==null?void 0:s.setItem(t,e))}catch{}}});var K=k(S=>{"use strict";Object.defineProperty(S,"__esModule",{value:!0});S.isTrackingUrl=Ct;S.toDeepLink=Rt;var xt=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/;function Ct(i){var e;let t=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(i);return!!(t&&xt.test((e=t[1])!=null?e:""))}function Rt(i,t,e){return!(i!=null&&i.matched)||!i.via?null:{deepLink:i.deepLink,code:i.code,deferred:t,via:i.via,...e?{url:e}:{}}}});var q={};var w=_t(()=>{"use strict"});var lt=k(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.Traqio=o.Client=o.isTrackingUrl=o.reportAdServicesToken=o.Skan=o.SDK_VERSION=void 0;o.normalizeAdvertisingId=dt;o.fromMaxAd=ht;var Ot=O(),Nt=M(),L=K();o.SDK_VERSION="0.1.1";var Mt=O();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return Mt.Skan}});var Kt=M();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return Kt.reportAdServicesToken}});var qt=K();Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return qt.isTrackingUrl}});var F="traq_install_sent",tt="traq_install_attempts",et="traq_referrer",st="traq_queue",it="traq_ad_queue",nt="traq_device_id",rt="traq_last_session",ot="traq_erased",_="traq_deferred_link",at="traq_consent",Lt=20,ct=500,Ft=100,ut=1e3,P=1e3,Pt=300*1e3,Ut=3e3,Vt=3,Qt=1800*1e3,Yt={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"},Wt="00000000-0000-0000-0000-000000000000";function dt(i){if(typeof i!="string")return;let t=i.trim();if(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(t))return t===Wt?void 0:t}function ht(i){var t,e,s;if(typeof i.revenue=="number"&&Number.isFinite(i.revenue)&&i.revenue>=0)return{valueMicros:Math.round(i.revenue*1e6),currency:"USD",precision:(e=Yt[(t=i.revenuePrecision)!=null?t:""])!=null?e:"unknown",adUnitId:i.adUnitId,adFormat:Bt[((s=i.format)!=null?s:"").toUpperCase()],adSourceName:i.networkName,ts:i.ts}}function y(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let t=Math.random()*16|0;return(i==="x"?t:t&3|8).toString(16)})}function $t(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Jt(){var i;try{let t=(w(),C(q)),e=(i=t==null?void 0:t.default)!=null?i:t;if(typeof(e==null?void 0:e.getItem)=="function"&&typeof(e==null?void 0:e.setItem)=="function")return{getItem:s=>e.getItem(s),setItem:(s,n)=>e.setItem(s,n)}}catch{}}var E=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 Ot.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null}async init(t){var e;if(!this.started&&(this.started=!0,this.opts={collectContext:!0,...t,storage:(e=t.storage)!=null?e:Jt()},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."),await this.restoreConsent(t.consent),await this.restoreQueue(),await this.restoreAdQueue(),await this.buildContext(),!await this.restoreErased())){if(!this.isWeb){let s=!!this.opts.storage&&!await this.opts.storage.getItem(F).catch(()=>"1");await this.sendInstallOnce(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(s),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(t,e){var n,r;if(!this.started||this.erased)return;let s=((n=e==null?void 0:e.transactionId)==null?void 0:n.trim())||void 0;this.enqueue({name:t,eventId:y(),value:e==null?void 0:e.value,currency:e==null?void 0:e.currency,...s?{transactionId:s,store:(r=e==null?void 0:e.store)!=null?r:this.defaultStore()}:{}}),this.skan.markEvent(t),e!=null&&e.value&&this.skan.addRevenue(e.value)}defaultStore(){var e;let t=(e=this.opts.native)==null?void 0:e.platform;return t==="ios"?"app_store":t==="android"?"play_store":void 0}trackAdRevenue(t){this.queueAdRevenue(t,"admob")}trackMaxAdRevenue(t){let e=ht(t);e&&this.queueAdRevenue(e,"applovin_max")}queueAdRevenue(t,e){var s;!this.started||this.erased||!(t.valueMicros>=0)||!t.currency||(this.adQueue.push({...t,source:e,impressionId:y(),ts:(s=t.ts)!=null?s:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(t.valueMicros/1e6),this.adQueue.length>ut&&this.adQueue.splice(0,this.adQueue.length-ut),this.persistAdQueue(),this.scheduleFlush())}getInstallReferrer(){return this.started?this.readReferrer():Promise.resolve({status:"unavailable",retryable:!1})}onDeepLink(t){this.deepLinkListeners.add(t);let e=this.undelivered.splice(0);for(let s of e)t(s);return()=>{this.deepLinkListeners.delete(t)}}async handleUrl(t){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,L.isTrackingUrl)(t))return null;let e=await this.postJson({url:t},"/deeplink/open"),s=(0,L.toDeepLink)(e,!1,t);return s&&this.emitDeepLink(s),s}getDeferredDeepLink(){var t;return(t=this.deferred)!=null?t:Promise.resolve(null)}async forgetMe(){return this.started?this.erased?!0:await this.post({deviceId:this.context.deviceId,appUserId:this.opts.userId},"/privacy/forget")?(await this.markErased(),!0):!1:!1}async setConsent(t){var e,s;this.consent=t?"granted":"denied",await((s=(e=this.opts)==null?void 0:e.storage)==null?void 0:s.setItem(at,this.consent).catch(()=>{}))}get forgotten(){return this.erased}setUserId(t){this.opts&&(this.opts.userId=t)}flush(){this.erased||(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.drain())}appOpened(){!this.started||this.erased||this.maybeStartSession()}get skanMapping(){return this.skan.activeMapping}async initAppleAds(){if(this.opts.appleAds===!1)return;let t=this.opts.native;(t==null?void 0:t.platform)!=="ios"||!t.getAttributionToken||await(0,Nt.reportAdServicesToken)({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,deviceId:this.context.deviceId,userId:this.opts.userId,storage:this.opts.storage,native:{getAttributionToken:()=>t.getAttributionToken()}})}async initSkan(){if(this.opts.skan===!1)return;let t=this.opts.native;(t==null?void 0:t.platform)!=="ios"||!t.updateConversionValue||await this.skan.init({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,storage:this.opts.storage,native:{updateConversionValue:(e,s,n)=>{var r;return(r=t.updateConversionValue)==null?void 0:r.call(t,e,s,n)}}})}async resolveDeferredOnce(t){var a,l;let e=this.opts.storage;try{let g=await(e==null?void 0:e.getItem(_));if(g)return JSON.parse(g)}catch{}if(!t&&!await(e==null?void 0:e.getItem(`${_}_pending`).catch(()=>null)))return null;let s=(l=(a=this.opts.native)==null?void 0:a.platform)!=null?l:"android",n=s==="android"?await this.readReferrer():null;await(e==null?void 0:e.setItem(`${_}_pending`,"1").catch(()=>{}));let r=await this.postJson({platform:s,installReferrer:n==null?void 0:n.referrer},"/deeplink/deferred");if(!r)return null;let u=(0,L.toDeepLink)(r,!0);try{await(e==null?void 0:e.setItem(_,JSON.stringify(u)))}catch{}return u&&this.emitDeepLink(u),u}emitDeepLink(t){if(!this.deepLinkListeners.size){this.undelivered.push(t);return}for(let e of this.deepLinkListeners)try{e(t)}catch{}}wireDeepLinks(){try{let{Linking:t}=(w(),C(q));if(!t)return;t.getInitialURL().then(e=>e&&this.handleUrl(e)).catch(()=>{}),t.addEventListener("url",({url:e})=>{this.handleUrl(e)})}catch{}}get isWeb(){var t;return((t=this.opts)==null?void 0:t.platform)==="web"}wireLifecycle(){let t={background:()=>this.flush(),foreground:()=>this.appOpened()};if(this.opts.lifecycle){this.opts.lifecycle(t);return}try{let{AppState:e}=(w(),C(q));e.addEventListener("change",s=>{if(s!=="active"){this.scheduleFlush(0);return}this.maybeStartSession()})}catch{}}async restoreErased(){var t;try{this.erased=await((t=this.opts.storage)==null?void 0:t.getItem(ot))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var t;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,await this.persistQueue(),await this.persistAdQueue();try{await((t=this.opts.storage)==null?void 0:t.setItem(ot,"1"))}catch{}}enqueue(t){this.queue.push(t),this.queue.length>ct&&this.queue.splice(0,this.queue.length-ct),this.persistQueue(),this.scheduleFlush()}async restoreQueue(){var t;try{let e=await((t=this.opts.storage)==null?void 0:t.getItem(st));e&&(this.queue=JSON.parse(e))}catch{}}async persistQueue(){var t;try{await((t=this.opts.storage)==null?void 0:t.setItem(st,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var t,e,s;try{let n=await((t=this.opts.storage)==null?void 0:t.getItem(it));if(!n)return;let r=JSON.parse(n);this.adQueue=(e=r.items)!=null?e:[],this.adBatchId=(s=r.batchId)!=null?s:null}catch{}}async persistAdQueue(){var t;try{let e={batchId:this.adBatchId,items:this.adQueue};await((t=this.opts.storage)==null?void 0:t.setItem(it,JSON.stringify(e)))}catch{}}async maybeStartSession(t=!1){var r,u,a;if(this.erased)return;let e=Date.now();if(!t){let l=Number(await((r=this.opts.storage)==null?void 0:r.getItem(rt).catch(()=>null)))||0;if(l&&e-l<Qt)return}let s=(u=this.context.deviceId)!=null?u:await this.getOrCreateDeviceId();if(await this.post({deviceId:s,appUserId:this.opts.userId,sessionId:y(),ts:Math.floor(e/1e3),context:this.context},"/ingest/session"))try{await((a=this.opts.storage)==null?void 0:a.setItem(rt,String(e)))}catch{}}async buildContext(){var e,s,n;if(!this.opts.collectContext){this.context={sdkVersion:o.SDK_VERSION};return}let t={};try{t=(n=await((s=(e=this.opts.native)==null?void 0:e.getContext)==null?void 0:s.call(e)))!=null?n:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:t.deviceModel,osVersion:t.osVersion,appVersion:this.opts.appVersion,locale:$t(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var e,s;try{let n=await((e=this.opts.storage)==null?void 0:e.getItem(nt));if(n)return n}catch{}let t=y();try{await((s=this.opts.storage)==null?void 0:s.setItem(nt,t))}catch{}return t}async readReferrer(){var s,n;if(this.referrer)return this.referrer;try{let r=await((s=this.opts.storage)==null?void 0:s.getItem(et));if(r)return this.referrer=JSON.parse(r)}catch{}let t=this.opts.native;if((t==null?void 0:t.platform)!=="android")return{status:t?"not_supported_platform":"unavailable",retryable:!1};let e=await t.getInstallReferrer().catch(()=>({status:"error",retryable:!0}));if(!e.retryable){this.referrer=e;try{await((n=this.opts.storage)==null?void 0:n.setItem(et,JSON.stringify(e)))}catch{}}return e}async readAdvertisingId(){var t;if(!(!this.opts.collectAdvertisingId||!((t=this.opts.native)!=null&&t.getAdvertisingId)))try{return dt(await this.opts.native.getAdvertisingId())}catch{return}}async sendInstallOnce(){var r,u;let t=this.opts.storage;if(t&&await t.getItem(F))return;let e=(u=(r=this.opts.native)==null?void 0:r.platform)!=null?u:"android",s=await this.readReferrer();if(s.retryable&&t){let a=Number(await t.getItem(tt))||0;if(a+1<Vt){await t.setItem(tt,String(a+1));return}}await this.post({install:{platform:e,installReferrer:s.referrer,appUserId:this.opts.userId,advertisingId:await this.readAdvertisingId(),context:this.context}})&&await(t==null?void 0:t.setItem(F,"1"))}scheduleFlush(t=Ut){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},t))}async drain(){var t;if(!this.erased&&!(this.flushing||!this.queue.length&&!this.adQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let e=this.queue.slice(0,Lt);if(!await this.post({events:e,appUserId:this.opts.userId,deviceId:this.context.deviceId}))return this.backOff();this.queue.splice(0,e.length),await this.persistQueue(),this.retryMs=P}for(;this.adQueue.length;){let e=(t=this.adQueue[0].source)!=null?t:"admob",s=this.adQueue.findIndex(u=>{var a;return((a=u.source)!=null?a:"admob")!==e}),n=this.adQueue.slice(0,Math.min(Ft,s===-1?this.adQueue.length:s));if(this.adBatchId||(this.adBatchId=y(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:e,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:n.map(({source:u,...a})=>a)},"/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,Pt),this.scheduleFlush(this.retryMs)}async postJson(t,e){try{let s=await fetch(`${this.opts.endpoint}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...t}),...this.keepalive()});return s.ok?await s.json():null}catch{return null}}async restoreConsent(t){var s;if(t!==void 0)return this.setConsent(t);if(this.consent)return this.setConsent(this.consent==="granted");let e=await((s=this.opts.storage)==null?void 0:s.getItem(at).catch(()=>null));(e==="granted"||e==="denied")&&(this.consent=e)}keepalive(){return this.isWeb?{keepalive:!0}:{}}async post(t,e="/ingest"){let s=this.consent&&(e==="/ingest"||e==="/ingest/session")?{consent:this.consent}:{};try{return(await fetch(`${this.opts.endpoint}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...t,...s}),...this.keepalive()})).ok}catch{return!1}}};o.Client=E;o.Traqio=new E});var gt=Et(lt(),1);var V="traq_";function Q(){return typeof document=="undefined"?void 0:document}function v(i){let t=Q();if(!t)return null;for(let e of t.cookie?t.cookie.split(";"):[]){let s=e.indexOf("=");if(!(s<0)&&e.slice(0,s).trim()===i)try{return decodeURIComponent(e.slice(s+1).trim())}catch{return null}}return null}function U(i,t,e,s){let n=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",r=s?`; Domain=${s}`:"";return`${i}=${encodeURIComponent(t)}; Max-Age=${Math.floor(e)}; Path=/${r}; SameSite=Lax${n}`}function ft(i){let t=Q();if(!t||!i.includes(".")||/^[\d.]+$/.test(i)||i.includes(":"))return null;let e=i.split("."),s=`${V}probe`;for(let n=e.length-2;n>=0;n--){let r=e.slice(n).join(".");if(t.cookie=U(s,"1",10,r),v(s)==="1")return t.cookie=U(s,"",0,r),r}return null}function p(i,t,e,s){let n=Q();if(n)try{n.cookie=U(i,t,e,s)}catch{}}function I(i,t){p(i,"",0,t)}var b="traq_device_id",Y=new Set([b]),Ht=395*24*60*60;function A(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var T=class{constructor(t,e,s){this.persistent=t;this.cookieDomain=e;this.cookies=s;this.memory=new Map}get isPersistent(){return this.persistent}async getItem(t){return this.getSync(t)}async setItem(t,e){this.setSync(t,e)}getSync(t){var s,n,r;if(this.memory.has(t))return(s=this.memory.get(t))!=null?s:null;if(!this.persistent)return null;let e=null;try{e=(r=(n=A())==null?void 0:n.getItem(t))!=null?r:null}catch{}return e===null&&this.cookies&&Y.has(t)&&(e=v(t)),e}setSync(t,e){if(!this.persistent){this.memory.set(t,e);return}let s=!1;try{let n=A();n&&(n.setItem(t,e),s=!0)}catch{}s||this.memory.set(t,e),this.cookies&&Y.has(t)&&p(t,e,Ht,this.cookieDomain())}removeSync(t){var e;this.memory.delete(t);try{(e=A())==null||e.removeItem(t)}catch{}this.cookies&&I(t,this.cookieDomain())}enable(){if(this.persistent)return;this.persistent=!0;let t=[...this.memory];this.memory.clear();for(let[e,s]of t)this.setSync(e,s)}disable(){if(!this.persistent)return;let t=A(),e=[];try{for(let s=0;t&&s<t.length;s++){let n=t.key(s);n&&n.startsWith(V)&&e.push(n)}}catch{}for(let s of Y)e.includes(s)||e.push(s);for(let s of e){let n=this.getSync(s);n!==null&&this.memory.set(s,n)}this.persistent=!1;for(let s of e){try{t==null||t.removeItem(s)}catch{}this.cookies&&I(s,this.cookieDomain())}}};var jt="traq_click",f="traq_click",pt=/^[A-Za-z0-9_-]{8,64}$/;function Xt(i){try{let t=new URL(i).searchParams.get(jt);return t&&pt.test(t)?t:null}catch{return null}}var D=class{constructor(t,e,s,n){this.store=t;this.maxAgeMs=e;this.cookieDomain=s;this.cookies=n}capture(t,e=Date.now()){let s=Xt(t);return s&&this.write(s,e),s}get(t=Date.now()){let e=this.store.getSync(f);if(e)try{let s=JSON.parse(e);if(s&&typeof s.id=="string"&&s.exp>t)return s.id}catch{}if(this.cookies&&this.store.isPersistent){let s=v(f);if(s&&pt.test(s))return s}return null}clear(){this.store.removeSync(f),this.cookies&&I(f,this.cookieDomain())}persistCookie(t=Date.now()){let e=this.store.getSync(f);if(!(!e||!this.cookies||!this.store.isPersistent))try{let s=JSON.parse(e);s.exp>t&&p(f,s.id,(s.exp-t)/1e3,this.cookieDomain())}catch{}}write(t,e){let s={id:t,exp:e+this.maxAgeMs};this.store.setSync(f,JSON.stringify(s)),this.cookies&&this.store.isPersistent&&p(f,t,this.maxAgeMs/1e3,this.cookieDomain())}};var zt="https://api.traqio.app",Zt=30,Gt=1440*60*1e3;function te(){return typeof window!="undefined"&&typeof document!="undefined"}function ee(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var B=class{constructor(){this.core=new gt.Client;this.store=null;this.trackIds=null;this.waitForConsent=!1;this.started=!1}async init(t){var a,l,g;if(this.started||!te())return;this.started=!0,this.waitForConsent=t.waitForConsent===!0;let e=t.cookies!==!1,s,n=()=>s===void 0?s=ft(location.hostname):s,r=(a=t.consent)!=null?a:this.earlyConsent,u=!this.waitForConsent||r===!0;if(this.store=new T(u,n,e),this.trackIds=new D(this.store,((l=t.trackIdDays)!=null?l:Zt)*Gt,n,e),this.trackIds.capture(location.href),!this.store.getSync(b)){let m=ee();m&&this.store.setSync(b,m)}await this.core.init({sdkKey:t.sdkKey,endpoint:((g=t.endpoint)!=null?g:zt).replace(/\/+$/,""),storage:this.store,platform:"web",userId:t.userId,consent:r,lifecycle:({background:m,foreground:yt})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?m():yt()),window.addEventListener("pagehide",m)}})}track(t,e){this.core.track(t,e)}setUserId(t){this.core.setUserId(t)}async setConsent(t){var e;this.started||(this.earlyConsent=t),this.store&&this.waitForConsent&&(t?(this.store.enable(),(e=this.trackIds)==null||e.persistCookie()):this.store.disable()),await this.core.setConsent(t)}getTrackId(){var t,e;return(e=(t=this.trackIds)==null?void 0:t.get())!=null?e:null}async forgetMe(){var e;let t=await this.core.forgetMe();return t&&((e=this.trackIds)==null||e.clear()),t}flush(){this.core.flush()}get forgotten(){return this.core.forgotten}},W=new B;window.Traqio=W;var h=document.currentScript,mt=h==null?void 0:h.dataset.sdkKey;mt&&W.init({sdkKey:mt,endpoint:(h==null?void 0:h.dataset.endpoint)||void 0,waitForConsent:(h==null?void 0:h.dataset.waitForConsent)==="true"});})();
|
|
2
2
|
//# sourceMappingURL=traqio.min.js.map
|