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:@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.Banner Attributes
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.
Banner Behaviors
These functions onwindow.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.
Banner Interface
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, setcontext 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 astatechange 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.