- The provider’s tag must travel with the creative, from campaign setup through the auction response.
- The storefront must insert the script into the rendered banner after the shopper has granted consent.
@topsort/verification library to handle these steps.
The helper library currently supports IAS only. It reduces the custom code needed to manage tag insertion, banner re-renders, ad rotation, and consent changes.
The initial 0.1.0 release supports custom web banner renderers using IAS monitoring tags. It does not yet include an automatic Banners.js integration, other verification providers, native mobile-app measurement, or direct <script> installation.
Before you start
- Your banners must use JSON templates, which define named creative fields.
- You need a Consent Management Platform (CMP) to collect and record the shopper’s consent. Topsort and this library do not provide a CMP. You connect the library to your existing CMP through a consent adapter.
<script> installation.
Step 1: Configure the banner template
When creating the banner template, include a text field namedverificationTag. This field holds the advertiser’s verification tag.
You can use another field name, provided your storefront reads the same name from the auction response. This guide uses verificationTag.
Step 2: Supply the verification tag
During campaign creation, the advertiser pastes the tag supplied by their verification provider into the template field. For the library’s current IAS support, the accepted value is exactly one external script tag:- The URL must use HTTPS.
- The hostname must be
staticjs.adsafeprotected.com. - The path must be
/fw.js. - The URL must contain exactly one numeric
advEntityIdand one numericpubEntityId. - Inline JavaScript, extra attributes, extra elements, other hosts, explicit ports, and URL fragments are rejected.
Step 3: Read the tag from the auction response
The template fields are returned in the winning asset’scontent object. Read verificationTag alongside the image URL, headline, and other creative fields.
In the raw auction response, this is winner.asset[index].content.verificationTag, where index identifies the asset you are rendering.
The examples below assume your application maps that asset’s content object to banner.content and the winner’s resolvedBidId to banner.resolvedBidId. These are application-level mappings, not a different auction response format.
Step 4: Register the rendered banner
The library inserts the validated script into the banner’s container after consent is granted. Your renderer must register each banner after its element is connected and dispose the registration when that banner is removed. Registering a different render key on the same element replaces the previous registration automatically. Three terms appear in the examples:- Runtime: The object returned by
createVerificationRuntime(...). It connects to your consent adapter and tracks registered banner elements. Create one runtime for the page and reuse it across banners. - Register: Calling
register(...)supplies the banner element, verification tag, and render key. The library checks consent before inserting the script. - Handle: The object returned by
register(...). Itsdispose()method terminates the registration and removes the script node the library inserted.
consentSource adapter described in Connect your CMP, then register each banner after its container element is available:
renderKey distinguishes a re-render of the same ad from a new ad rendered into the same element. Registering a new renderKey on the same element automatically tears down and replaces the previous registration.
Keep the key stable for re-renders of the same ad, and change it for a new ad render.
An empty tag safely loads nothing and disposes any previous registration owned by the same element. Invalid elements, empty render keys, and malformed non-empty tags load nothing and produce bounded diagnostics. These conditions do not throw into your banner rendering code.
Using React
For React, create the runtime once in a shared module and import it wherever you render banners. Do not create it inside a component, where repeated mounts would create separate runtimes and consent subscriptions.useVerificationRef returns a callback ref. React calls it with the DOM node when the banner mounts and with null when it unmounts. The helper registers the banner and handles cleanup, so you do not call dispose() yourself.
Connect your CMP
The library shows no consent UI and does not communicate directly with your CMP. You provide an adapter with two functions:current()returns the current consent state.subscribe(listener)reports consent changes and returns a function that stops listening.
"unknown", "granted", or "denied".
The following example illustrates the adapter structure. Replace readMyCmp() and myCmp.on/off with your CMP’s actual APIs:
unknown: Waits without parsing the tag, fetching the provider script, or modifying the DOM.granted: Validates the tag, creates a fresh<script>element from the validatedsrc, and appends it inside the banner element. It does not insert stored markup throughinnerHTML.denied: Terminates the registration without loading the script.
"granted" bypasses consent gating and allows IAS to load as soon as the banner is registered.
If consent is withdrawn later, the library terminates the registration and removes its own script node. It cannot undo vendor code that has already executed, requests already sent, globals already set, or storage already written. Cleanup is best-effort and covers only the script node created by the library.
Check the integration
Pass anonDiagnostic callback when creating the runtime to receive status codes such as:
registeredactiveconsent_deniedinvalid_tagprovider_load_failedconsent_withdrawnconsent_source_failedelement_not_readyruntime_disposed
active means only that the provider’s script finished loading. It does not confirm that IAS recorded an impression, considered the ad viewable, or accepted the data. Confirm measurement in IAS reporting.
Content Security Policy
If your storefront uses a Content Security Policy (CSP), allowstaticjs.adsafeprotected.com in script-src so the browser can load the IAS script.
This is not a complete production allowlist. The full set of IAS origins required for script-src, connect-src, img-src, and frame-src remains subject to IAS-side validation.
Banners.js
Automatic Banners.js integration is not part of0.1.0. A custom integration can use the runtime only if it can provide the exact rendered element, verificationTag, and resolvedBidId, and can dispose the registration with the banner lifecycle. First-class Banners.js support will be documented separately when it is available.