@traqio/web 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ import type { BrowserStore } from "./storage";
2
+ /**
3
+ * One value kept twice, on purpose:
4
+ * - localStorage `<key>` = `{ id, exp }`: survives navigation on this origin;
5
+ * - cookie `<key>` = the bare value, on the registrable domain: shared with the
6
+ * other subdomains, and sent by the browser to the site's OWN backend with the
7
+ * sign-up request — where the conversion that counts is known.
8
+ *
9
+ * Both writes go through the store's consent mode: before consent (with
10
+ * `waitForConsent`) the value lives in memory and no cookie is written.
11
+ */
12
+ export declare class KeptValue {
13
+ private readonly store;
14
+ private readonly key;
15
+ private readonly cookieDomain;
16
+ private readonly cookies;
17
+ /** A cookie value that fails this is ignored (another script's cookie, a tampered one). */
18
+ private readonly valid;
19
+ constructor(store: BrowserStore, key: string, cookieDomain: () => string | null, cookies: boolean,
20
+ /** A cookie value that fails this is ignored (another script's cookie, a tampered one). */
21
+ valid: (value: string) => boolean);
22
+ /** The kept value, or null once it has expired or was never there. */
23
+ get(now?: number): string | null;
24
+ set(value: string, maxAgeMs: number, now?: number): void;
25
+ /** Removes it everywhere — `forgetMe()`. */
26
+ clear(): void;
27
+ /** Writes the cookie half once storage becomes allowed (the localStorage half moves with the store). */
28
+ persistCookie(now?: number): void;
29
+ }
@@ -0,0 +1,70 @@
1
+ import type { BrowserStore } from "./storage";
2
+ /**
3
+ * Where a visitor came from when there was no Traqio link to click: the `utm_*`
4
+ * parameters of the landing URL (an Instagram bio, a newsletter, a LinkedIn post),
5
+ * the ad networks' own click ids (`gclid`, `fbclid`, `ttclid`), and the host of the
6
+ * page that sent them (`document.referrer`).
7
+ *
8
+ * Kept like the trackID (`traq_click`) — localStorage + a first-party cookie
9
+ * `traq_src`, same lifetime, same consent rules — so the site's backend reads it
10
+ * with the sign-up request and sends it with the sign-up (`@traqio/node`:
11
+ * `sourceFromRequest(req)`). Traqio then reports the sign-up under that source and
12
+ * campaign. A Traqio link click, when there is one, wins over it.
13
+ *
14
+ * The cookie holds a query string — `utm_source=instagram&utm_campaign=launch&ts=…`
15
+ * — so any backend language parses it with its standard library.
16
+ */
17
+ export declare const SOURCE_KEY = "traq_src";
18
+ /** The landing-URL parameters kept, as written in the URL. */
19
+ export declare const SOURCE_PARAMS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term", "gclid", "fbclid", "ttclid"];
20
+ /** Where the visitor came from — see `getSource()`. Every field is optional. */
21
+ export interface WebSource {
22
+ utmSource?: string;
23
+ utmMedium?: string;
24
+ utmCampaign?: string;
25
+ utmContent?: string;
26
+ utmTerm?: string;
27
+ /** Host of the page that linked here (`l.instagram.com`) — never its path or query. */
28
+ referrer?: string;
29
+ /** Google Ads click id. */
30
+ gclid?: string;
31
+ /** Meta click id (Facebook and Instagram links, paid or not). */
32
+ fbclid?: string;
33
+ /** TikTok Ads click id. */
34
+ ttclid?: string;
35
+ /** When the visitor landed with it, epoch ms. */
36
+ landedAt?: number;
37
+ }
38
+ /**
39
+ * The host of an EXTERNAL referrer, or null (none, this site, not http(s)). Only the
40
+ * host: a referrer's path and query can carry anything, a search, an email address.
41
+ */
42
+ export declare function referrerHost(referrer: string | null | undefined, pageHref: string): string | null;
43
+ /**
44
+ * The source a landing carries, as the query string kept in `traq_src`, or null
45
+ * when it carries none. `fromUrl` = the landing URL itself carried a parameter (a
46
+ * referrer-only landing does not).
47
+ */
48
+ export declare function sourceFromLanding(href: string, referrer: string | null | undefined, now: number): {
49
+ query: string;
50
+ fromUrl: boolean;
51
+ } | null;
52
+ /** The kept query string, as a `WebSource`. Null when it holds nothing we know. */
53
+ export declare function parseSource(query: string): WebSource | null;
54
+ export declare class SourceKeeper {
55
+ private readonly maxAgeMs;
56
+ private readonly kept;
57
+ constructor(store: BrowserStore, maxAgeMs: number, cookieDomain: () => string | null, cookies: boolean);
58
+ /**
59
+ * Reads the landing. URL parameters (`utm_*`, a click id) REPLACE what is kept:
60
+ * the last campaign that brought the visitor is the one that counts, as for the
61
+ * trackID. A referrer alone only fills an empty slot — the return from a payment
62
+ * page or a webmail must not overwrite the campaign the visitor came from. A
63
+ * landing with neither (a typed URL, an internal navigation) changes nothing.
64
+ */
65
+ capture(href: string, referrer: string | null | undefined, now?: number): WebSource | null;
66
+ /** The kept source, or null (none, or expired). */
67
+ get(now?: number): WebSource | null;
68
+ clear(): void;
69
+ persistCookie(now?: number): void;
70
+ }
@@ -15,6 +15,7 @@ export interface FakeBrowser {
15
15
  }
16
16
  export declare function installBrowser(href: string, opts?: {
17
17
  storageBlocked?: boolean;
18
+ referrer?: string;
18
19
  }): FakeBrowser;
