Constructor
new CpexPackage()
Constructor of the main class, initializes variables and settings
Methods
clearAds(elementIds)
Clears all elements of currently rendered ads, reset the ads registry.
| Name | Type | Description |
|---|---|---|
elementIds |
Array | Array of element IDs of the ads to clear, if not provided, all ads are cleared |
(async) init()
Initializes loading and running
(async) refresh()
Refresh all ads. Used mainly for single page applications.
registerAd(elementId)
Helper function to register ads for use in HB, outside of the usual adserver flow
| Name | Type | Description |
|---|---|---|
elementId |
string | Element ID of the ad to register, used for targeting and rendering |
(async) reload()
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)
Renders ads with support for custom CPEx formats
| 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()
Runs everything
(async) autoRefreshLoop()
Refreshes ads based on autorefresh settings
failsafe()
Failsafe method - attempts to detect ad server if settings failed to load
(async) load()
Waits for settings to be loaded, starts loading for modules, they handle the waiting inside
(async) loadSettings(attempt)
Loads settings files and merges them with defaults
Expects config object with publisherSettingsPath and websiteSettingsPath URLs to be present on window
| Name | Type | Description |
|---|---|---|
attempt |
number | Current attempt number for loading settings, used for logging and retry mechanism |
overrideFromLocalStorage()
Searches for settings in local storage and overrides current settings
reloadSettings()
Reloads settings from source files
runQueue()
Searches for existing queue and runs it. Executed after loading settings to allow page-specific overrides.
setAdServer()
Sets the appropriate ad server module based on settings
setPublisher()
Sets the appropriate publisher module (for special cases)