Skip to main content
Topsort’s banners.js public library allows marketplaces to display banner ads through a low-code integration. By using a simple HTML tag, the marketplace can connect to Topsort’s ad server and render banners from active campaigns without complex integrations.

Installation

banners.js runs the auction and displays the banner. Load analytics.js with it, so that renders, impressions and clicks on the banner are reported. Install both with npm:
Then import @topsort/banners after setting up analytics.js as described on its page, with window.TS set before either library loads. Or load them with <script> tags. Set window.TS first, then load analytics.js synchronously (without async), then banners.js. banners.js reads window.TS.token and window.TS.getUserId when it runs the auction, so if analytics.js loads later the auction is sent without an opaqueUserId. banners.js requires analytics.js 2.9.0 or later.

Usage

This example shows a minimal setup required to do it. The integration works with standard HTML and Javascript, making it compatible with most frontend stacks. To test it, you just need to add your Marketplace API Key and the banner slot id, configured in the campaign.
These are the attributes available for the <topsort-banner> component. They serve as input to the auction request, to fetch the right winners for that context. Set only one of category-id, category-ids and category-disjunctions. If more than one is set, only the first in that order is used. These functions on window.TS_BANNERS customize how banners are displayed. All of them are optional. context is an object with the optional fields location, slotId and language, taken from the banner element. It describes where the banner is rendering. A custom element returned by getBannerElement must carry data-ts-resolved-bid="<banner.resolvedBidId>" (leave it out when isFallback is true). Without it, impressions and clicks are not tracked. To narrow the click surface, add data-ts-clickable to a descendant. Without it, the whole element is clickable. The banner interface is the structure of a banner object. Each banner contains metadata about the campaign, and the resolvedBidId, the parameter needed for tracking user interactions (renders, impressions and clicks).

Multiple banners and predefined content

To render several winners of one auction, set context on <topsort-banner> and add <topsort-banner-slot rank="1"> children. To keep your own markup, add predefined and bind auction content with data-ts-field (for example data-ts-field="mainImage:src"), marking the clickable element with data-ts-clickable. See the banners.js README for the full binding rules.

Events

The component emits a statechange event with status set to ready, nowinners or error. ready means the auction returned a winner. It does not mean the banner was shown: the impression is reported by analytics.js once the banner is at least 50% in view and painted for one second. In context mode each <topsort-banner-slot> emits its own event, and the parent emits none.