19
20
  export interface CapturedRequest {
20
21
  url: string;
@@ -14,10 +14,8 @@ export declare const CLICK_PARAM = "traq_click";
14
14
  /** The click id carried by a URL, or null. Never throws on a malformed URL. */
15
15
  export declare function clickIdFromUrl(href: string): string | null;
16
16
  export declare class TrackIdKeeper {
17
- private readonly store;
18
17
  private readonly maxAgeMs;
19
- private readonly cookieDomain;
20
- private readonly cookies;
18
+ private readonly kept;
21
19
  constructor(store: BrowserStore, maxAgeMs: number, cookieDomain: () => string | null, cookies: boolean);
22
20
  /**
23
21
  * Reads the landing URL. A new click REPLACES the kept one: the last ad clicked is
@@ -31,5 +29,4 @@ export declare class TrackIdKeeper {
31
29
  clear(): void;
32
30
  /** Writes the cookie half once storage becomes allowed (the localStorage half moves with the store). */
33
31
  persistCookie(now?: number): void;
34
- private write;
35
32
  }
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{var Ye=Object.create;var $=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var Qe=(n,e,t)=>()=>{if(t)throw t[0];try{return n&&(e=n(n=0)),e}catch(i){throw t=[i],i}};var T=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var ae=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of We(e))!Be.call(n,r)&&r!==t&&$(n,r,{get:()=>e[r],enumerable:!(i=$e(e,r))||i.enumerable});return n};var Xe=(n,e,t)=>(t=n!=null?Ye(je(n)):{},ae(e||!n||!n.__esModule?$(t,"default",{value:n,enumerable:!0}):t,n)),L=n=>ae($({},"__esModule",{value:!0}),n);var j=T(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});l.Skan=l.SKAN_STATE_KEY=l.CONVERSION_WINDOWS=void 0;l.windowForAge=de;l.shouldLockWindow=ce;l.fineValueForRevenue=le;l.fineValueForEvents=he;l.coarseValueForRevenue=fe;l.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function de(n){let e=l.CONVERSION_WINDOWS.find(t=>n>=t.startHours&&n<t.endHours);return e?e.window:null}function ce(n,e){let t=de(e);if(t==null||!n||!n.length)return!1;let i=n.find(r=>r.window===t);return!i||!i.lock?!1:i.lockAfterHours==null?!0:e>=i.lockAfterHours}var He=63,Je=6;function le(n,e){let t=0;for(let i=0;i<Math.min(e.length,He+1);i++)n>=e[i]&&(t=i);return t}function he(n,e){let t=new Set(n),i=0;return e.slice(0,Je).forEach((r,s)=>{t.has(r)&&(i|=1<<s)}),i}function fe(n,e){if(!e)return;let t,i=-1/0;for(let r of["low","medium","high"]){let s=e[r];s!=null&&n>=s&&s>=i&&(t=r,i=s)}return t}var ue={revenue:0,events:[],lastFine:null};l.SKAN_STATE_KEY="traq_skan_state";var W=class{constructor(){this.mapping=null,this.state={...ue},this.enabled=!1}async init(e){this.opts=e,this.enabled=!!e.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(e){!this.enabled||!(e>0)||!Number.isFinite(e)||(this.state.revenue+=e,this.persist(),this.push())}markEvent(e){!this.enabled||this.state.events.includes(e)||(this.state.events.push(e),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var r,s;let e=this.mapping;if(!e||!this.opts.native)return;let t,i;if(e.mode==="events"){if(!((r=e.eventBits)!=null&&r.length))return;t=he(this.state.events,e.eventBits)}else{if(!((s=e.revenueBuckets)!=null&&s.length))return;t=le(this.state.revenue,e.revenueBuckets),i=fe(this.state.revenue,e.coarseRevenue)}this.state.lastFine==null&&t===0||this.state.lastFine!=null&&t<=this.state.lastFine||(this.state.lastFine=t,this.persist(),this.opts.native.updateConversionValue(t,i,this.lockWindowNow()))}lockWindowNow(){var i;let e=this.state.firstSeenAt;if(e==null)return!1;let t=(this.now()-e)/36e5;return ce((i=this.mapping)==null?void 0:i.postbackWindows,t)}now(){return this.opts.nowFn?this.opts.nowFn():Date.now()}async fetchMapping(){var t;let e=(t=this.opts.fetchFn)!=null?t:typeof fetch=="function"?fetch:void 0;if(!e)return null;try{let i=await e(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!i.ok)return null;let r=await i.json();return r&&typeof r=="object"?r:null}catch{return null}}async restore(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(l.SKAN_STATE_KEY));t&&(this.state={...ue,...JSON.parse(t)})}catch{}}async persist(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(l.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};l.Skan=W});var Q=T(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.ADSERVICES_ATTEMPTS_KEY=f.ADSERVICES_SENT_KEY=void 0;f.reportAdServicesToken=Ze;f.ADSERVICES_SENT_KEY="traq_adservices_sent";f.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var ze=5;async function Ze(n){var i,r;if(!((i=n.native)!=null&&i.getAttributionToken))return"unsupported";if(await pe(n,f.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await n.native.getAttributionToken()}catch{}if(!e||!e.trim()){let s=Number(await pe(n,f.ADSERVICES_ATTEMPTS_KEY))||0;return await B(n,f.ADSERVICES_ATTEMPTS_KEY,String(s+1)),s+1>=ze&&await B(n,f.ADSERVICES_SENT_KEY,"1"),"no-token"}let t=(r=n.fetchFn)!=null?r:typeof fetch=="function"?fetch:void 0;if(!t)return"post-failed";try{if(!(await t(`${n.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:n.sdkKey,token:e.trim(),deviceId:n.deviceId,appUserId:n.userId,...n.debug?{debug:!0}:{}})})).ok)return"post-failed"}catch{return"post-failed"}return await B(n,f.ADSERVICES_SENT_KEY,"1"),"sent"}async function pe(n,e){var t,i;try{return(i=await((t=n.storage)==null?void 0:t.getItem(e)))!=null?i:null}catch{return null}}async function B(n,e,t){var i;try{await((i=n.storage)==null?void 0:i.setItem(e,t))}catch{}}});var X=T(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.isTrackingUrl=tt;R.isOpenUrl=it;R.toDeepLink=ve;R.upgradeStoredDeepLink=nt;var et=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/,me=/^\/o\/[0-9a-fA-F-]{36}\/?$/;function ge(n){var t;let e=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(n);return e?(t=e[1])!=null?t:"":null}function tt(n){let e=ge(n);return e!==null&&(et.test(e)||me.test(e))}function it(n){let e=ge(n);return e!==null&&me.test(e)}function ve(n,e,t){var s,a,u;if(!(n!=null&&n.matched)||!n.via)return null;let i=(s=n.matchType)!=null?s:n.via==="ip_match"?"probabilistic":n.via,r=(a=n.payload)!=null?a:{deepLink:n.deepLink,value:null,params:{}};return{payload:r,matchType:i,confidence:i==="probabilistic"?(u=n.confidence)!=null?u:"low":null,deferred:e,code:n.code,deepLink:r.deepLink,via:n.via,...t?{url:t}:{}}}function nt(n){var t,i,r;if(!n||typeof n!="object")return null;let e=n;return e.payload&&e.matchType?e:e.via?ve({matched:!0,via:e.via,code:(t=e.code)!=null?t:null,deepLink:(i=e.deepLink)!=null?i:null},(r=e.deferred)!=null?r:!0,e.url):null}});var P={};var D=Qe(()=>{"use strict"});var z=T(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.CAPACITOR_ADMOB_PAID_EVENTS=d.MAX_RN_MIN_VERSION=d.MAX_RN_REVENUE_EVENTS=d.GMA_MIN_VERSION=d.GMA_FULLSCREEN_CHANNELS=d.AdRevenueGate=void 0;d.fromGoogleMobileAdsPaid=J;d.fromGoogleMobileAdsChannel=Ee;d.fromGoogleMobileAdsNativeAd=Ie;d.fromMaxAdInfo=Se;d.fromCapacitorAdMob=ot;d.watchReactNativeAds=ut;function rt(n){return Array.isArray(n)?n.length>0:n===!0}var H=class{constructor(e=t=>console.warn(t)){this.warn=e,this.coverage={},this.warned=new Set,this.seen=new WeakSet}arm(e){this.coverage={...e}}captures(e){return rt(this.coverage[e])}capturesFormat(e,t){let i=this.coverage[e];return i===!0?!0:Array.isArray(i)&&t!==void 0&&i.includes(t)}manual(e,t){return this.captures(e)?(this.warnOnce(`manual:${e}`,`[traqio] adRevenue.${e} is on: manual ${t}() ignored \u2014 Traqio already captures this network, remove the call.`),!1):!0}helper(e,t,i,r){return this.capturesFormat(e,t)?(this.warnOnce(`helper:${e}:${t}`,`[traqio] adRevenue.${e} already captures ${t} ads: ${r} ignored for them, keep it on the formats it is documented for.`),!1):this.first(i)}first(e){return!e||typeof e!="object"?!0:this.seen.has(e)?!1:(this.seen.add(e),!0)}warnOnce(e,t){if(!this.warned.has(e)){this.warned.add(e);try{this.warn(t)}catch{}}}};d.AdRevenueGate=H;var st=["unknown","estimated","publisher_provided","precise"];function ye(n){var e;return typeof n=="number"&&(e=st[n])!=null?e:"unknown"}function y(n){return typeof n=="string"&&n.trim()?n:void 0}function A(n){return n&&typeof n=="object"?n:void 0}function Ae(n){let e=typeof n=="string"&&/^\d+$/.test(n.trim())?Number(n):n;return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}d.GMA_FULLSCREEN_CHANNELS={rnapp_google_mobile_ads_app_open_event:"app_open",rnapp_google_mobile_ads_interstitial_event:"interstitial",rnapp_google_mobile_ads_rewarded_event:"rewarded",rnapp_google_mobile_ads_rewarded_interstitial_event:"rewarded_interstitial"};d.GMA_MIN_VERSION="12.4.0";function J(n,e={}){var a;let t=A(n);if(!t)return;let i=y(t.currency);if(!i)return;let r=Ae(t.valueMicros);if(r===void 0){if(!(typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=0))return;r=Math.round(t.value*1e6)}let s=A((a=A(t.responseInfo))==null?void 0:a.loadedAdapterResponse);return{valueMicros:r,currency:i,precision:ye(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:y(s==null?void 0:s.adSourceName)}}function Ee(n,e){let t=A(e),i=A(t==null?void 0:t.body);if(!(!t||(i==null?void 0:i.type)!=="paid"))return J(i.data,{adUnitId:y(t.adUnitId),adFormat:d.GMA_FULLSCREEN_CHANNELS[n]})}function Ie(n){let e=A(n);if((e==null?void 0:e.type)==="paid")return J(e,{adFormat:"native"})}d.MAX_RN_REVENUE_EVENTS=["OnBannerAdRevenuePaid","OnMRecAdRevenuePaid","OnInterstitialAdRevenuePaid","OnRewardedAdRevenuePaid","OnAppOpenAdRevenuePaid"];d.MAX_RN_MIN_VERSION="5.0.0";function Se(n){let e=A(n);if(!(!e||typeof e.revenue!="number"))return{revenue:e.revenue,revenuePrecision:y(e.revenuePrecision),adUnitId:y(e.adUnitId),format:y(e.adFormat),networkName:y(e.networkName)}}d.CAPACITOR_ADMOB_PAID_EVENTS={bannerAdPaid:"banner",nativeAdPaid:"native",interstitialAdImpression:"interstitial",onRewardedVideoAdImpression:"rewarded",onRewardedInterstitialAdImpression:"rewarded_interstitial",appOpenAdImpression:"app_open"};function ot(n,e){let t=A(n),i=Ae(t==null?void 0:t.valueMicros),r=y(t==null?void 0:t.currencyCode);if(!(!t||i===void 0||!r))return{valueMicros:i,currency:r,precision:ye(t.precision),adUnitId:y(t.adUnitId),adFormat:e,adSourceName:y(t.networkName)}}function _e(n,e){var t,i,r,s,a;try{return(s=(i=(t=n.TurboModuleRegistry)==null?void 0:t.get)==null?void 0:i.call(t,e))!=null?s:(r=n.NativeModules)==null?void 0:r[e]}catch{return(a=n.NativeModules)==null?void 0:a[e]}}var at=["interstitial","rewarded","rewarded_interstitial","app_open"];function ut(n,e,t){var u,h,I,m;if(!t)try{t=(D(),L(P))}catch{return{coverage:{},stop:()=>{}}}let i=[],r={},s=(c,g,v=_=>_)=>_=>{try{let S=c(_);S&&g(S,v(_))}catch{}},a=c=>{var g,v;return(v=A((g=A(c))==null?void 0:g.body))==null?void 0:v.data};if(n.admob){r.admob=[];for(let[v,_]of Object.entries(d.GMA_FULLSCREEN_CHANNELS)){let S=(u=t.DeviceEventEmitter)==null?void 0:u.addListener(v,s(w=>Ee(v,w),e.admob,a));S&&(i.push(S),r.admob.push(_))}let c=_e(t,"RNGoogleMobileAdsNativeModule"),g=s(Ie,e.admob);try{if(c&&typeof c.onAdEvent=="function")i.push(c.onAdEvent(g)),r.admob.push("native");else if(c&&t.NativeEventEmitter){let v=new t.NativeEventEmitter(((h=t.Platform)==null?void 0:h.OS)==="ios"?c:void 0);i.push(v.addListener("RNGMANativeAdEvent",g)),r.admob.push("native")}}catch{}}if(n.applovinMax){let c=_e(t,"AppLovinMAX");if(c&&t.NativeEventEmitter)try{let g=[...d.MAX_RN_REVENUE_EVENTS];try{let _=(m=(I=c.getConstants)==null?void 0:I.call(c))!=null?m:{},S=Object.keys(_).filter(w=>/^ON_.*_AD_REVENUE_PAID$/.test(w)).map(w=>_[w]).filter(w=>typeof w=="string");S.length&&(g=[...new Set([...S,...g])])}catch{}let v=new t.NativeEventEmitter(c);for(let _ of g)i.push(v.addListener(_,s(Se,e.applovinMax)));r.applovinMax=[...at]}catch{}}return{coverage:r,stop:()=>{for(let c of i.splice(0))try{c.remove()}catch{}}}}});var Fe=T(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.Traqio=o.Client=o.AdRevenueGate=o.watchReactNativeAds=o.fromMaxAdInfo=o.fromGoogleMobileAdsPaid=o.fromGoogleMobileAdsNativeAd=o.fromGoogleMobileAdsChannel=o.fromCapacitorAdMob=o.MAX_RN_REVENUE_EVENTS=o.MAX_RN_MIN_VERSION=o.GMA_MIN_VERSION=o.GMA_FULLSCREEN_CHANNELS=o.CAPACITOR_ADMOB_PAID_EVENTS=o.isTrackingUrl=o.isOpenUrl=o.reportAdServicesToken=o.Skan=o.SDK_VERSION=void 0;o.normalizeAdvertisingId=Le;o.fromMaxAd=F;o.detectDebug=Pe;o.isLocalPage=Ue;var dt=j(),ct=Q(),b=X(),U=z();o.SDK_VERSION="0.5.0";var lt=j();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return lt.Skan}});var ht=Q();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return ht.reportAdServicesToken}});var xe=X();Object.defineProperty(o,"isOpenUrl",{enumerable:!0,get:function(){return xe.isOpenUrl}});Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return xe.isTrackingUrl}});var p=z();Object.defineProperty(o,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return p.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(o,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return p.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(o,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return p.GMA_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return p.MAX_RN_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return p.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(o,"fromCapacitorAdMob",{enumerable:!0,get:function(){return p.fromCapacitorAdMob}});Object.defineProperty(o,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return p.fromGoogleMobileAdsChannel}});Object.defineProperty(o,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return p.fromGoogleMobileAdsNativeAd}});Object.defineProperty(o,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return p.fromGoogleMobileAdsPaid}});Object.defineProperty(o,"fromMaxAdInfo",{enumerable:!0,get:function(){return p.fromMaxAdInfo}});Object.defineProperty(o,"watchReactNativeAds",{enumerable:!0,get:function(){return p.watchReactNativeAds}});Object.defineProperty(o,"AdRevenueGate",{enumerable:!0,get:function(){return p.AdRevenueGate}});var ft="traq_install_sent",pt="traq_install_sent_debug",be="traq_install_attempts",ke="traq_referrer",we="traq_queue",Ne="traq_ad_queue",Re="traq_device_id",Me="traq_last_session",Te="traq_erased",N="traq_deferred_link",Z="traq_deferred_consent_retry_until",mt=60*6e4,De="traq_consent",gt=20,vt=new Set([400,413,422]),Oe=500,_t=100,Ce=1e3,ee=1e3,yt=300*1e3,At=3e3,Et=3,It=1800*1e3,St={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},bt={BANNER:"banner",LEADER:"banner",MREC:"banner",INTER:"interstitial",INTERSTITIAL:"interstitial",REWARDED:"rewarded",REWARDED_INTER:"rewarded_interstitial",NATIVE:"native",APPOPEN:"app_open",APP_OPEN:"app_open"},kt="00000000-0000-0000-0000-000000000000";function Le(n){if(typeof n!="string")return;let e=n.trim();if(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(e))return e===kt?void 0:e}function F(n){var e,t,i;if(typeof n.revenue=="number"&&Number.isFinite(n.revenue)&&n.revenue>=0)return{valueMicros:Math.round(n.revenue*1e6),currency:"USD",precision:(t=St[(e=n.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:n.adUnitId,adFormat:bt[((i=n.format)!=null?i:"").toUpperCase()],adSourceName:n.networkName,ts:n.ts}}function O(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)})}function wt(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Nt(){var n;try{let e=(D(),L(P)),t=(n=e==null?void 0:e.default)!=null?n:e;if(typeof(t==null?void 0:t.getItem)=="function"&&typeof(t==null?void 0:t.setItem)=="function")return{getItem:i=>t.getItem(i),setItem:(i,r)=>t.setItem(i,r)}}catch{}}var V=class{constructor(){this.queue=[],this.adQueue=[],this.adGate=new U.AdRevenueGate,this.adBatchId=null,this.context={sdkVersion:o.SDK_VERSION},this.referrer=null,this.started=!1,this.flushing=!1,this.flushTimer=null,this.retryMs=ee,this.skan=new dt.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null,this.debug=!1,this.maxRevenuePaid=e=>{try{let t=(0,U.fromMaxAdInfo)(e),i=t&&F(t);i&&this.adGate.helper("applovinMax",i.adFormat,e,"Traqio.maxRevenuePaid")&&this.queueAdRevenue(i,"applovin_max","auto")}catch{}}}get isDebug(){return this.debug}async init(e){var t;if(!this.started&&(this.started=!0,this.opts={collectContext:!0,...e,storage:(t=e.storage)!=null?t:Nt()},this.opts.storage||console.warn("[traqio] no storage available \u2014 pass `storage` to init() or install @react-native-async-storage/async-storage, otherwise the install is re-sent at every launch."),this.debug=await Pe(e),await this.restoreConsent(e.consent),await this.restoreQueue(),await this.restoreAdQueue(),await this.buildContext(),!await this.restoreErased())){if(!this.isWeb){let i=!!this.opts.storage&&!await this.opts.storage.getItem(this.installSentKey).catch(()=>"1");await this.sendInstallOnce(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(i).then(r=>r!=null?r:this.retryDeferredWithConsent()),this.wireDeepLinks())}await this.maybeStartSession(!this.isWeb),await this.initSkan(),await this.initAppleAds(),this.wireLifecycle(),this.wireAdRevenue(),(this.queue.length||this.adQueue.length)&&this.scheduleFlush(0)}}wireAdRevenue(){var i,r;let e=this.opts.adRevenue;if(!e||this.isWeb||!(e.admob||e.applovinMax))return;let t={admob:(s,a)=>{this.adGate.first(a)&&this.queueAdRevenue(s,"admob","auto")},applovinMax:(s,a)=>{let u=F(s);u&&this.adGate.first(a)&&this.queueAdRevenue(u,"applovin_max","auto")}};try{let s=(i=this.opts.native)!=null&&i.watchAdRevenue?(r=this.opts.native.watchAdRevenue(e,t))!=null?r:e:(0,U.watchReactNativeAds)(e,t).coverage;this.adGate.arm(s)}catch{}}track(e,t){var r,s;if(!this.started||this.erased)return;let i=((r=t==null?void 0:t.transactionId)==null?void 0:r.trim())||void 0;this.enqueue({name:e,eventId:O(),value:t==null?void 0:t.value,currency:t==null?void 0:t.currency,...i?{transactionId:i,store:(s=t==null?void 0:t.store)!=null?s:this.defaultStore()}:{}}),this.skan.markEvent(e),t!=null&&t.value&&this.skan.addRevenue(t.value)}defaultStore(){var t;let e=(t=this.opts.native)==null?void 0:t.platform;return e==="ios"?"app_store":e==="android"?"play_store":void 0}trackAdRevenue(e){this.adGate.manual("admob","trackAdRevenue")&&this.queueAdRevenue(e,"admob","manual")}trackMaxAdRevenue(e){if(!this.adGate.manual("applovinMax","trackMaxAdRevenue"))return;let t=F(e);t&&this.queueAdRevenue(t,"applovin_max","manual")}admobPaid(e,t="banner"){return i=>{try{let r=(0,U.fromGoogleMobileAdsPaid)(i,{adUnitId:e,adFormat:t});r&&this.adGate.helper("admob",t,i,"Traqio.admobPaid()")&&this.queueAdRevenue(r,"admob","auto")}catch{}}}queueAdRevenue(e,t,i){var r;!this.started||this.erased||!(e.valueMicros>=0)||!e.currency||(this.adQueue.push({...e,source:t,origin:i,impressionId:O(),ts:(r=e.ts)!=null?r:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>Ce&&this.adQueue.splice(0,this.adQueue.length-Ce),this.persistAdQueue(),this.scheduleFlush())}getInstallReferrer(){return this.started?this.readReferrer():Promise.resolve({status:"unavailable",retryable:!1})}onDeepLink(e){this.deepLinkListeners.add(e);let t=this.undelivered.splice(0);for(let i of t)e(i);return()=>{this.deepLinkListeners.delete(e)}}async handleUrl(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,b.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),i=(0,b.isOpenUrl)(e),r=(0,b.toDeepLink)(t,i,e);return r&&i&&await this.keepDeferred(r),r&&this.emitDeepLink(r),r}getDeferredDeepLink(){var e;return(e=this.deferred)!=null?e:Promise.resolve(null)}async redeemDeepLinkCode(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!e.trim())return null;let t=await this.postJson({code:e},"/deeplink/code"),i=(0,b.toDeepLink)(t,!0);return i?(await this.keepDeferred(i),this.emitDeepLink(i),i):null}async forgetMe(){return this.started?this.erased?!0:await this.post({deviceId:this.context.deviceId,appUserId:this.opts.userId},"/privacy/forget")?(await this.markErased(),!0):!1:!1}async setConsent(e){var t,i;this.consent=e?"granted":"denied",await((i=(t=this.opts)==null?void 0:t.storage)==null?void 0:i.setItem(De,this.consent).catch(()=>{})),e&&this.deferred&&!this.erased&&(this.deferred=this.deferred.then(r=>r!=null?r:this.retryDeferredWithConsent()),await this.deferred)}get forgotten(){return this.erased}setUserId(e){this.opts&&(this.opts.userId=e)}flush(){this.erased||(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.drain())}appOpened(){!this.started||this.erased||this.maybeStartSession()}get skanMapping(){return this.skan.activeMapping}async initAppleAds(){if(this.opts.appleAds===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.getAttributionToken||await(0,ct.reportAdServicesToken)({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,deviceId:this.context.deviceId,userId:this.opts.userId,storage:this.opts.storage,native:{getAttributionToken:()=>e.getAttributionToken()},debug:this.debug})}async initSkan(){if(this.opts.skan===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.updateConversionValue||await this.skan.init({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,storage:this.opts.storage,native:{updateConversionValue:(t,i,r)=>{var s;return(s=e.updateConversionValue)==null?void 0:s.call(e,t,i,r)}}})}async resolveDeferredOnce(e){var h,I;let t=this.opts.storage;try{let m=await(t==null?void 0:t.getItem(N));if(m)return(0,b.upgradeStoredDeepLink)(JSON.parse(m))}catch{}if(!e&&!await(t==null?void 0:t.getItem(`${N}_pending`).catch(()=>null)))return null;let i=(I=(h=this.opts.native)==null?void 0:h.platform)!=null?I:"android",r=i==="android"?await this.readReferrer():null;await(t==null?void 0:t.setItem(`${N}_pending`,"1").catch(()=>{}));let s=await this.askDeferred(i,r==null?void 0:r.referrer);if(!s)return null;let a=(0,b.toDeepLink)(s,!0),u=await this.storedDeferred();if(u)return u;try{await(t==null?void 0:t.setItem(N,JSON.stringify(a))),!a&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(Z,String(Date.now()+mt)))}catch{}return a&&this.emitDeepLink(a),a}askDeferred(e,t){return this.postJson({platform:e,installReferrer:t,...this.consent?{consent:this.consent}:{},...this.context.osVersion?{osVersion:this.context.osVersion}:{},...this.context.deviceModel?{deviceModel:this.context.deviceModel}:{}},"/deeplink/deferred")}async retryDeferredWithConsent(){var s,a,u,h;let e=(s=this.opts)==null?void 0:s.storage;if(!e||this.consent!=="granted"||this.opts.deepLinking===!1||this.isWeb)return null;let t=Number(await e.getItem(Z).catch(()=>null));if(!t||(await e.setItem(Z,"").catch(()=>{}),Date.now()>t))return null;let i=await this.storedDeferred();if(i)return i;let r=(0,b.toDeepLink)(await this.askDeferred((u=(a=this.opts.native)==null?void 0:a.platform)!=null?u:"ios",void 0),!0);return r?(await((h=this.opts.storage)==null?void 0:h.setItem(N,JSON.stringify(r)).catch(()=>{})),this.emitDeepLink(r),r):null}async storedDeferred(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(N));return t?(0,b.upgradeStoredDeepLink)(JSON.parse(t)):null}catch{return null}}async keepDeferred(e){var t;await this.storedDeferred()||(await((t=this.opts.storage)==null?void 0:t.setItem(N,JSON.stringify(e)).catch(()=>{})),this.deferred=Promise.resolve(e))}emitDeepLink(e){if(!this.deepLinkListeners.size){this.undelivered.push(e);return}for(let t of this.deepLinkListeners)try{t(e)}catch{}}wireDeepLinks(){try{let{Linking:e}=(D(),L(P));if(!e)return;e.getInitialURL().then(t=>t&&this.handleUrl(t)).catch(()=>{}),e.addEventListener("url",({url:t})=>{this.handleUrl(t)})}catch{}}get isWeb(){var e;return((e=this.opts)==null?void 0:e.platform)==="web"}get installSentKey(){return this.debug?pt:ft}debugField(){return this.debug?{debug:!0}:{}}wireLifecycle(){let e={background:()=>this.flush(),foreground:()=>this.appOpened()};if(this.opts.lifecycle){this.opts.lifecycle(e);return}try{let{AppState:t}=(D(),L(P));t.addEventListener("change",i=>{if(i!=="active"){this.scheduleFlush(0);return}this.maybeStartSession()})}catch{}}async restoreErased(){var e;try{this.erased=await((e=this.opts.storage)==null?void 0:e.getItem(Te))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var e;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,await this.persistQueue(),await this.persistAdQueue();try{await((e=this.opts.storage)==null?void 0:e.setItem(Te,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>Oe&&this.queue.splice(0,this.queue.length-Oe),this.persistQueue(),this.scheduleFlush()}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(we));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(we,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,i;try{let r=await((e=this.opts.storage)==null?void 0:e.getItem(Ne));if(!r)return;let s=JSON.parse(r);this.adQueue=(t=s.items)!=null?t:[],this.adBatchId=(i=s.batchId)!=null?i:null}catch{}}async persistAdQueue(){var e;try{let t={batchId:this.adBatchId,items:this.adQueue};await((e=this.opts.storage)==null?void 0:e.setItem(Ne,JSON.stringify(t)))}catch{}}async maybeStartSession(e=!1){var s,a,u;if(this.erased)return;let t=Date.now();if(!e){let h=Number(await((s=this.opts.storage)==null?void 0:s.getItem(Me).catch(()=>null)))||0;if(h&&t-h<It)return}let i=(a=this.context.deviceId)!=null?a:await this.getOrCreateDeviceId();if(await this.post({deviceId:i,appUserId:this.opts.userId,sessionId:O(),ts:Math.floor(t/1e3),context:this.context},"/ingest/session"))try{await((u=this.opts.storage)==null?void 0:u.setItem(Me,String(t)))}catch{}}async buildContext(){var t,i,r;if(!this.opts.collectContext){this.context={sdkVersion:o.SDK_VERSION};return}let e={};try{e=(r=await((i=(t=this.opts.native)==null?void 0:t.getContext)==null?void 0:i.call(t)))!=null?r:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:e.deviceModel,osVersion:e.osVersion,appVersion:this.opts.appVersion,locale:wt(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var t,i;try{let r=await((t=this.opts.storage)==null?void 0:t.getItem(Re));if(r)return r}catch{}let e=O();try{await((i=this.opts.storage)==null?void 0:i.setItem(Re,e))}catch{}return e}async readReferrer(){var i,r;if(this.referrer)return this.referrer;try{let s=await((i=this.opts.storage)==null?void 0:i.getItem(ke));if(s)return this.referrer=JSON.parse(s)}catch{}let e=this.opts.native;if((e==null?void 0:e.platform)!=="android")return{status:e?"not_supported_platform":"unavailable",retryable:!1};let t=await e.getInstallReferrer().catch(()=>({status:"error",retryable:!0}));if(!t.retryable){this.referrer=t;try{await((r=this.opts.storage)==null?void 0:r.setItem(ke,JSON.stringify(t)))}catch{}}return t}async readAdvertisingId(){var e;if(!(!this.opts.collectAdvertisingId||!((e=this.opts.native)!=null&&e.getAdvertisingId)))try{return Le(await this.opts.native.getAdvertisingId())}catch{return}}async sendInstallOnce(){var s,a;let e=this.opts.storage;if(e&&await e.getItem(this.installSentKey))return;let t=(a=(s=this.opts.native)==null?void 0:s.platform)!=null?a:"android",i=await this.readReferrer();if(i.retryable&&e){let u=Number(await e.getItem(be))||0;if(u+1<Et){await e.setItem(be,String(u+1));return}}await this.post({install:{platform:t,installReferrer:i.referrer,appUserId:this.opts.userId,advertisingId:await this.readAdvertisingId(),context:this.context}})&&await(e==null?void 0:e.setItem(this.installSentKey,"1"))}scheduleFlush(e=At){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},e))}async drain(){var e;if(!this.erased&&!(this.flushing||!this.queue.length&&!this.adQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let t=this.queue.slice(0,gt),i=await this.send({events:t,appUserId:this.opts.userId,deviceId:this.context.deviceId});if(i==="retry")return this.backOff();i==="refused"&&console.warn(`[traqio] the server refused ${t.length} event(s) as malformed \u2014 dropped, not retried`),this.queue.splice(0,t.length),await this.persistQueue(),this.retryMs=ee}for(;this.adQueue.length;){let t=(e=this.adQueue[0].source)!=null?e:"admob",i=this.adQueue.findIndex(a=>{var u;return((u=a.source)!=null?u:"admob")!==t}),r=this.adQueue.slice(0,Math.min(_t,i===-1?this.adQueue.length:i));if(this.adBatchId||(this.adBatchId=O(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:t,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:r.map(({source:a,...u})=>u)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,r.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=ee}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,yt),this.scheduleFlush(this.retryMs)}async postJson(e,t){try{let i=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...this.debugField()}),...this.keepalive()});return i.ok?await i.json():null}catch{return null}}async restoreConsent(e){var i;if(e!==void 0)return this.setConsent(e);if(this.consent)return this.setConsent(this.consent==="granted");let t=await((i=this.opts.storage)==null?void 0:i.getItem(De).catch(()=>null));(t==="granted"||t==="denied")&&(this.consent=t)}keepalive(){return this.isWeb?{keepalive:!0}:{}}async post(e,t="/ingest"){return await this.send(e,t)==="ok"}async send(e,t="/ingest"){let i=this.consent&&(t==="/ingest"||t==="/ingest/session")?{consent:this.consent}:{};try{let r=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...i,...this.debugField()}),...this.keepalive()});return r.ok?"ok":vt.has(r.status)?"refused":"retry"}catch{return"retry"}}};o.Client=V;async function Pe(n){var e,t;if(n.debug!==void 0)return n.debug;if(n.platform==="web")return Ue();if(globalThis.__DEV__===!0)return!0;try{return await((t=(e=n.native)==null?void 0:e.isDebugBuild)==null?void 0:t.call(e))===!0}catch{return!1}}function Ue(n=globalThis.location){if(!n)return!1;if(n.protocol==="file:")return!0;let e=n.hostname.toLowerCase().replace(/^\[|\]$/g,"");return e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e==="::1"||e==="0.0.0.0"||/^127\.\d+\.\d+\.\d+$/.test(e)}o.Traqio=new V});var Ke=Xe(Fe(),1);var ie="traq_";function ne(){return typeof document=="undefined"?void 0:document}function C(n){let e=ne();if(!e)return null;for(let t of e.cookie?e.cookie.split(";"):[]){let i=t.indexOf("=");if(!(i<0)&&t.slice(0,i).trim()===n)try{return decodeURIComponent(t.slice(i+1).trim())}catch{return null}}return null}function te(n,e,t,i){let r=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",s=i?`; Domain=${i}`:"";return`${n}=${encodeURIComponent(e)}; Max-Age=${Math.floor(t)}; Path=/${s}; SameSite=Lax${r}`}function Ve(n){let e=ne();if(!e||!n.includes(".")||/^[\d.]+$/.test(n)||n.includes(":"))return null;let t=n.split("."),i=`${ie}probe`;for(let r=t.length-2;r>=0;r--){let s=t.slice(r).join(".");if(e.cookie=te(i,"1",10,s),C(i)==="1")return e.cookie=te(i,"",0,s),s}return null}function M(n,e,t,i){let r=ne();if(r)try{r.cookie=te(n,e,t,i)}catch{}}function x(n,e){M(n,"",0,e)}var G="traq_device_id",re=new Set([G]),Rt=395*24*60*60;function q(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var K=class{constructor(e,t,i){this.persistent=e;this.cookieDomain=t;this.cookies=i;this.memory=new Map}get isPersistent(){return this.persistent}async getItem(e){return this.getSync(e)}async setItem(e,t){this.setSync(e,t)}getSync(e){var i,r,s;if(this.memory.has(e))return(i=this.memory.get(e))!=null?i:null;if(!this.persistent)return null;let t=null;try{t=(s=(r=q())==null?void 0:r.getItem(e))!=null?s:null}catch{}return t===null&&this.cookies&&re.has(e)&&(t=C(e)),t}setSync(e,t){if(!this.persistent){this.memory.set(e,t);return}let i=!1;try{let r=q();r&&(r.setItem(e,t),i=!0)}catch{}i||this.memory.set(e,t),this.cookies&&re.has(e)&&M(e,t,Rt,this.cookieDomain())}removeSync(e){var t;this.memory.delete(e);try{(t=q())==null||t.removeItem(e)}catch{}this.cookies&&x(e,this.cookieDomain())}enable(){if(this.persistent)return;this.persistent=!0;let e=[...this.memory];this.memory.clear();for(let[t,i]of e)this.setSync(t,i)}disable(){if(!this.persistent)return;let e=q(),t=[];try{for(let i=0;e&&i<e.length;i++){let r=e.key(i);r&&r.startsWith(ie)&&t.push(r)}}catch{}for(let i of re)t.includes(i)||t.push(i);for(let i of t){let r=this.getSync(i);r!==null&&this.memory.set(i,r)}this.persistent=!1;for(let i of t){try{e==null||e.removeItem(i)}catch{}this.cookies&&x(i,this.cookieDomain())}}};var Mt="traq_click",k="traq_click",qe=/^[A-Za-z0-9_-]{8,64}$/;function Tt(n){try{let e=new URL(n).searchParams.get(Mt);return e&&qe.test(e)?e:null}catch{return null}}var Y=class{constructor(e,t,i,r){this.store=e;this.maxAgeMs=t;this.cookieDomain=i;this.cookies=r}capture(e,t=Date.now()){let i=Tt(e);return i&&this.write(i,t),i}get(e=Date.now()){let t=this.store.getSync(k);if(t)try{let i=JSON.parse(t);if(i&&typeof i.id=="string"&&i.exp>e)return i.id}catch{}if(this.cookies&&this.store.isPersistent){let i=C(k);if(i&&qe.test(i))return i}return null}clear(){this.store.removeSync(k),this.cookies&&x(k,this.cookieDomain())}persistCookie(e=Date.now()){let t=this.store.getSync(k);if(!(!t||!this.cookies||!this.store.isPersistent))try{let i=JSON.parse(t);i.exp>e&&M(k,i.id,(i.exp-e)/1e3,this.cookieDomain())}catch{}}write(e,t){let i={id:e,exp:t+this.maxAgeMs};this.store.setSync(k,JSON.stringify(i)),this.cookies&&this.store.isPersistent&&M(k,e,this.maxAgeMs/1e3,this.cookieDomain())}};var Dt="https://api.traqio.app",Ot=30,Ct=1440*60*1e3;function xt(){return typeof window!="undefined"&&typeof document!="undefined"}function Lt(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var se=class{constructor(){this.core=new Ke.Client;this.store=null;this.trackIds=null;this.waitForConsent=!1;this.started=!1}async init(e){var u,h,I;if(this.started||!xt())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,i,r=()=>i===void 0?i=Ve(location.hostname):i,s=(u=e.consent)!=null?u:this.earlyConsent,a=!this.waitForConsent||s===!0;if(this.store=new K(a,r,t),this.trackIds=new Y(this.store,((h=e.trackIdDays)!=null?h:Ot)*Ct,r,t),this.trackIds.capture(location.href),!this.store.getSync(G)){let m=Lt();m&&this.store.setSync(G,m)}await this.core.init({sdkKey:e.sdkKey,endpoint:((I=e.endpoint)!=null?I:Dt).replace(/\/+$/,""),storage:this.store,platform:"web",userId:e.userId,consent:s,debug:e.debug,lifecycle:({background:m,foreground:c})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?m():c()),window.addEventListener("pagehide",m)}})}get isDebug(){return this.core.isDebug}track(e,t){this.core.track(e,t)}setUserId(e){this.core.setUserId(e)}async setConsent(e){var t;this.started||(this.earlyConsent=e),this.store&&this.waitForConsent&&(e?(this.store.enable(),(t=this.trackIds)==null||t.persistCookie()):this.store.disable()),await this.core.setConsent(e)}getTrackId(){var e,t;return(t=(e=this.trackIds)==null?void 0:e.get())!=null?t:null}async forgetMe(){var t;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear()),e}flush(){this.core.flush()}get forgotten(){return this.core.forgotten}},oe=new se;window.Traqio=oe;var E=document.currentScript,Ge=E==null?void 0:E.dataset.sdkKey;Ge&&oe.init({sdkKey:Ge,endpoint:(E==null?void 0:E.dataset.endpoint)||void 0,waitForConsent:(E==null?void 0:E.dataset.waitForConsent)==="true"});})();
1
+ "use strict";(()=>{var je=Object.create;var B=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty;var ze=(r,e,t)=>()=>{if(t)throw t[0];try{return r&&(e=r(r=0)),e}catch(n){throw t=[n],n}};var T=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var le=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Xe(e))!Je.call(r,i)&&i!==t&&B(r,i,{get:()=>e[i],enumerable:!(n=Qe(e,i))||n.enumerable});return r};var Ze=(r,e,t)=>(t=r!=null?je(He(r)):{},le(e||!r||!r.__esModule?B(t,"default",{value:r,enumerable:!0}):t,r)),L=r=>le(B({},"__esModule",{value:!0}),r);var j=T(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.Skan=h.SKAN_STATE_KEY=h.CONVERSION_WINDOWS=void 0;h.windowForAge=fe;h.shouldLockWindow=pe;h.fineValueForRevenue=me;h.fineValueForEvents=ge;h.coarseValueForRevenue=ve;h.CONVERSION_WINDOWS=[{window:0,startHours:0,endHours:48},{window:1,startHours:48,endHours:168},{window:2,startHours:168,endHours:840}];function fe(r){let e=h.CONVERSION_WINDOWS.find(t=>r>=t.startHours&&r<t.endHours);return e?e.window:null}function pe(r,e){let t=fe(e);if(t==null||!r||!r.length)return!1;let n=r.find(i=>i.window===t);return!n||!n.lock?!1:n.lockAfterHours==null?!0:e>=n.lockAfterHours}var et=63,tt=6;function me(r,e){let t=0;for(let n=0;n<Math.min(e.length,et+1);n++)r>=e[n]&&(t=n);return t}function ge(r,e){let t=new Set(r),n=0;return e.slice(0,tt).forEach((i,s)=>{t.has(i)&&(n|=1<<s)}),n}function ve(r,e){if(!e)return;let t,n=-1/0;for(let i of["low","medium","high"]){let s=e[i];s!=null&&r>=s&&s>=n&&(t=i,n=s)}return t}var he={revenue:0,events:[],lastFine:null};h.SKAN_STATE_KEY="traq_skan_state";var $=class{constructor(){this.mapping=null,this.state={...he},this.enabled=!1}async init(e){this.opts=e,this.enabled=!!e.native,this.enabled&&(await this.restore(),this.state.firstSeenAt==null&&(this.state.firstSeenAt=this.now(),await this.persist()),this.mapping=await this.fetchMapping(),this.mapping&&this.push())}addRevenue(e){!this.enabled||!(e>0)||!Number.isFinite(e)||(this.state.revenue+=e,this.persist(),this.push())}markEvent(e){!this.enabled||this.state.events.includes(e)||(this.state.events.push(e),this.persist(),this.push())}get activeMapping(){return this.mapping}push(){var i,s;let e=this.mapping;if(!e||!this.opts.native)return;let t,n;if(e.mode==="events"){if(!((i=e.eventBits)!=null&&i.length))return;t=ge(this.state.events,e.eventBits)}else{if(!((s=e.revenueBuckets)!=null&&s.length))return;t=me(this.state.revenue,e.revenueBuckets),n=ve(this.state.revenue,e.coarseRevenue)}this.state.lastFine==null&&t===0||this.state.lastFine!=null&&t<=this.state.lastFine||(this.state.lastFine=t,this.persist(),this.opts.native.updateConversionValue(t,n,this.lockWindowNow()))}lockWindowNow(){var n;let e=this.state.firstSeenAt;if(e==null)return!1;let t=(this.now()-e)/36e5;return pe((n=this.mapping)==null?void 0:n.postbackWindows,t)}now(){return this.opts.nowFn?this.opts.nowFn():Date.now()}async fetchMapping(){var t;let e=(t=this.opts.fetchFn)!=null?t:typeof fetch=="function"?fetch:void 0;if(!e)return null;try{let n=await e(`${this.opts.endpoint}/skan/mapping/${encodeURIComponent(this.opts.sdkKey)}`);if(!n.ok)return null;let i=await n.json();return i&&typeof i=="object"?i:null}catch{return null}}async restore(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(h.SKAN_STATE_KEY));t&&(this.state={...he,...JSON.parse(t)})}catch{}}async persist(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(h.SKAN_STATE_KEY,JSON.stringify(this.state)))}catch{}}};h.Skan=$});var X=T(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.ADSERVICES_ATTEMPTS_KEY=p.ADSERVICES_SENT_KEY=void 0;p.reportAdServicesToken=rt;p.ADSERVICES_SENT_KEY="traq_adservices_sent";p.ADSERVICES_ATTEMPTS_KEY="traq_adservices_attempts";var nt=5;async function rt(r){var n,i;if(!((n=r.native)!=null&&n.getAttributionToken))return"unsupported";if(await ye(r,p.ADSERVICES_SENT_KEY))return"already-sent";let e=null;try{e=await r.native.getAttributionToken()}catch{}if(!e||!e.trim()){let s=Number(await ye(r,p.ADSERVICES_ATTEMPTS_KEY))||0;return await Q(r,p.ADSERVICES_ATTEMPTS_KEY,String(s+1)),s+1>=nt&&await Q(r,p.ADSERVICES_SENT_KEY,"1"),"no-token"}let t=(i=r.fetchFn)!=null?i:typeof fetch=="function"?fetch:void 0;if(!t)return"post-failed";try{if(!(await t(`${r.endpoint}/ingest/adservices`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:r.sdkKey,token:e.trim(),deviceId:r.deviceId,appUserId:r.userId,...r.debug?{debug:!0}:{}})})).ok)return"post-failed"}catch{return"post-failed"}return await Q(r,p.ADSERVICES_SENT_KEY,"1"),"sent"}async function ye(r,e){var t,n;try{return(n=await((t=r.storage)==null?void 0:t.getItem(e)))!=null?n:null}catch{return null}}async function Q(r,e,t){var n;try{await((n=r.storage)==null?void 0:n.setItem(e,t))}catch{}}});var H=T(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.isTrackingUrl=st;N.isOpenUrl=ot;N.toDeepLink=Se;N.upgradeStoredDeepLink=at;var it=/^\/c\/[A-Za-z0-9_-]{1,50}\/?$/,_e=/^\/o\/[0-9a-fA-F-]{36}\/?$/;function Ae(r){var t;let e=/^https?:\/\/[^/?#]+(\/[^?#]*)?/i.exec(r);return e?(t=e[1])!=null?t:"":null}function st(r){let e=Ae(r);return e!==null&&(it.test(e)||_e.test(e))}function ot(r){let e=Ae(r);return e!==null&&_e.test(e)}function Se(r,e,t){var s,a,u;if(!(r!=null&&r.matched)||!r.via)return null;let n=(s=r.matchType)!=null?s:r.via==="ip_match"?"probabilistic":r.via,i=(a=r.payload)!=null?a:{deepLink:r.deepLink,value:null,params:{}};return{payload:i,matchType:n,confidence:n==="probabilistic"?(u=r.confidence)!=null?u:"low":null,deferred:e,code:r.code,deepLink:i.deepLink,via:r.via,...t?{url:t}:{}}}function at(r){var t,n,i;if(!r||typeof r!="object")return null;let e=r;return e.payload&&e.matchType?e:e.via?Se({matched:!0,via:e.via,code:(t=e.code)!=null?t:null,deepLink:(n=e.deepLink)!=null?n:null},(i=e.deferred)!=null?i:!0,e.url):null}});var P={};var D=ze(()=>{"use strict"});var Z=T(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.CAPACITOR_ADMOB_PAID_EVENTS=d.MAX_RN_MIN_VERSION=d.MAX_RN_REVENUE_EVENTS=d.GMA_MIN_VERSION=d.GMA_FULLSCREEN_CHANNELS=d.AdRevenueGate=void 0;d.fromGoogleMobileAdsPaid=z;d.fromGoogleMobileAdsChannel=ke;d.fromGoogleMobileAdsNativeAd=we;d.fromMaxAdInfo=Ne;d.fromCapacitorAdMob=dt;d.watchReactNativeAds=ht;function ut(r){return Array.isArray(r)?r.length>0:r===!0}var J=class{constructor(e=t=>console.warn(t)){this.warn=e,this.coverage={},this.warned=new Set,this.seen=new WeakSet}arm(e){this.coverage={...e}}captures(e){return ut(this.coverage[e])}capturesFormat(e,t){let n=this.coverage[e];return n===!0?!0:Array.isArray(n)&&t!==void 0&&n.includes(t)}manual(e,t){return this.captures(e)?(this.warnOnce(`manual:${e}`,`[traqio] adRevenue.${e} is on: manual ${t}() ignored \u2014 Traqio already captures this network, remove the call.`),!1):!0}helper(e,t,n,i){return this.capturesFormat(e,t)?(this.warnOnce(`helper:${e}:${t}`,`[traqio] adRevenue.${e} already captures ${t} ads: ${i} ignored for them, keep it on the formats it is documented for.`),!1):this.first(n)}first(e){return!e||typeof e!="object"?!0:this.seen.has(e)?!1:(this.seen.add(e),!0)}warnOnce(e,t){if(!this.warned.has(e)){this.warned.add(e);try{this.warn(t)}catch{}}}};d.AdRevenueGate=J;var ct=["unknown","estimated","publisher_provided","precise"];function be(r){var e;return typeof r=="number"&&(e=ct[r])!=null?e:"unknown"}function y(r){return typeof r=="string"&&r.trim()?r:void 0}function _(r){return r&&typeof r=="object"?r:void 0}function Ie(r){let e=typeof r=="string"&&/^\d+$/.test(r.trim())?Number(r):r;return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}d.GMA_FULLSCREEN_CHANNELS={rnapp_google_mobile_ads_app_open_event:"app_open",rnapp_google_mobile_ads_interstitial_event:"interstitial",rnapp_google_mobile_ads_rewarded_event:"rewarded",rnapp_google_mobile_ads_rewarded_interstitial_event:"rewarded_interstitial"};d.GMA_MIN_VERSION="12.4.0";function z(r,e={}){var a;let t=_(r);if(!t)return;let n=y(t.currency);if(!n)return;let i=Ie(t.valueMicros);if(i===void 0){if(!(typeof t.value=="number"&&Number.isFinite(t.value)&&t.value>=0))return;i=Math.round(t.value*1e6)}let s=_((a=_(t.responseInfo))==null?void 0:a.loadedAdapterResponse);return{valueMicros:i,currency:n,precision:be(t.precision),adUnitId:e.adUnitId,adFormat:e.adFormat,adSourceName:y(s==null?void 0:s.adSourceName)}}function ke(r,e){let t=_(e),n=_(t==null?void 0:t.body);if(!(!t||(n==null?void 0:n.type)!=="paid"))return z(n.data,{adUnitId:y(t.adUnitId),adFormat:d.GMA_FULLSCREEN_CHANNELS[r]})}function we(r){let e=_(r);if((e==null?void 0:e.type)==="paid")return z(e,{adFormat:"native"})}d.MAX_RN_REVENUE_EVENTS=["OnBannerAdRevenuePaid","OnMRecAdRevenuePaid","OnInterstitialAdRevenuePaid","OnRewardedAdRevenuePaid","OnAppOpenAdRevenuePaid"];d.MAX_RN_MIN_VERSION="5.0.0";function Ne(r){let e=_(r);if(!(!e||typeof e.revenue!="number"))return{revenue:e.revenue,revenuePrecision:y(e.revenuePrecision),adUnitId:y(e.adUnitId),format:y(e.adFormat),networkName:y(e.networkName)}}d.CAPACITOR_ADMOB_PAID_EVENTS={bannerAdPaid:"banner",nativeAdPaid:"native",interstitialAdImpression:"interstitial",onRewardedVideoAdImpression:"rewarded",onRewardedInterstitialAdImpression:"rewarded_interstitial",appOpenAdImpression:"app_open"};function dt(r,e){let t=_(r),n=Ie(t==null?void 0:t.valueMicros),i=y(t==null?void 0:t.currencyCode);if(!(!t||n===void 0||!i))return{valueMicros:n,currency:i,precision:be(t.precision),adUnitId:y(t.adUnitId),adFormat:e,adSourceName:y(t.networkName)}}function Ee(r,e){var t,n,i,s,a;try{return(s=(n=(t=r.TurboModuleRegistry)==null?void 0:t.get)==null?void 0:n.call(t,e))!=null?s:(i=r.NativeModules)==null?void 0:i[e]}catch{return(a=r.NativeModules)==null?void 0:a[e]}}var lt=["interstitial","rewarded","rewarded_interstitial","app_open"];function ht(r,e,t){var u,l,S,E;if(!t)try{t=(D(),L(P))}catch{return{coverage:{},stop:()=>{}}}let n=[],i={},s=(c,f,g=v=>v)=>v=>{try{let b=c(v);b&&f(b,g(v))}catch{}},a=c=>{var f,g;return(g=_((f=_(c))==null?void 0:f.body))==null?void 0:g.data};if(r.admob){i.admob=[];for(let[g,v]of Object.entries(d.GMA_FULLSCREEN_CHANNELS)){let b=(u=t.DeviceEventEmitter)==null?void 0:u.addListener(g,s(k=>ke(g,k),e.admob,a));b&&(n.push(b),i.admob.push(v))}let c=Ee(t,"RNGoogleMobileAdsNativeModule"),f=s(we,e.admob);try{if(c&&typeof c.onAdEvent=="function")n.push(c.onAdEvent(f)),i.admob.push("native");else if(c&&t.NativeEventEmitter){let g=new t.NativeEventEmitter(((l=t.Platform)==null?void 0:l.OS)==="ios"?c:void 0);n.push(g.addListener("RNGMANativeAdEvent",f)),i.admob.push("native")}}catch{}}if(r.applovinMax){let c=Ee(t,"AppLovinMAX");if(c&&t.NativeEventEmitter)try{let f=[...d.MAX_RN_REVENUE_EVENTS];try{let v=(E=(S=c.getConstants)==null?void 0:S.call(c))!=null?E:{},b=Object.keys(v).filter(k=>/^ON_.*_AD_REVENUE_PAID$/.test(k)).map(k=>v[k]).filter(k=>typeof k=="string");b.length&&(f=[...new Set([...b,...f])])}catch{}let g=new t.NativeEventEmitter(c);for(let v of f)n.push(g.addListener(v,s(Ne,e.applovinMax)));i.applovinMax=[...lt]}catch{}}return{coverage:i,stop:()=>{for(let c of n.splice(0))try{c.remove()}catch{}}}}});var Ge=T(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.Traqio=o.Client=o.AdRevenueGate=o.watchReactNativeAds=o.fromMaxAdInfo=o.fromGoogleMobileAdsPaid=o.fromGoogleMobileAdsNativeAd=o.fromGoogleMobileAdsChannel=o.fromCapacitorAdMob=o.MAX_RN_REVENUE_EVENTS=o.MAX_RN_MIN_VERSION=o.GMA_MIN_VERSION=o.GMA_FULLSCREEN_CHANNELS=o.CAPACITOR_ADMOB_PAID_EVENTS=o.isTrackingUrl=o.isOpenUrl=o.reportAdServicesToken=o.Skan=o.SDK_VERSION=void 0;o.normalizeAdvertisingId=Fe;o.fromMaxAd=V;o.detectDebug=qe;o.isLocalPage=Ke;var ft=j(),pt=X(),I=H(),U=Z();o.SDK_VERSION="0.5.0";var mt=j();Object.defineProperty(o,"Skan",{enumerable:!0,get:function(){return mt.Skan}});var gt=X();Object.defineProperty(o,"reportAdServicesToken",{enumerable:!0,get:function(){return gt.reportAdServicesToken}});var Ve=H();Object.defineProperty(o,"isOpenUrl",{enumerable:!0,get:function(){return Ve.isOpenUrl}});Object.defineProperty(o,"isTrackingUrl",{enumerable:!0,get:function(){return Ve.isTrackingUrl}});var m=Z();Object.defineProperty(o,"CAPACITOR_ADMOB_PAID_EVENTS",{enumerable:!0,get:function(){return m.CAPACITOR_ADMOB_PAID_EVENTS}});Object.defineProperty(o,"GMA_FULLSCREEN_CHANNELS",{enumerable:!0,get:function(){return m.GMA_FULLSCREEN_CHANNELS}});Object.defineProperty(o,"GMA_MIN_VERSION",{enumerable:!0,get:function(){return m.GMA_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_MIN_VERSION",{enumerable:!0,get:function(){return m.MAX_RN_MIN_VERSION}});Object.defineProperty(o,"MAX_RN_REVENUE_EVENTS",{enumerable:!0,get:function(){return m.MAX_RN_REVENUE_EVENTS}});Object.defineProperty(o,"fromCapacitorAdMob",{enumerable:!0,get:function(){return m.fromCapacitorAdMob}});Object.defineProperty(o,"fromGoogleMobileAdsChannel",{enumerable:!0,get:function(){return m.fromGoogleMobileAdsChannel}});Object.defineProperty(o,"fromGoogleMobileAdsNativeAd",{enumerable:!0,get:function(){return m.fromGoogleMobileAdsNativeAd}});Object.defineProperty(o,"fromGoogleMobileAdsPaid",{enumerable:!0,get:function(){return m.fromGoogleMobileAdsPaid}});Object.defineProperty(o,"fromMaxAdInfo",{enumerable:!0,get:function(){return m.fromMaxAdInfo}});Object.defineProperty(o,"watchReactNativeAds",{enumerable:!0,get:function(){return m.watchReactNativeAds}});Object.defineProperty(o,"AdRevenueGate",{enumerable:!0,get:function(){return m.AdRevenueGate}});var vt="traq_install_sent",yt="traq_install_sent_debug",Re="traq_install_attempts",Me="traq_referrer",Te="traq_queue",De="traq_ad_queue",Oe="traq_device_id",Ce="traq_last_session",xe="traq_erased",w="traq_deferred_link",ee="traq_deferred_consent_retry_until",_t=60*6e4,Le="traq_consent",At=20,St=new Set([400,413,422]),Pe=500,Et=100,Ue=1e3,te=1e3,bt=300*1e3,It=3e3,kt=3,wt=1800*1e3,Nt={exact:"precise",publisher_defined:"publisher_provided",estimated:"estimated"},Rt={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"},Mt="00000000-0000-0000-0000-000000000000";function Fe(r){if(typeof r!="string")return;let e=r.trim();if(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(e))return e===Mt?void 0:e}function V(r){var e,t,n;if(typeof r.revenue=="number"&&Number.isFinite(r.revenue)&&r.revenue>=0)return{valueMicros:Math.round(r.revenue*1e6),currency:"USD",precision:(t=Nt[(e=r.revenuePrecision)!=null?e:""])!=null?t:"unknown",adUnitId:r.adUnitId,adFormat:Rt[((n=r.format)!=null?n:"").toUpperCase()],adSourceName:r.networkName,ts:r.ts}}function O(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})}function Tt(){try{return Intl.DateTimeFormat().resolvedOptions().locale}catch{return}}function Dt(){var r;try{let e=(D(),L(P)),t=(r=e==null?void 0:e.default)!=null?r:e;if(typeof(t==null?void 0:t.getItem)=="function"&&typeof(t==null?void 0:t.setItem)=="function")return{getItem:n=>t.getItem(n),setItem:(n,i)=>t.setItem(n,i)}}catch{}}var F=class{constructor(){this.queue=[],this.adQueue=[],this.adGate=new U.AdRevenueGate,this.adBatchId=null,this.context={sdkVersion:o.SDK_VERSION},this.referrer=null,this.started=!1,this.flushing=!1,this.flushTimer=null,this.retryMs=te,this.skan=new ft.Skan,this.erased=!1,this.deepLinkListeners=new Set,this.undelivered=[],this.deferred=null,this.consent=null,this.debug=!1,this.maxRevenuePaid=e=>{try{let t=(0,U.fromMaxAdInfo)(e),n=t&&V(t);n&&this.adGate.helper("applovinMax",n.adFormat,e,"Traqio.maxRevenuePaid")&&this.queueAdRevenue(n,"applovin_max","auto")}catch{}}}get isDebug(){return this.debug}async init(e){var t;if(!this.started&&(this.started=!0,this.opts={collectContext:!0,...e,storage:(t=e.storage)!=null?t:Dt()},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 qe(e),await this.restoreConsent(e.consent),await this.restoreQueue(),await this.restoreAdQueue(),await this.buildContext(),!await this.restoreErased())){if(!this.isWeb){let n=!!this.opts.storage&&!await this.opts.storage.getItem(this.installSentKey).catch(()=>"1");await this.sendInstallOnce(),this.opts.deepLinking!==!1&&(this.deferred=this.resolveDeferredOnce(n).then(i=>i!=null?i:this.retryDeferredWithConsent()),this.wireDeepLinks())}await this.maybeStartSession(!this.isWeb),await this.initSkan(),await this.initAppleAds(),this.wireLifecycle(),this.wireAdRevenue(),(this.queue.length||this.adQueue.length)&&this.scheduleFlush(0)}}wireAdRevenue(){var n,i;let e=this.opts.adRevenue;if(!e||this.isWeb||!(e.admob||e.applovinMax))return;let t={admob:(s,a)=>{this.adGate.first(a)&&this.queueAdRevenue(s,"admob","auto")},applovinMax:(s,a)=>{let u=V(s);u&&this.adGate.first(a)&&this.queueAdRevenue(u,"applovin_max","auto")}};try{let s=(n=this.opts.native)!=null&&n.watchAdRevenue?(i=this.opts.native.watchAdRevenue(e,t))!=null?i:e:(0,U.watchReactNativeAds)(e,t).coverage;this.adGate.arm(s)}catch{}}track(e,t){var i,s;if(!this.started||this.erased)return;let n=((i=t==null?void 0:t.transactionId)==null?void 0:i.trim())||void 0;this.enqueue({name:e,eventId:O(),value:t==null?void 0:t.value,currency:t==null?void 0:t.currency,...n?{transactionId:n,store:(s=t==null?void 0:t.store)!=null?s:this.defaultStore()}:{}}),this.skan.markEvent(e),t!=null&&t.value&&this.skan.addRevenue(t.value)}defaultStore(){var t;let e=(t=this.opts.native)==null?void 0:t.platform;return e==="ios"?"app_store":e==="android"?"play_store":void 0}trackAdRevenue(e){this.adGate.manual("admob","trackAdRevenue")&&this.queueAdRevenue(e,"admob","manual")}trackMaxAdRevenue(e){if(!this.adGate.manual("applovinMax","trackMaxAdRevenue"))return;let t=V(e);t&&this.queueAdRevenue(t,"applovin_max","manual")}admobPaid(e,t="banner"){return n=>{try{let i=(0,U.fromGoogleMobileAdsPaid)(n,{adUnitId:e,adFormat:t});i&&this.adGate.helper("admob",t,n,"Traqio.admobPaid()")&&this.queueAdRevenue(i,"admob","auto")}catch{}}}queueAdRevenue(e,t,n){var i;!this.started||this.erased||!(e.valueMicros>=0)||!e.currency||(this.adQueue.push({...e,source:t,origin:n,impressionId:O(),ts:(i=e.ts)!=null?i:Math.floor(Date.now()/1e3)}),this.skan.addRevenue(e.valueMicros/1e6),this.adQueue.length>Ue&&this.adQueue.splice(0,this.adQueue.length-Ue),this.persistAdQueue(),this.scheduleFlush())}getInstallReferrer(){return this.started?this.readReferrer():Promise.resolve({status:"unavailable",retryable:!1})}onDeepLink(e){this.deepLinkListeners.add(e);let t=this.undelivered.splice(0);for(let n of t)e(n);return()=>{this.deepLinkListeners.delete(e)}}async handleUrl(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!(0,I.isTrackingUrl)(e))return null;let t=await this.postJson({url:e},"/deeplink/open"),n=(0,I.isOpenUrl)(e),i=(0,I.toDeepLink)(t,n,e);return i&&n&&await this.keepDeferred(i),i&&this.emitDeepLink(i),i}getDeferredDeepLink(){var e;return(e=this.deferred)!=null?e:Promise.resolve(null)}async redeemDeepLinkCode(e){if(!this.started||this.erased||this.opts.deepLinking===!1||!e.trim())return null;let t=await this.postJson({code:e},"/deeplink/code"),n=(0,I.toDeepLink)(t,!0);return n?(await this.keepDeferred(n),this.emitDeepLink(n),n):null}async forgetMe(){return this.started?this.erased?!0:await this.post({deviceId:this.context.deviceId,appUserId:this.opts.userId},"/privacy/forget")?(await this.markErased(),!0):!1:!1}async setConsent(e){var t,n;this.consent=e?"granted":"denied",await((n=(t=this.opts)==null?void 0:t.storage)==null?void 0:n.setItem(Le,this.consent).catch(()=>{})),e&&this.deferred&&!this.erased&&(this.deferred=this.deferred.then(i=>i!=null?i:this.retryDeferredWithConsent()),await this.deferred)}get forgotten(){return this.erased}setUserId(e){this.opts&&(this.opts.userId=e)}flush(){this.erased||(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.drain())}appOpened(){!this.started||this.erased||this.maybeStartSession()}get skanMapping(){return this.skan.activeMapping}async initAppleAds(){if(this.opts.appleAds===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.getAttributionToken||await(0,pt.reportAdServicesToken)({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,deviceId:this.context.deviceId,userId:this.opts.userId,storage:this.opts.storage,native:{getAttributionToken:()=>e.getAttributionToken()},debug:this.debug})}async initSkan(){if(this.opts.skan===!1)return;let e=this.opts.native;(e==null?void 0:e.platform)!=="ios"||!e.updateConversionValue||await this.skan.init({endpoint:this.opts.endpoint,sdkKey:this.opts.sdkKey,storage:this.opts.storage,native:{updateConversionValue:(t,n,i)=>{var s;return(s=e.updateConversionValue)==null?void 0:s.call(e,t,n,i)}}})}async resolveDeferredOnce(e){var l,S;let t=this.opts.storage;try{let E=await(t==null?void 0:t.getItem(w));if(E)return(0,I.upgradeStoredDeepLink)(JSON.parse(E))}catch{}if(!e&&!await(t==null?void 0:t.getItem(`${w}_pending`).catch(()=>null)))return null;let n=(S=(l=this.opts.native)==null?void 0:l.platform)!=null?S:"android",i=n==="android"?await this.readReferrer():null;await(t==null?void 0:t.setItem(`${w}_pending`,"1").catch(()=>{}));let s=await this.askDeferred(n,i==null?void 0:i.referrer);if(!s)return null;let a=(0,I.toDeepLink)(s,!0),u=await this.storedDeferred();if(u)return u;try{await(t==null?void 0:t.setItem(w,JSON.stringify(a))),!a&&this.consent!=="granted"&&await(t==null?void 0:t.setItem(ee,String(Date.now()+_t)))}catch{}return a&&this.emitDeepLink(a),a}askDeferred(e,t){return this.postJson({platform:e,installReferrer:t,...this.consent?{consent:this.consent}:{},...this.context.osVersion?{osVersion:this.context.osVersion}:{},...this.context.deviceModel?{deviceModel:this.context.deviceModel}:{}},"/deeplink/deferred")}async retryDeferredWithConsent(){var s,a,u,l;let e=(s=this.opts)==null?void 0:s.storage;if(!e||this.consent!=="granted"||this.opts.deepLinking===!1||this.isWeb)return null;let t=Number(await e.getItem(ee).catch(()=>null));if(!t||(await e.setItem(ee,"").catch(()=>{}),Date.now()>t))return null;let n=await this.storedDeferred();if(n)return n;let i=(0,I.toDeepLink)(await this.askDeferred((u=(a=this.opts.native)==null?void 0:a.platform)!=null?u:"ios",void 0),!0);return i?(await((l=this.opts.storage)==null?void 0:l.setItem(w,JSON.stringify(i)).catch(()=>{})),this.emitDeepLink(i),i):null}async storedDeferred(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(w));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(w,JSON.stringify(e)).catch(()=>{})),this.deferred=Promise.resolve(e))}emitDeepLink(e){if(!this.deepLinkListeners.size){this.undelivered.push(e);return}for(let t of this.deepLinkListeners)try{t(e)}catch{}}wireDeepLinks(){try{let{Linking:e}=(D(),L(P));if(!e)return;e.getInitialURL().then(t=>t&&this.handleUrl(t)).catch(()=>{}),e.addEventListener("url",({url:t})=>{this.handleUrl(t)})}catch{}}get isWeb(){var e;return((e=this.opts)==null?void 0:e.platform)==="web"}get installSentKey(){return this.debug?yt:vt}debugField(){return this.debug?{debug:!0}:{}}wireLifecycle(){let e={background:()=>this.flush(),foreground:()=>this.appOpened()};if(this.opts.lifecycle){this.opts.lifecycle(e);return}try{let{AppState:t}=(D(),L(P));t.addEventListener("change",n=>{if(n!=="active"){this.scheduleFlush(0);return}this.maybeStartSession()})}catch{}}async restoreErased(){var e;try{this.erased=await((e=this.opts.storage)==null?void 0:e.getItem(xe))==="1"}catch{this.erased=!1}return this.erased}async markErased(){var e;this.erased=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue=[],this.adQueue=[],this.adBatchId=null,await this.persistQueue(),await this.persistAdQueue();try{await((e=this.opts.storage)==null?void 0:e.setItem(xe,"1"))}catch{}}enqueue(e){this.queue.push(e),this.queue.length>Pe&&this.queue.splice(0,this.queue.length-Pe),this.persistQueue(),this.scheduleFlush()}async restoreQueue(){var e;try{let t=await((e=this.opts.storage)==null?void 0:e.getItem(Te));t&&(this.queue=JSON.parse(t))}catch{}}async persistQueue(){var e;try{await((e=this.opts.storage)==null?void 0:e.setItem(Te,JSON.stringify(this.queue)))}catch{}}async restoreAdQueue(){var e,t,n;try{let i=await((e=this.opts.storage)==null?void 0:e.getItem(De));if(!i)return;let s=JSON.parse(i);this.adQueue=(t=s.items)!=null?t:[],this.adBatchId=(n=s.batchId)!=null?n:null}catch{}}async persistAdQueue(){var e;try{let t={batchId:this.adBatchId,items:this.adQueue};await((e=this.opts.storage)==null?void 0:e.setItem(De,JSON.stringify(t)))}catch{}}async maybeStartSession(e=!1){var s,a,u;if(this.erased)return;let t=Date.now();if(!e){let l=Number(await((s=this.opts.storage)==null?void 0:s.getItem(Ce).catch(()=>null)))||0;if(l&&t-l<wt)return}let n=(a=this.context.deviceId)!=null?a:await this.getOrCreateDeviceId();if(await this.post({deviceId:n,appUserId:this.opts.userId,sessionId:O(),ts:Math.floor(t/1e3),context:this.context},"/ingest/session"))try{await((u=this.opts.storage)==null?void 0:u.setItem(Ce,String(t)))}catch{}}async buildContext(){var t,n,i;if(!this.opts.collectContext){this.context={sdkVersion:o.SDK_VERSION};return}let e={};try{e=(i=await((n=(t=this.opts.native)==null?void 0:t.getContext)==null?void 0:n.call(t)))!=null?i:{}}catch{}this.context={deviceId:await this.getOrCreateDeviceId(),deviceModel:e.deviceModel,osVersion:e.osVersion,appVersion:this.opts.appVersion,locale:Tt(),sdkVersion:o.SDK_VERSION}}async getOrCreateDeviceId(){var t,n;try{let i=await((t=this.opts.storage)==null?void 0:t.getItem(Oe));if(i)return i}catch{}let e=O();try{await((n=this.opts.storage)==null?void 0:n.setItem(Oe,e))}catch{}return e}async readReferrer(){var n,i;if(this.referrer)return this.referrer;try{let s=await((n=this.opts.storage)==null?void 0:n.getItem(Me));if(s)return this.referrer=JSON.parse(s)}catch{}let e=this.opts.native;if((e==null?void 0:e.platform)!=="android")return{status:e?"not_supported_platform":"unavailable",retryable:!1};let t=await e.getInstallReferrer().catch(()=>({status:"error",retryable:!0}));if(!t.retryable){this.referrer=t;try{await((i=this.opts.storage)==null?void 0:i.setItem(Me,JSON.stringify(t)))}catch{}}return t}async readAdvertisingId(){var e;if(!(!this.opts.collectAdvertisingId||!((e=this.opts.native)!=null&&e.getAdvertisingId)))try{return Fe(await this.opts.native.getAdvertisingId())}catch{return}}async sendInstallOnce(){var s,a;let e=this.opts.storage;if(e&&await e.getItem(this.installSentKey))return;let t=(a=(s=this.opts.native)==null?void 0:s.platform)!=null?a:"android",n=await this.readReferrer();if(n.retryable&&e){let u=Number(await e.getItem(Re))||0;if(u+1<kt){await e.setItem(Re,String(u+1));return}}await this.post({install:{platform:t,installReferrer:n.referrer,appUserId:this.opts.userId,advertisingId:await this.readAdvertisingId(),context:this.context}})&&await(e==null?void 0:e.setItem(this.installSentKey,"1"))}scheduleFlush(e=It){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain()},e))}async drain(){var e;if(!this.erased&&!(this.flushing||!this.queue.length&&!this.adQueue.length)){this.flushing=!0;try{for(;this.queue.length;){let t=this.queue.slice(0,At),n=await this.send({events:t,appUserId:this.opts.userId,deviceId:this.context.deviceId});if(n==="retry")return this.backOff();n==="refused"&&console.warn(`[traqio] the server refused ${t.length} event(s) as malformed \u2014 dropped, not retried`),this.queue.splice(0,t.length),await this.persistQueue(),this.retryMs=te}for(;this.adQueue.length;){let t=(e=this.adQueue[0].source)!=null?e:"admob",n=this.adQueue.findIndex(a=>{var u;return((u=a.source)!=null?u:"admob")!==t}),i=this.adQueue.slice(0,Math.min(Et,n===-1?this.adQueue.length:n));if(this.adBatchId||(this.adBatchId=O(),await this.persistAdQueue()),!await this.post({batchId:this.adBatchId,source:t,environment:this.opts.testAds?"TEST":"PRODUCTION",deviceId:this.context.deviceId,appUserId:this.opts.userId,impressions:i.map(({source:a,...u})=>u)},"/ingest/ad-revenue"))return this.backOff();this.adQueue.splice(0,i.length),this.adBatchId=null,await this.persistAdQueue(),this.retryMs=te}}finally{this.flushing=!1}}}backOff(){this.retryMs=Math.min(this.retryMs*2,bt),this.scheduleFlush(this.retryMs)}async postJson(e,t){try{let n=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...this.debugField()}),...this.keepalive()});return n.ok?await n.json():null}catch{return null}}async restoreConsent(e){var n;if(e!==void 0)return this.setConsent(e);if(this.consent)return this.setConsent(this.consent==="granted");let t=await((n=this.opts.storage)==null?void 0:n.getItem(Le).catch(()=>null));(t==="granted"||t==="denied")&&(this.consent=t)}keepalive(){return this.isWeb?{keepalive:!0}:{}}async post(e,t="/ingest"){return await this.send(e,t)==="ok"}async send(e,t="/ingest"){let n=this.consent&&(t==="/ingest"||t==="/ingest/session")?{consent:this.consent}:{};try{let i=await fetch(`${this.opts.endpoint}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdkKey:this.opts.sdkKey,...e,...n,...this.debugField()}),...this.keepalive()});return i.ok?"ok":St.has(i.status)?"refused":"retry"}catch{return"retry"}}};o.Client=F;async function qe(r){var e,t;if(r.debug!==void 0)return r.debug;if(r.platform==="web")return Ke();if(globalThis.__DEV__===!0)return!0;try{return await((t=(e=r.native)==null?void 0:e.isDebugBuild)==null?void 0:t.call(e))===!0}catch{return!1}}function Ke(r=globalThis.location){if(!r)return!1;if(r.protocol==="file:")return!0;let e=r.hostname.toLowerCase().replace(/^\[|\]$/g,"");return e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e==="::1"||e==="0.0.0.0"||/^127\.\d+\.\d+\.\d+$/.test(e)}o.Traqio=new F});var Be=Ze(Ge(),1);var re="traq_";function ie(){return typeof document=="undefined"?void 0:document}function C(r){let e=ie();if(!e)return null;for(let t of e.cookie?e.cookie.split(";"):[]){let n=t.indexOf("=");if(!(n<0)&&t.slice(0,n).trim()===r)try{return decodeURIComponent(t.slice(n+1).trim())}catch{return null}}return null}function ne(r,e,t,n){let i=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",s=n?`; Domain=${n}`:"";return`${r}=${encodeURIComponent(e)}; Max-Age=${Math.floor(t)}; Path=/${s}; SameSite=Lax${i}`}function We(r){let e=ie();if(!e||!r.includes(".")||/^[\d.]+$/.test(r)||r.includes(":"))return null;let t=r.split("."),n=`${re}probe`;for(let i=t.length-2;i>=0;i--){let s=t.slice(i).join(".");if(e.cookie=ne(n,"1",10,s),C(n)==="1")return e.cookie=ne(n,"",0,s),s}return null}function R(r,e,t,n){let i=ie();if(i)try{i.cookie=ne(r,e,t,n)}catch{}}function x(r,e){R(r,"",0,e)}var G="traq_device_id",se=new Set([G]),Ot=395*24*60*60;function q(){try{return typeof localStorage=="undefined"?void 0:localStorage}catch{return}}var K=class{constructor(e,t,n){this.persistent=e;this.cookieDomain=t;this.cookies=n;this.memory=new Map}get isPersistent(){return this.persistent}async getItem(e){return this.getSync(e)}async setItem(e,t){this.setSync(e,t)}getSync(e){var n,i,s;if(this.memory.has(e))return(n=this.memory.get(e))!=null?n:null;if(!this.persistent)return null;let t=null;try{t=(s=(i=q())==null?void 0:i.getItem(e))!=null?s:null}catch{}return t===null&&this.cookies&&se.has(e)&&(t=C(e)),t}setSync(e,t){if(!this.persistent){this.memory.set(e,t);return}let n=!1;try{let i=q();i&&(i.setItem(e,t),n=!0)}catch{}n||this.memory.set(e,t),this.cookies&&se.has(e)&&R(e,t,Ot,this.cookieDomain())}removeSync(e){var t;this.memory.delete(e);try{(t=q())==null||t.removeItem(e)}catch{}this.cookies&&x(e,this.cookieDomain())}enable(){if(this.persistent)return;this.persistent=!0;let e=[...this.memory];this.memory.clear();for(let[t,n]of e)this.setSync(t,n)}disable(){if(!this.persistent)return;let e=q(),t=[];try{for(let n=0;e&&n<e.length;n++){let i=e.key(n);i&&i.startsWith(re)&&t.push(i)}}catch{}for(let n of se)t.includes(n)||t.push(n);for(let n of t){let i=this.getSync(n);i!==null&&this.memory.set(n,i)}this.persistent=!1;for(let n of t){try{e==null||e.removeItem(n)}catch{}this.cookies&&x(n,this.cookieDomain())}}};var M=class{constructor(e,t,n,i,s){this.store=e;this.key=t;this.cookieDomain=n;this.cookies=i;this.valid=s}get(e=Date.now()){let t=this.store.getSync(this.key);if(t)try{let n=JSON.parse(t);if(n&&typeof n.id=="string"&&n.exp>e)return n.id}catch{}if(this.cookies&&this.store.isPersistent){let n=C(this.key);if(n&&this.valid(n))return n}return null}set(e,t,n=Date.now()){let i={id:e,exp:n+t};this.store.setSync(this.key,JSON.stringify(i)),this.cookies&&this.store.isPersistent&&R(this.key,e,t/1e3,this.cookieDomain())}clear(){this.store.removeSync(this.key),this.cookies&&x(this.key,this.cookieDomain())}persistCookie(e=Date.now()){let t=this.store.getSync(this.key);if(!(!t||!this.cookies||!this.store.isPersistent))try{let n=JSON.parse(t);n.exp>e&&R(this.key,n.id,(n.exp-e)/1e3,this.cookieDomain())}catch{}}};var Ct="traq_src",xt=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","gclid","fbclid","ttclid"],Lt=200,Pt={utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",fbclid:"fbclid",ttclid:"ttclid",referrer:"referrer"},ue=r=>{let e=r==null?void 0:r.trim();return e?e.slice(0,Lt):null},ae=r=>r.toLowerCase().replace(/^www\./,"");function Ut(r,e){let t=ae(r),n=ae(e);return t===n||t.endsWith(`.${n}`)||n.endsWith(`.${t}`)}function Vt(r,e){if(!r)return null;try{let t=new URL(r);return t.protocol!=="http:"&&t.protocol!=="https:"||Ut(new URL(e).hostname,t.hostname)?null:ue(ae(t.hostname))}catch{return null}}function Ft(r,e,t){let n=new URLSearchParams;try{let a=new URL(r).searchParams;for(let u of xt){let l=ue(a.get(u));l&&n.set(u,l)}}catch{return null}let i=n.toString()!=="",s=Vt(e,r);return s&&n.set("referrer",s),n.toString()===""?null:(n.set("ts",String(t)),{query:n.toString(),fromUrl:i})}function oe(r){let e;try{e=new URLSearchParams(r)}catch{return null}let t={};for(let[i,s]of Object.entries(Pt)){let a=ue(e.get(i));a&&(t[s]=a)}if(!Object.keys(t).length)return null;let n=Number(e.get("ts"));return Number.isFinite(n)&&n>0&&(t.landedAt=n),t}var W=class{constructor(e,t,n,i){this.maxAgeMs=t;this.kept=new M(e,Ct,n,i,s=>oe(s)!==null)}capture(e,t,n=Date.now()){let i=Ft(e,t,n);return!i||!i.fromUrl&&this.kept.get(n)!==null?null:(this.kept.set(i.query,this.maxAgeMs,n),oe(i.query))}get(e=Date.now()){let t=this.kept.get(e);return t===null?null:oe(t)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var qt="traq_click",Kt="traq_click",Ye=/^[A-Za-z0-9_-]{8,64}$/;function Gt(r){try{let e=new URL(r).searchParams.get(qt);return e&&Ye.test(e)?e:null}catch{return null}}var Y=class{constructor(e,t,n,i){this.maxAgeMs=t;this.kept=new M(e,Kt,n,i,s=>Ye.test(s))}capture(e,t=Date.now()){let n=Gt(e);return n&&this.kept.set(n,this.maxAgeMs,t),n}get(e=Date.now()){return this.kept.get(e)}clear(){this.kept.clear()}persistCookie(e=Date.now()){this.kept.persistCookie(e)}};var Wt="https://api.traqio.app",Yt=30,Bt=1440*60*1e3;function $t(){return typeof window!="undefined"&&typeof document!="undefined"}function jt(){try{return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():null}catch{return null}}var ce=class{constructor(){this.core=new Be.Client;this.store=null;this.trackIds=null;this.sources=null;this.waitForConsent=!1;this.started=!1}async init(e){var l,S,E;if(this.started||!$t())return;this.started=!0,this.waitForConsent=e.waitForConsent===!0;let t=e.cookies!==!1,n,i=()=>n===void 0?n=We(location.hostname):n,s=(l=e.consent)!=null?l:this.earlyConsent,a=!this.waitForConsent||s===!0;this.store=new K(a,i,t);let u=((S=e.trackIdDays)!=null?S:Yt)*Bt;if(this.trackIds=new Y(this.store,u,i,t),this.trackIds.capture(location.href),this.sources=new W(this.store,u,i,t),this.sources.capture(location.href,document.referrer),!this.store.getSync(G)){let c=jt();c&&this.store.setSync(G,c)}await this.core.init({sdkKey:e.sdkKey,endpoint:((E=e.endpoint)!=null?E:Wt).replace(/\/+$/,""),storage:this.store,platform:"web",userId:e.userId,consent:s,debug:e.debug,lifecycle:({background:c,foreground:f})=>{document.addEventListener("visibilitychange",()=>document.visibilityState==="hidden"?c():f()),window.addEventListener("pagehide",c)}})}get isDebug(){return this.core.isDebug}track(e,t){this.core.track(e,t)}setUserId(e){this.core.setUserId(e)}async setConsent(e){var t,n;this.started||(this.earlyConsent=e),this.store&&this.waitForConsent&&(e?(this.store.enable(),(t=this.trackIds)==null||t.persistCookie(),(n=this.sources)==null||n.persistCookie()):this.store.disable()),await this.core.setConsent(e)}getTrackId(){var e,t;return(t=(e=this.trackIds)==null?void 0:e.get())!=null?t:null}getSource(){var e,t;return(t=(e=this.sources)==null?void 0:e.get())!=null?t:null}async forgetMe(){var t,n;let e=await this.core.forgetMe();return e&&((t=this.trackIds)==null||t.clear(),(n=this.sources)==null||n.clear()),e}flush(){this.core.flush()}get forgotten(){return this.core.forgotten}},de=new ce;window.Traqio=de;var A=document.currentScript,$e=A==null?void 0:A.dataset.sdkKey;$e&&de.init({sdkKey:$e,endpoint:(A==null?void 0:A.dataset.endpoint)||void 0,waitForConsent:(A==null?void 0:A.dataset.waitForConsent)==="true"});})();
2
2
  //# sourceMappingURL=traqio.min.js.map