CpexPackage

Entry point of the library, adds and manages all modules


Constructor

new CpexPackage()

Constructor of the main class, initializes variables and settings

Methods

clearAds(elementIds) @public

Clears all elements of currently rendered ads, reset the ads registry.

Parameters
Name Type Description
elementIds Array

Array of element IDs of the ads to clear, if not provided, all ads are cleared


(async) init() @public

Initializes loading and running


(async) refresh() @public

Refresh all ads. Used mainly for single page applications.


registerAd(elementId) @public

Helper function to register ads for use in HB, outside of the usual adserver flow

Parameters
Name Type Description
elementId string

Element ID of the ad to register, used for targeting and rendering


(async) reload() @public

Reload all modules, as if the page was refreshed. Used mainly for single page applications. Modules have checks against loading files for a second time.


render(elementId, adUnitopt, creative, width, height) @public

Renders ads with support for custom CPEx formats

Parameters
Name Type Attributes Description
elementId string

Element ID for rendering

adUnit string <optional>

Ad unit name

creative string

Creative HTML code

width number

Ad width

height number

Ad height


(async) run() @public

Runs everything


(async) autoRefreshLoop() @internal

Refreshes ads based on autorefresh settings


failsafe() @internal

Failsafe method - attempts to detect ad server if settings failed to load


(async) load() @internal

Waits for settings to be loaded, starts loading for modules, they handle the waiting inside


(async) loadSettings(attempt) @internal

Loads settings files and merges them with defaults Expects config object with publisherSettingsPath and websiteSettingsPath URLs to be present on window

Parameters
Name Type Description
attempt number

Current attempt number for loading settings, used for logging and retry mechanism


overrideFromLocalStorage() @internal

Searches for settings in local storage and overrides current settings


reloadSettings() @internal

Reloads settings from source files


runQueue() @internal

Searches for existing queue and runs it. Executed after loading settings to allow page-specific overrides.


setAdServer() @internal

Sets the appropriate ad server module based on settings


setPublisher() @internal

Sets the appropriate publisher module (for special cases)