Skip to content

registerFormat

The registerFormat method registers a special ad format under a name. It is normally called by a format’s own CDN app (htag-format-<name>) when that app is lazily loaded — you rarely call it directly.

window.htag.api('1').registerFormat(name, format);
  • name (string): The format’s unique name (lowercase letters, digits and dashes), e.g. 'sidebar'.
  • format (object): The format definition.
    • applyFormat(divId) (function, required): Applies the format to the placement element divId. Returns an optional teardown function that Htag runs when the ad reloads/refreshes (wired into the Effects system under the ad:{divId} tag). Return nothing for a no-op.
    • allowScheduledReload() (function, optional): Returns whether Htag may automatically (timer/scheduled) reload the placement while this format is active. Defaults to true (reloadable) when omitted.
// Inside the htag-format-<name> app, executed on load:
const sidebar = {
applyFormat(divId) {
const teardown = expand(divId); // your DOM work
return teardown; // run automatically on the next ad reload
},
allowScheduledReload: () => false, // keep the format on screen; suppress auto-reloads
};
window.htag.api('1').registerFormat('sidebar', sidebar);