@topsort/analytics.js
Advanced tools
| // Re-export types from detector | ||
| export type { EventType } from "./detector"; | ||
| // Re-export types and classes from queue | ||
| export type { ProcessorResult, Entry, Processor } from "./queue"; | ||
| export { Queue } from "./queue"; | ||
| // Re-export utility functions from set | ||
| export { truncateSet } from "./set"; | ||
| // Re-export types and classes from store | ||
| export type { Store } from "./store"; | ||
| export { MemoryStore, LocalStorageStore, BidStore } from "./store"; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| (function(f){typeof define=="function"&&define.amd?define(f):f()})(function(){"use strict";var f=Object.defineProperty,d=(e,t)=>f(e,"name",{value:t,configurable:!0}),H="https://api.topsort.com",_={auctions:"v2/auctions",events:"v2/events"},I="0.3.1",E=class{constructor(t,s,r,n=!1){this.status=t,this.statusText=s,this.body=r,this.retry=n}};d(E,"AppError");var j=E,u=j,T=class{async handleResponse(t){let s;if(t.status!==204&&(s=await t.json()),!t.ok){let r=t.status===429||t.status>=500;throw new u(t.status,t.statusText,s,r)}return s}async request(t,s){try{let r=this.sanitizeUrl(t),n=await fetch(r,s);return this.handleResponse(n)}catch(r){let n=r instanceof Error?r.message:"Unknown error";throw new u(500,"Internal Server Error",n)}}setupTimeoutSignal(t){if(t.timeout!=null){let s=new AbortController;return setTimeout(()=>s.abort(),t.timeout),s.signal}}async post(t,s,r){let n=this.setupTimeoutSignal(r);return this.request(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-UA":r.userAgent?`@topsort/sdk ${I} ${r.userAgent}`:`@topsort/sdk ${I}`,Authorization:`Bearer ${r.apiKey}`},body:JSON.stringify(s),signal:n})}sanitizeUrl(t){try{return new URL(t).href.replace(/\/+$/,"")}catch(s){throw new u(400,"Invalid URL",{error:`Invalid URL: ${s}`})}}};d(T,"APIClient");var B=T,b=new B;function v(e){var t;if(!((t=e==null?void 0:e.apiKey)!=null&&t.length))throw new u(401,"API Key is required.",{})}d(v,"validateConfig");function y(e){return async(...t)=>{let s=t[t.length-1];return v(s),e(...t)}}d(y,"withValidation");async function k(e,t){let s=`${t.host}/${_.auctions}`;return await b.post(s.toString(),e,t)}d(k,"handler");var D=y(k);async function O(e,t){try{let s=`${t.host}/${_.events}`;return await b.post(s,e,t),{ok:!0,retry:!1}}catch(s){if(s instanceof u&&s.retry)return{ok:!1,retry:!0};throw s}}d(O,"handler");var K=y(O),A=class{constructor(t){this.config=t,this.config.host=this.config.host??H}async reportEvent(t){return K(t,this.config)}async createAuction(t){return D(t,this.config)}};d(A,"TopsortClient");var X=A,z=X;const J="2.5.0";class P{constructor(){this._data=[]}get(){return this._data}set(t){this._data=t}}class M{constructor(t){this._key=t,this._storage=window.localStorage}get(){const t=this._storage.getItem(this._key);return t?JSON.parse(t):[]}set(t){this._storage.setItem(this._key,JSON.stringify(t))}}class Y{constructor(t){this._key=t,this._storage=window.sessionStorage,this._bid=void 0}get(){try{return this._storage.getItem(this._key)??void 0}catch{return this._bid}}set(t){this._bid=t;try{this._storage.setItem(this._key,t)}catch{}}}const G="ts-t",Z="ts-q",V=250,W=3,F=25,Q=250,U=9,tt=0;function et(e,t){return t>0?e+(Math.random()+Math.pow(2,t))*1e3:0}function st(){var t;const e=new M(G);try{const s="3";if(e.set([{x:s}]),((t=e.get()[0])==null?void 0:t.x)===s)return new M(Z)}catch{}return new P}class rt{constructor(t){this._store=st(),this._processing=new Set,this._scheduled=!1,this._processor=t}append(t,s){let r=this._store.get();r.push({e:t,r:0,p:s!=null&&s.highPriority?U:tt}),r=r.slice(-V),this._setEntries(r)}async _processNow(t){if(!t.length)return;const s=[];for(let i=t.length-1;i>=0&&s.length<F;i--){const a=t[i],h=a==null?void 0:a.e;h&&!this._processing.has(h.id)&&et(h.t,a.r)<=Date.now()&&(s.push(h),this._processing.add(h.id))}if(!s.length){this._scheduleProcessing();return}let r={done:new Set,retry:new Set};try{r=await this._processor(s)}catch{for(const a of s)r.done.add(a.id)}const n=[];for(const i of this._processing)s.find(a=>a.id===i)||n.push(i);this._processing=new Set(n);const o=this._store.get(),c=[];for(const i of o)r.done.has(i.e.id)||(r.retry.has(i.e.id)?i.r<W&&(i.r+=1,c.push(i)):c.push(i));this._setEntries(c)}_setEntries(t){this._store.set(t),t.length&&(t.some(s=>s.p===U)||this._store instanceof P?this._processNow(t):this._scheduleProcessing())}_scheduleProcessing(){this._scheduled||(this._scheduled=!0,setTimeout(()=>{this._scheduled=!1,this._processNow(this._store.get())},Q))}}function nt(e,t){if(e.size<=t)return e;const s=e.values();for(let r=0;r<e.size-t;++r)s.next();return new Set(s)}const ot=2500,it=.5;let p=new Set;const C=new Y("ts-b");function N(){var e,t;return((t=(e=window.URL).createObjectURL)==null?void 0:t.call(e,new Blob).split("/").pop())||`${Math.random()}`}let l;function S(){if(l)return l;const e=at();if(e)return l=e,e;const t=N();return R(t),t}function R(e){const t=window.TS.cookieName||"tsuid";l=e,document.cookie=`${t}=${e};max-age=31536000`}function ct(){return l=void 0,document.cookie="tsuid=",S()}window.TS.setUserId=R,typeof window.TS.getUserId!="function"&&(window.TS.getUserId=S),window.TS.resetUserId=ct;function at(){var s;const e=window.TS.cookieName||"tsuid";return(s=new RegExp(`(^|;)\\s*${e}\\s*=\\s*([^;]+)`).exec(document.cookie))==null?void 0:s.pop()}function dt(e){const t=e.type,s={path:e.page};let r;e.product&&(r={type:"product",id:e.product});let n;e.additionalProduct&&(n={type:"product",id:e.additionalProduct});const o=new Date(e.t).toISOString();switch(t){case"Click":return{clicks:[{resolvedBidId:e.bid,entity:r,additionalAttribution:n,placement:s,occurredAt:o,opaqueUserId:e.uid,id:e.id}]};case"Impression":return{impressions:[{resolvedBidId:e.bid,entity:r,additionalAttribution:n,placement:s,occurredAt:o,opaqueUserId:e.uid,id:e.id}]};case"Purchase":return{purchases:[{occurredAt:o,opaqueUserId:e.uid,items:(e.items||[]).map(c=>({productId:c.product,quantity:c.quantity,unitPrice:c.price})),id:e.id}]}}}async function ut(e){const t={done:new Set,retry:new Set},s=[],r={apiKey:window.TS.token,host:window.TS.url,userAgent:`ts.js/${J}`},n=new z(r);for(const o of e)s.push(n.reportEvent(dt(o)).then(c=>{(c.retry?t.retry:t.done).add(o.id)}).catch(()=>{t.done.add(o.id)}));return await Promise.all(s),t}const lt=new rt(ut);function w(e,t){const s=ht(e);if(p.has(s))return;p.add(s),p=nt(p,ot),lt.append(e);const r=new CustomEvent("topsort",{bubbles:!0,detail:e});t.dispatchEvent(r)}function ht(e){const t=JSON.stringify(e.items||[]);return[e.page,e.type,e.product??e.additionalProduct,e.bid,t].join("-")}function ft(){const e=window.location,t=e.hash;return t[1]==="/"?t:`${e.pathname}${e.search}`}function g(e,t){let s=t.dataset.tsProduct,r=t.dataset.tsResolvedBid,n;r==="inherit"&&s&&(e==="Click"||e==="Impression")&&(r=C.get(),n=s,s=void 0);const o={type:e,product:s,additionalProduct:n,bid:r,t:Date.now(),page:ft(),id:N(),uid:typeof window.TS.getUserId=="function"?window.TS.getUserId():S()};return e==="Purchase"&&(o.items=JSON.parse(t.dataset.tsItems||"[]")),o}function pt(e){if(!(e.currentTarget instanceof HTMLElement))return;const t=e.currentTarget.closest(L);if(t&&t instanceof HTMLElement){const s=g("Click",t);w(s,t),s.bid&&C.set(s.bid)}}const m=window.IntersectionObserver?new IntersectionObserver(e=>{for(const t of e)if(t.isIntersecting){const s=t.target;s instanceof HTMLElement&&(w(g("Impression",s),s),m&&m.unobserve(s))}},{threshold:it}):void 0,L="[data-ts-product],[data-ts-action],[data-ts-items],[data-ts-resolved-bid]";function wt(e){const t=e.querySelectorAll("[data-ts-clickable]");(t.length===0?[e]:t).forEach(r=>r.addEventListener("click",pt))}function $(e){gt(e)?w(g("Purchase",e),e):(m?m.observe(e):w(g("Impression",e),e),wt(e))}function q(e){const t=e.querySelectorAll(L);for(let s=0;s<t.length;s++){const r=t[s];r instanceof HTMLElement&&$(r)}}function gt(e){return e.dataset.tsAction==="purchase"}function mt(e){for(const t of e)if(t.type==="childList"){const s=new Set;for(let r=0;r<t.addedNodes.length;r++){const n=t.addedNodes[r];if((n==null?void 0:n.nodeType)===Node.ELEMENT_NODE){const o=n.parentElement;o&&!s.has(o)&&s.add(o)}for(const o of s)q(o)}}else if(t.type==="attributes"){if(!(t.target instanceof HTMLElement))continue;$(t.target)}}function x(){var s,r;if((s=window.TS)!=null&&s.loaded)return;if(window.TS.loaded=!0,!((r=window.TS)!=null&&r.token)){console.error("Missing TS token");return}q(document);const e=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;new e(mt).observe(document,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["data-ts-product","data-ts-action","data-ts-items","data-ts-resolved-bid"]})}/complete|interactive|loaded/.test(document.readyState)?x():window.addEventListener("DOMContentLoaded",x)}); | ||
| (function(h){typeof define=="function"&&define.amd?define(h):h()})((function(){"use strict";var h="https://api.topsort.com",m={auctions:"v2/auctions",events:"v2/events"},_="0.3.8";class M{status;statusText;body;retry;constructor(t,s,n,o=!1){this.status=t,this.statusText=s,this.body=n,this.retry=o}}var d=M;class R{async handleResponse(t){let s;if(t.status!==204&&(s=await t.json()),!t.ok){let n=t.status===429||t.status>=500;throw new d(t.status,t.statusText,s,n)}return s}async request(t,s){try{let n=this.sanitizeUrl(t),o=await fetch(n,s);return this.handleResponse(o)}catch(n){let o=n instanceof Error?n.message:"Unknown error";throw new d(500,"Internal Server Error",o)}}setupTimeoutSignal(t){if(t.timeout!=null){let s=new AbortController;return setTimeout(()=>s.abort(),t.timeout),s.signal}}async post(t,s,n){let o=this.setupTimeoutSignal(n),r=n.fetchOptions??{keepalive:!0};return this.request(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-UA":n.userAgent?`@topsort/sdk ${_} ${n.userAgent}`:`@topsort/sdk ${_}`,Authorization:`Bearer ${n.apiKey}`},body:JSON.stringify(s),signal:o,...r})}sanitizeUrl(t){try{return new URL(t).href.replace(/\/+$/,"")}catch(s){throw new d(400,"Invalid URL",{error:`Invalid URL: ${s}`})}}}var S=new R;function L(e){if(!e?.apiKey?.length)throw new d(401,"API Key is required.",{})}function I(e){return async(...t)=>{let s=t[t.length-1];return L(s),e(...t)}}async function C(e,t){let s=`${t.host}/${m.auctions}`;return await S.post(s.toString(),e,t)}var $=I(C);async function q(e,t){try{let s=`${t.host}/${m.events}`;return await S.post(s,e,t),{ok:!0,retry:!1}}catch(s){if(s instanceof d&&s.retry)return{ok:!1,retry:!0};throw s}}var x=I(q);class H{config;constructor(t){this.config=t,this.config.host=this.config.host??h}async reportEvent(t){return x(t,this.config)}async createAuction(t){return $(t,this.config)}}var B=H;const D="2.6.0";class T{constructor(){this._data=[]}get(){return this._data}set(t){this._data=t}}class E{constructor(t){this._key=t,this._storage=window.localStorage}get(){const t=this._storage.getItem(this._key);return t?JSON.parse(t):[]}set(t){this._storage.setItem(this._key,JSON.stringify(t))}}class K{constructor(t){this._key=t,this._storage=window.sessionStorage,this._bid=void 0}get(){try{return this._storage.getItem(this._key)??void 0}catch{return this._bid}}set(t){this._bid=t;try{this._storage.setItem(this._key,t)}catch{}}}const j="ts-t",z="ts-q",J=3,X=25,Y=250,b=9,G=0;function W(e,t){return t>0?e+(Math.random()+2**t)*1e3:0}function Z(){const e=new E(j);try{if(e.set([{x:"3"}]),e.get()[0]?.x==="3")return new E(z)}catch{}return new T}class F{constructor(t){this._store=Z(),this._processing=new Set,this._scheduled=!1,this._processor=t}append(t,s){let n=this._store.get();n.push({e:t,r:0,p:s?.highPriority?b:G}),n=n.slice(-250),this._setEntries(n)}async _processNow(t){if(!t.length)return;const s=[];for(let i=t.length-1;i>=0&&s.length<X;i--){const a=t[i],l=a?.e;l&&!this._processing.has(l.id)&&W(l.t,a.r)<=Date.now()&&(s.push(l),this._processing.add(l.id))}if(!s.length){this._scheduleProcessing();return}let n={done:new Set,retry:new Set};try{n=await this._processor(s)}catch{for(const a of s)n.done.add(a.id)}const o=[];for(const i of this._processing)s.find(a=>a.id===i)||o.push(i);this._processing=new Set(o);const r=this._store.get(),c=[];for(const i of r)n.done.has(i.e.id)||(n.retry.has(i.e.id)?i.r<J&&(i.r+=1,c.push(i)):c.push(i));this._setEntries(c)}_setEntries(t){this._store.set(t),t.length&&(t.some(s=>s.p===b)||this._store instanceof T?this._processNow(t):this._scheduleProcessing())}_scheduleProcessing(){this._scheduled||(this._scheduled=!0,setTimeout(()=>{this._scheduled=!1,this._processNow(this._store.get())},Y))}}function Q(e,t){if(e.size<=t)return e;const s=e.values();for(let n=0;n<e.size-t;++n)s.next();return new Set(s)}const V=2500,tt=.5;let f=new Set;const k=new K("ts-b");function v(){return window.URL.createObjectURL?.(new Blob).split("/").pop()||`${Math.random()}`}let u;function y(){if(u)return u;const e=st();if(e)return u=e,e;const t=v();return O(t),t}function O(e){const t=window.TS.cookieName||"tsuid";u=e,document.cookie=`${t}=${e};max-age=31536000`}function et(){return u=void 0,document.cookie="tsuid=",y()}window.TS.setUserId=O,typeof window.TS.getUserId!="function"&&(window.TS.getUserId=y),window.TS.resetUserId=et;function st(){const e=window.TS.cookieName||"tsuid";return new RegExp(`(^|;)\\s*${e}\\s*=\\s*([^;]+)`).exec(document.cookie)?.pop()}function nt(e){const t=e.type,s={path:e.page};let n;e.product&&(n={type:"product",id:e.product});let o;e.additionalProduct&&(o={type:"product",id:e.additionalProduct});const r=new Date(e.t).toISOString();switch(t){case"Click":return{clicks:[{resolvedBidId:e.bid,entity:n,additionalAttribution:o,placement:s,occurredAt:r,opaqueUserId:e.uid,id:e.id}]};case"Impression":return{impressions:[{resolvedBidId:e.bid,entity:n,additionalAttribution:o,placement:s,occurredAt:r,opaqueUserId:e.uid,id:e.id}]};case"Purchase":return{purchases:[{occurredAt:r,opaqueUserId:e.uid,items:(e.items||[]).map(c=>({productId:c.product,quantity:c.quantity,unitPrice:c.price})),id:e.id}]}}}async function ot(e){const t={done:new Set,retry:new Set},s=[],n={apiKey:window.TS.token,host:window.TS.url,userAgent:`ts.js/${D}`},o=new B(n);for(const r of e)s.push(o.reportEvent(nt(r)).then(c=>{(c.retry?t.retry:t.done).add(r.id)}).catch(()=>{t.done.add(r.id)}));return await Promise.all(s),t}const rt=new F(ot);function p(e,t){const s=it(e);if(f.has(s))return;f.add(s),f=Q(f,V),rt.append(e);const n=new CustomEvent("topsort",{bubbles:!0,detail:e});t.dispatchEvent(n)}function it(e){const t=JSON.stringify(e.items||[]);return[e.page,e.type,e.product??e.additionalProduct,e.bid,t].join("-")}function ct(){const e=window.location,t=e.hash;return t[1]==="/"?t:`${e.pathname}${e.search}`}function w(e,t){let s=t.dataset.tsProduct,n=t.dataset.tsResolvedBid,o;n==="inherit"&&s&&(e==="Click"||e==="Impression")&&(n=k.get(),o=s,s=void 0);const r={type:e,product:s,additionalProduct:o,bid:n,t:Date.now(),page:ct(),id:v(),uid:typeof window.TS.getUserId=="function"?window.TS.getUserId():y()};return e==="Purchase"&&(r.items=JSON.parse(t.dataset.tsItems||"[]")),r}function at(e){if(!(e.currentTarget instanceof HTMLElement))return;const t=e.currentTarget.closest(A);if(t&&t instanceof HTMLElement){const s=w("Click",t);p(s,t),s.bid&&k.set(s.bid)}}const g=window.IntersectionObserver?new IntersectionObserver(e=>{for(const t of e)if(t.isIntersecting){const s=t.target;s instanceof HTMLElement&&(p(w("Impression",s),s),g&&g.unobserve(s))}},{threshold:tt}):void 0,A="[data-ts-product],[data-ts-action],[data-ts-items],[data-ts-resolved-bid]";function dt(e){const t=e.querySelectorAll("[data-ts-clickable]"),s=t.length===0?[e]:Array.from(t);for(const n of s)n.addEventListener("click",at)}function P(e){ut(e)?p(w("Purchase",e),e):(g?g.observe(e):p(w("Impression",e),e),dt(e))}function U(e){const t=e.querySelectorAll(A);for(let s=0;s<t.length;s++){const n=t[s];n instanceof HTMLElement&&P(n)}}function ut(e){return e.dataset.tsAction==="purchase"}function lt(e){for(const t of e)if(t.type==="childList"){const s=new Set;for(let n=0;n<t.addedNodes.length;n++){const o=t.addedNodes[n];if(o?.nodeType===Node.ELEMENT_NODE){const r=o.parentElement;r&&!s.has(r)&&s.add(r)}for(const r of s)U(r)}}else if(t.type==="attributes"){if(!(t.target instanceof HTMLElement))continue;P(t.target)}}function N(){if(window.TS?.loaded)return;if(window.TS.loaded=!0,!window.TS?.token){console.error("Missing TS token");return}U(document);const e=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;new e(lt).observe(document,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["data-ts-product","data-ts-action","data-ts-items","data-ts-resolved-bid"]})}/complete|interactive|loaded/.test(document.readyState)?N():window.addEventListener("DOMContentLoaded",N)})); |
+125
-129
@@ -1,8 +0,13 @@ | ||
| var x = Object.defineProperty, d = (e, t) => x(e, "name", { value: t, configurable: !0 }), H = "https://api.topsort.com", T = { auctions: "v2/auctions", events: "v2/events" }, S = "0.3.1", b = class { | ||
| var N = "https://api.topsort.com", I = { auctions: "v2/auctions", events: "v2/events" }, y = "0.3.8"; | ||
| class M { | ||
| status; | ||
| statusText; | ||
| body; | ||
| retry; | ||
| constructor(t, s, r, n = !1) { | ||
| this.status = t, this.statusText = s, this.body = r, this.retry = n; | ||
| } | ||
| }; | ||
| d(b, "AppError"); | ||
| var j = b, l = j, v = class { | ||
| } | ||
| var u = M; | ||
| class R { | ||
| async handleResponse(t) { | ||
@@ -12,3 +17,3 @@ let s; | ||
| let r = t.status === 429 || t.status >= 500; | ||
| throw new l(t.status, t.statusText, s, r); | ||
| throw new u(t.status, t.statusText, s, r); | ||
| } | ||
@@ -23,3 +28,3 @@ return s; | ||
| let n = r instanceof Error ? r.message : "Unknown error"; | ||
| throw new l(500, "Internal Server Error", n); | ||
| throw new u(500, "Internal Server Error", n); | ||
| } | ||
@@ -34,4 +39,4 @@ } | ||
| async post(t, s, r) { | ||
| let n = this.setupTimeoutSignal(r); | ||
| return this.request(t, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json", "X-UA": r.userAgent ? `@topsort/sdk ${S} ${r.userAgent}` : `@topsort/sdk ${S}`, Authorization: `Bearer ${r.apiKey}` }, body: JSON.stringify(s), signal: n }); | ||
| let n = this.setupTimeoutSignal(r), o = r.fetchOptions ?? { keepalive: !0 }; | ||
| return this.request(t, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json", "X-UA": r.userAgent ? `@topsort/sdk ${y} ${r.userAgent}` : `@topsort/sdk ${y}`, Authorization: `Bearer ${r.apiKey}` }, body: JSON.stringify(s), signal: n, ...o }); | ||
| } | ||
@@ -42,51 +47,46 @@ sanitizeUrl(t) { | ||
| } catch (s) { | ||
| throw new l(400, "Invalid URL", { error: `Invalid URL: ${s}` }); | ||
| throw new u(400, "Invalid URL", { error: `Invalid URL: ${s}` }); | ||
| } | ||
| } | ||
| }; | ||
| d(v, "APIClient"); | ||
| var B = v, k = new B(); | ||
| function O(e) { | ||
| var t; | ||
| if (!((t = e == null ? void 0 : e.apiKey) != null && t.length)) throw new l(401, "API Key is required.", {}); | ||
| } | ||
| d(O, "validateConfig"); | ||
| function y(e) { | ||
| var T = new R(); | ||
| function L(e) { | ||
| if (!e?.apiKey?.length) throw new u(401, "API Key is required.", {}); | ||
| } | ||
| function E(e) { | ||
| return async (...t) => { | ||
| let s = t[t.length - 1]; | ||
| return O(s), e(...t); | ||
| return L(s), e(...t); | ||
| }; | ||
| } | ||
| d(y, "withValidation"); | ||
| async function A(e, t) { | ||
| let s = `${t.host}/${T.auctions}`; | ||
| return await k.post(s.toString(), e, t); | ||
| async function C(e, t) { | ||
| let s = `${t.host}/${I.auctions}`; | ||
| return await T.post(s.toString(), e, t); | ||
| } | ||
| d(A, "handler"); | ||
| var D = y(A); | ||
| async function P(e, t) { | ||
| var $ = E(C); | ||
| async function q(e, t) { | ||
| try { | ||
| let s = `${t.host}/${T.events}`; | ||
| return await k.post(s, e, t), { ok: !0, retry: !1 }; | ||
| let s = `${t.host}/${I.events}`; | ||
| return await T.post(s, e, t), { ok: !0, retry: !1 }; | ||
| } catch (s) { | ||
| if (s instanceof l && s.retry) return { ok: !1, retry: !0 }; | ||
| if (s instanceof u && s.retry) return { ok: !1, retry: !0 }; | ||
| throw s; | ||
| } | ||
| } | ||
| d(P, "handler"); | ||
| var K = y(P), M = class { | ||
| var x = E(q); | ||
| class H { | ||
| config; | ||
| constructor(t) { | ||
| this.config = t, this.config.host = this.config.host ?? H; | ||
| this.config = t, this.config.host = this.config.host ?? N; | ||
| } | ||
| async reportEvent(t) { | ||
| return K(t, this.config); | ||
| return x(t, this.config); | ||
| } | ||
| async createAuction(t) { | ||
| return D(t, this.config); | ||
| return $(t, this.config); | ||
| } | ||
| }; | ||
| d(M, "TopsortClient"); | ||
| var X = M, z = X; | ||
| const J = "2.5.0"; | ||
| class U { | ||
| } | ||
| var B = H; | ||
| const D = "2.6.0"; | ||
| class b { | ||
| constructor() { | ||
@@ -114,3 +114,3 @@ this._data = []; | ||
| } | ||
| class Y { | ||
| class K { | ||
| constructor(t) { | ||
@@ -134,20 +134,18 @@ this._key = t, this._storage = window.sessionStorage, this._bid = void 0; | ||
| } | ||
| const G = "ts-t", Z = "ts-q", V = 250, W = 3, F = 25, Q = 250, I = 9, tt = 0; | ||
| function et(e, t) { | ||
| return t > 0 ? e + (Math.random() + Math.pow(2, t)) * 1e3 : 0; | ||
| const j = "ts-t", z = "ts-q", J = 3, X = 25, Y = 250, m = 9, G = 0; | ||
| function W(e, t) { | ||
| return t > 0 ? e + (Math.random() + 2 ** t) * 1e3 : 0; | ||
| } | ||
| function st() { | ||
| var t; | ||
| const e = new _(G); | ||
| function Z() { | ||
| const e = new _(j); | ||
| try { | ||
| const s = "3"; | ||
| if (e.set([{ x: s }]), ((t = e.get()[0]) == null ? void 0 : t.x) === s) | ||
| return new _(Z); | ||
| if (e.set([{ x: "3" }]), e.get()[0]?.x === "3") | ||
| return new _(z); | ||
| } catch { | ||
| } | ||
| return new U(); | ||
| return new b(); | ||
| } | ||
| class rt { | ||
| class F { | ||
| constructor(t) { | ||
| this._store = st(), this._processing = /* @__PURE__ */ new Set(), this._scheduled = !1, this._processor = t; | ||
| this._store = Z(), this._processing = /* @__PURE__ */ new Set(), this._scheduled = !1, this._processor = t; | ||
| } | ||
@@ -159,4 +157,4 @@ append(t, s) { | ||
| r: 0, | ||
| p: s != null && s.highPriority ? I : tt | ||
| }), r = r.slice(-V), this._setEntries(r); | ||
| p: s?.highPriority ? m : G | ||
| }), r = r.slice(-250), this._setEntries(r); | ||
| } | ||
@@ -167,5 +165,5 @@ async _processNow(t) { | ||
| const s = []; | ||
| for (let i = t.length - 1; i >= 0 && s.length < F; i--) { | ||
| const a = t[i], u = a == null ? void 0 : a.e; | ||
| u && !this._processing.has(u.id) && et(u.t, a.r) <= Date.now() && (s.push(u), this._processing.add(u.id)); | ||
| for (let i = t.length - 1; i >= 0 && s.length < X; i--) { | ||
| const a = t[i], d = a?.e; | ||
| d && !this._processing.has(d.id) && W(d.t, a.r) <= Date.now() && (s.push(d), this._processing.add(d.id)); | ||
| } | ||
@@ -189,7 +187,7 @@ if (!s.length) { | ||
| for (const i of o) | ||
| r.done.has(i.e.id) || (r.retry.has(i.e.id) ? i.r < W && (i.r += 1, c.push(i)) : c.push(i)); | ||
| r.done.has(i.e.id) || (r.retry.has(i.e.id) ? i.r < J && (i.r += 1, c.push(i)) : c.push(i)); | ||
| this._setEntries(c); | ||
| } | ||
| _setEntries(t) { | ||
| this._store.set(t), t.length && (t.some((s) => s.p === I) || this._store instanceof U ? this._processNow(t) : this._scheduleProcessing()); | ||
| this._store.set(t), t.length && (t.some((s) => s.p === m) || this._store instanceof b ? this._processNow(t) : this._scheduleProcessing()); | ||
| } | ||
@@ -199,6 +197,6 @@ _scheduleProcessing() { | ||
| this._scheduled = !1, this._processNow(this._store.get()); | ||
| }, Q)); | ||
| }, Y)); | ||
| } | ||
| } | ||
| function nt(e, t) { | ||
| function Q(e, t) { | ||
| if (e.size <= t) | ||
@@ -211,35 +209,33 @@ return e; | ||
| } | ||
| const ot = 2500, it = 0.5; | ||
| let f = /* @__PURE__ */ new Set(); | ||
| const C = new Y("ts-b"); | ||
| function N() { | ||
| var e, t; | ||
| return ((t = (e = window.URL).createObjectURL) == null ? void 0 : t.call(e, new Blob()).split("/").pop()) || `${Math.random()}`; | ||
| const V = 2500, tt = 0.5; | ||
| let h = /* @__PURE__ */ new Set(); | ||
| const k = new K("ts-b"); | ||
| function v() { | ||
| return window.URL.createObjectURL?.(new Blob()).split("/").pop() || `${Math.random()}`; | ||
| } | ||
| let h; | ||
| function m() { | ||
| if (h) | ||
| return h; | ||
| const e = at(); | ||
| let l; | ||
| function g() { | ||
| if (l) | ||
| return l; | ||
| const e = st(); | ||
| if (e) | ||
| return h = e, e; | ||
| const t = N(); | ||
| return R(t), t; | ||
| return l = e, e; | ||
| const t = v(); | ||
| return O(t), t; | ||
| } | ||
| function R(e) { | ||
| function O(e) { | ||
| const t = window.TS.cookieName || "tsuid"; | ||
| h = e, document.cookie = `${t}=${e};max-age=31536000`; | ||
| l = e, document.cookie = `${t}=${e};max-age=31536000`; | ||
| } | ||
| function ct() { | ||
| return h = void 0, document.cookie = "tsuid=", m(); | ||
| function et() { | ||
| return l = void 0, document.cookie = "tsuid=", g(); | ||
| } | ||
| window.TS.setUserId = R; | ||
| typeof window.TS.getUserId != "function" && (window.TS.getUserId = m); | ||
| window.TS.resetUserId = ct; | ||
| function at() { | ||
| var s; | ||
| window.TS.setUserId = O; | ||
| typeof window.TS.getUserId != "function" && (window.TS.getUserId = g); | ||
| window.TS.resetUserId = et; | ||
| function st() { | ||
| const e = window.TS.cookieName || "tsuid"; | ||
| return (s = new RegExp(`(^|;)\\s*${e}\\s*=\\s*([^;]+)`).exec(document.cookie)) == null ? void 0 : s.pop(); | ||
| return new RegExp(`(^|;)\\s*${e}\\s*=\\s*([^;]+)`).exec(document.cookie)?.pop(); | ||
| } | ||
| function dt(e) { | ||
| function rt(e) { | ||
| const t = e.type, s = { | ||
@@ -305,3 +301,3 @@ path: e.page | ||
| } | ||
| async function ut(e) { | ||
| async function nt(e) { | ||
| const t = { | ||
@@ -313,7 +309,7 @@ done: /* @__PURE__ */ new Set(), | ||
| host: window.TS.url, | ||
| userAgent: `ts.js/${J}` | ||
| }, n = new z(r); | ||
| userAgent: `ts.js/${D}` | ||
| }, n = new B(r); | ||
| for (const o of e) | ||
| s.push( | ||
| n.reportEvent(dt(o)).then((c) => { | ||
| n.reportEvent(rt(o)).then((c) => { | ||
| (c.retry ? t.retry : t.done).add(o.id); | ||
@@ -326,12 +322,12 @@ }).catch(() => { | ||
| } | ||
| const lt = new rt(ut); | ||
| function p(e, t) { | ||
| const s = ht(e); | ||
| if (f.has(s)) | ||
| const ot = new F(nt); | ||
| function f(e, t) { | ||
| const s = it(e); | ||
| if (h.has(s)) | ||
| return; | ||
| f.add(s), f = nt(f, ot), lt.append(e); | ||
| h.add(s), h = Q(h, V), ot.append(e); | ||
| const r = new CustomEvent("topsort", { bubbles: !0, detail: e }); | ||
| t.dispatchEvent(r); | ||
| } | ||
| function ht(e) { | ||
| function it(e) { | ||
| const t = JSON.stringify(e.items || []); | ||
@@ -342,9 +338,9 @@ return [e.page, e.type, e.product ?? e.additionalProduct, e.bid, t].join( | ||
| } | ||
| function ft() { | ||
| function ct() { | ||
| const e = window.location, t = e.hash; | ||
| return t[1] === "/" ? t : `${e.pathname}${e.search}`; | ||
| } | ||
| function w(e, t) { | ||
| function p(e, t) { | ||
| let s = t.dataset.tsProduct, r = t.dataset.tsResolvedBid, n; | ||
| r === "inherit" && s && (e === "Click" || e === "Impression") && (r = C.get(), n = s, s = void 0); | ||
| r === "inherit" && s && (e === "Click" || e === "Impression") && (r = k.get(), n = s, s = void 0); | ||
| const o = { | ||
@@ -356,18 +352,18 @@ type: e, | ||
| t: Date.now(), | ||
| page: ft(), | ||
| id: N(), | ||
| uid: typeof window.TS.getUserId == "function" ? window.TS.getUserId() : m() | ||
| page: ct(), | ||
| id: v(), | ||
| uid: typeof window.TS.getUserId == "function" ? window.TS.getUserId() : g() | ||
| }; | ||
| return e === "Purchase" && (o.items = JSON.parse(t.dataset.tsItems || "[]")), o; | ||
| } | ||
| function pt(e) { | ||
| function at(e) { | ||
| if (!(e.currentTarget instanceof HTMLElement)) | ||
| return; | ||
| const t = e.currentTarget.closest(L); | ||
| const t = e.currentTarget.closest(A); | ||
| if (t && t instanceof HTMLElement) { | ||
| const s = w("Click", t); | ||
| p(s, t), s.bid && C.set(s.bid); | ||
| const s = p("Click", t); | ||
| f(s, t), s.bid && k.set(s.bid); | ||
| } | ||
| } | ||
| const g = window.IntersectionObserver ? new IntersectionObserver( | ||
| const w = window.IntersectionObserver ? new IntersectionObserver( | ||
| (e) => { | ||
@@ -377,27 +373,28 @@ for (const t of e) | ||
| const s = t.target; | ||
| s instanceof HTMLElement && (p(w("Impression", s), s), g && g.unobserve(s)); | ||
| s instanceof HTMLElement && (f(p("Impression", s), s), w && w.unobserve(s)); | ||
| } | ||
| }, | ||
| { | ||
| threshold: it | ||
| threshold: tt | ||
| } | ||
| ) : void 0, L = "[data-ts-product],[data-ts-action],[data-ts-items],[data-ts-resolved-bid]"; | ||
| function wt(e) { | ||
| const t = e.querySelectorAll("[data-ts-clickable]"); | ||
| (t.length === 0 ? [e] : t).forEach((r) => r.addEventListener("click", pt)); | ||
| ) : void 0, A = "[data-ts-product],[data-ts-action],[data-ts-items],[data-ts-resolved-bid]"; | ||
| function dt(e) { | ||
| const t = e.querySelectorAll("[data-ts-clickable]"), s = t.length === 0 ? [e] : Array.from(t); | ||
| for (const r of s) | ||
| r.addEventListener("click", at); | ||
| } | ||
| function $(e) { | ||
| gt(e) ? p(w("Purchase", e), e) : (g ? g.observe(e) : p(w("Impression", e), e), wt(e)); | ||
| function P(e) { | ||
| ut(e) ? f(p("Purchase", e), e) : (w ? w.observe(e) : f(p("Impression", e), e), dt(e)); | ||
| } | ||
| function q(e) { | ||
| const t = e.querySelectorAll(L); | ||
| function U(e) { | ||
| const t = e.querySelectorAll(A); | ||
| for (let s = 0; s < t.length; s++) { | ||
| const r = t[s]; | ||
| r instanceof HTMLElement && $(r); | ||
| r instanceof HTMLElement && P(r); | ||
| } | ||
| } | ||
| function gt(e) { | ||
| function ut(e) { | ||
| return e.dataset.tsAction === "purchase"; | ||
| } | ||
| function yt(e) { | ||
| function lt(e) { | ||
| for (const t of e) | ||
@@ -408,3 +405,3 @@ if (t.type === "childList") { | ||
| const n = t.addedNodes[r]; | ||
| if ((n == null ? void 0 : n.nodeType) === Node.ELEMENT_NODE) { | ||
| if (n?.nodeType === Node.ELEMENT_NODE) { | ||
| const o = n.parentElement; | ||
@@ -414,3 +411,3 @@ o && !s.has(o) && s.add(o); | ||
| for (const o of s) | ||
| q(o); | ||
| U(o); | ||
| } | ||
@@ -420,16 +417,15 @@ } else if (t.type === "attributes") { | ||
| continue; | ||
| $(t.target); | ||
| P(t.target); | ||
| } | ||
| } | ||
| function E() { | ||
| var s, r; | ||
| if ((s = window.TS) != null && s.loaded) | ||
| function S() { | ||
| if (window.TS?.loaded) | ||
| return; | ||
| if (window.TS.loaded = !0, !((r = window.TS) != null && r.token)) { | ||
| if (window.TS.loaded = !0, !window.TS?.token) { | ||
| console.error("Missing TS token"); | ||
| return; | ||
| } | ||
| q(document); | ||
| U(document); | ||
| const e = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; | ||
| new e(yt).observe(document, { | ||
| new e(lt).observe(document, { | ||
| attributes: !0, | ||
@@ -441,2 +437,2 @@ childList: !0, | ||
| } | ||
| /complete|interactive|loaded/.test(document.readyState) ? E() : window.addEventListener("DOMContentLoaded", E); | ||
| /complete|interactive|loaded/.test(document.readyState) ? S() : window.addEventListener("DOMContentLoaded", S); |
+36
-34
| { | ||
| "name": "@topsort/analytics.js", | ||
| "version": "2.5.0", | ||
| "version": "2.6.0", | ||
| "description": "JS library to automatically report events to Topsort's Analytics", | ||
@@ -10,4 +10,10 @@ "main": "dist/ts.js", | ||
| }, | ||
| "packageManager": "pnpm@9.9.0", | ||
| "keywords": ["ads", "sponsored listings", "auctions", "analytics", "topsort"], | ||
| "packageManager": "pnpm@10.22.0", | ||
| "keywords": [ | ||
| "ads", | ||
| "sponsored listings", | ||
| "auctions", | ||
| "analytics", | ||
| "topsort" | ||
| ], | ||
| "engines": { | ||
@@ -18,5 +24,5 @@ "node": ">=20.0.0" | ||
| ".": { | ||
| "types": "./dist/src/index.d.ts", | ||
| "import": "./dist/ts.mjs", | ||
| "require": "./dist/ts.js", | ||
| "types": "./dist/src/events.d.ts" | ||
| "require": "./dist/ts.js" | ||
| } | ||
@@ -29,3 +35,3 @@ }, | ||
| "dist/ts.mjs", | ||
| "dist/*.d.ts", | ||
| "dist/src/*.d.ts", | ||
| "package.json", | ||
@@ -38,10 +44,10 @@ "README.md", | ||
| "build": "vite build", | ||
| "format": "biome check", | ||
| "format:fix": "biome check --write", | ||
| "lint": "eslint . --max-warnings 0 --ignore-path .gitignore", | ||
| "lint:fix": "eslint . --max-warnings 0 --ignore-path .gitignore --fix", | ||
| "lint:ci": "eslint . --max-warnings 0 --ignore-path .gitignore", | ||
| "format": "biome format", | ||
| "format:fix": "biome format --write", | ||
| "lint": "biome check", | ||
| "lint:fix": "biome check --write", | ||
| "lint:ci": "biome ci", | ||
| "test": "vitest run --coverage", | ||
| "test:e2e": "vite build && vite build -c vite.config.browser-test.js && tsc && node dist/mocks/api-server.js", | ||
| "types:check": "tsc" | ||
| "types:check": "tsc --noemit" | ||
| }, | ||
@@ -51,27 +57,23 @@ "author": "Topsort", | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^1.9.2", | ||
| "@types/express": "^4.17.21", | ||
| "@types/node": "^20.13.0", | ||
| "@types/react": "^18.3.12", | ||
| "@types/react-dom": "^18.3.0", | ||
| "@typescript-eslint/eslint-plugin": "^7.9.0", | ||
| "@typescript-eslint/parser": "^7.18.0", | ||
| "@vitest/coverage-v8": "^2.0.5", | ||
| "eslint": "^8.57.0", | ||
| "eslint-plugin-vitest": "^0.4.1", | ||
| "express": "^4.20.0", | ||
| "jsdom": "^24.0.0", | ||
| "msw": "^2.6.6", | ||
| "react": "^18.3.1", | ||
| "react-dom": "^18.3.1", | ||
| "react-router-dom": "^6.28.0", | ||
| "tslib": "^2.6.3", | ||
| "typescript": "^5.5.2", | ||
| "vite": "^5.4.10", | ||
| "vite-plugin-dts": "^4.2.3", | ||
| "vitest": "^2.0.5" | ||
| "@biomejs/biome": "2.3.5", | ||
| "@types/express": "5.0.5", | ||
| "@types/node": "24.10.1", | ||
| "@types/react": "19.2.4", | ||
| "@types/react-dom": "19.2.3", | ||
| "@vitest/coverage-v8": "4.0.8", | ||
| "express": "5.1.0", | ||
| "jsdom": "27.2.0", | ||
| "msw": "2.12.1", | ||
| "react": "19.2.0", | ||
| "react-dom": "19.2.0", | ||
| "react-router-dom": "7.9.5", | ||
| "tslib": "2.8.1", | ||
| "typescript": "5.9.3", | ||
| "vite": "7.2.2", | ||
| "vite-plugin-dts": "4.5.4", | ||
| "vitest": "4.0.8" | ||
| }, | ||
| "dependencies": { | ||
| "@topsort/sdk": "^0.3.1" | ||
| "@topsort/sdk": "0.3.8" | ||
| } | ||
| } |
+3
-3
@@ -102,3 +102,3 @@ # Topsort Analytics.js Tutorial | ||
| * `product_id`: The ID of the product. | ||
| * `productId`: The ID of the product. | ||
| * `quantity`: The quantity of the product purchased. | ||
@@ -111,6 +111,6 @@ * `price`: The price of the product. | ||
| data-ts-action="purchase" | ||
| data-ts-items='[{"product_id": "product-123", "quantity": 1, "price": 2399}, {"product_id": "product-456", "quantity": 2, "price": 399, "vendorId": "vendor-abc"}]' | ||
| data-ts-items='[{"productId": "product-123", "quantity": 1, "price": 2399}, {"productId": "product-456", "quantity": 2, "price": 399, "vendorId": "vendor-abc"}]' | ||
| > | ||
| Complete Purchase | ||
| </button> | ||
| </button onclick="return false;"> | ||
| ``` | ||
@@ -117,0 +117,0 @@ |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
17
-19.05%33326
-2.2%11
-54.17%507
-1.74%+ Added
- Removed
Updated