Installation
Install the package from npm and import it in your code:import and top-level await, so run them in a <script type="module"> or in your bundled code.
Creating an Auction
Reporting Events
Report a render when you insert a winner into the page, and an impression when that winner becomes visible to the shopper. Send the sameopaqueUserId for a shopper on every auction and event, for example an id you keep in a cookie or your login session. A new id per event breaks attribution.
Renders
A render records that a sponsored ad was inserted into the page, whether or not it ever becomes visible. Renders are sponsored-only, soresolvedBidId is required and there is no entity field.
Impressions
An impression records that an ad or product became visible to the shopper.Clicks
A click records that the shopper clicked an ad or product.entity: { type: "product", id: "<product id>" } instead of resolvedBidId, in impressions and clicks.
Purchases
A purchase records the products a shopper bought. Topsort attributes it to the ads the shopper interacted with.Retryable Errors
reportEvent resolves with retry: true for 429 and 5xx responses. Other errors, such as a 400 or a network failure, reject the promise, so catch them too: