Documentation Index
Fetch the complete documentation index at: https://docs.topsort.com/llms.txt
Use this file to discover all available pages before exploring further.
El Topsort JavaScript SDK es la biblioteca cliente oficial para integrarse con las APIs de subastas y seguimiento de eventos de Topsort. Construido en TypeScript, este SDK simplifica la integración, permitiendo la creación de un flujo end-to-end en minutos.
Instalación
<script
async
type="module"
src="https://unpkg.com/@topsort/sdk@latest/dist/index.mjs"
></script>
<script>
window.TS = {
token: "TSE_XXXXXXXXXXXX", // Replace with your Topsort API key
};
</script>
Creando una Subasta
import { TopsortClient } from "https://unpkg.com/@topsort/sdk@latest/dist/index.mjs";
const topsortClient = new TopsortClient({ apiKey: window.TS.token });
const auctionDetails = {
auctions: [
{
type: "listings",
slots: 3,
searchQuery: "winter",
},
{
type: "banners",
slots: 1,
device: "desktop",
slotId: "slot123",
},
],
};
topsortClient
.createAuction(auctionDetails)
.then((result) => console.log("Auction Result", result))
.catch((error) => console.error("Auction Error", error));
Reportando Eventos
const winners = auctionResult.results.flatMap((result) => result.winners || []);
if (winners.length > 0) {
const impressions = winners.map((winner) => ({
resolvedBidId: winner.resolvedBidId,
id: crypto.randomUUID(),
occurredAt: new Date().toISOString(),
opaqueUserId: crypto.randomUUID(),
placement: { path: "/search/winter" },
}));
topsortClient
.reportEvent({ impressions })
.then((result) => console.log("Event Result", result))
.catch((error) => console.error("Event Error", error));
}
Errores Reintentables
La función reportEvent devuelve retry: true para errores 429 o 5xx:
topsortClient.reportEvent(eventPayload).then((result) => {
if (result.retry) {
console.warn("Transient error. Retry the call.");
}
});
Para la documentación completa y ejemplos end-to-end, consulta el repositorio de GitHub.