Skip to main content
Topsort’s analytics.js public library allows marketplaces to easily send Topsort interaction events, such as clicks, impressions and purchases, with a low-code integration. By using a simple HTML tag, the marketplace can connect to Topsort’s ad server and send all tracking events related to an ad.

Installation

Load the library with a <script> tag, setting window.TS before the library loads:

With npm

Imports run before the rest of a module, so set window.TS in a separate file and import that file first:
Do not replace window.TS after the library has loaded. To set the token later, assign window.TS.token instead.

Marking Promoted Elements

To allow Topsort to automatically track clicks, impression and purchases, use the HTML element data-ts-* to mark promoted elements in the page.

Organic (non-promoted) elements

Render tracking

The library reports a render event as soon as a promoted element is inserted into the page, and an impression later, when that element becomes visible. Renders use the same data-ts-resolved-bid attribute, so no extra markup is needed:
Renders require an explicit resolvedBidId, so they do not fire for organic elements or for data-ts-resolved-bid="inherit". Do not also report renders, impressions or clicks for these elements with a Topsort SDK, or they are counted twice.

Clickable areas

Use data-ts-clickable to indicate what areas should trigger a click event:
On the banner’s destination page, mark each product featured in the banner so that its events are attributed to the banner:

Purchase tracking

Use data-ts-items JSON array to track purchases:

End to End Example

This example also uses banners.js for the topsort-banner tag.