Skip to main content

cleanup

Interfaces

ICleanupModule

Cleanup Module

Cleans up special formats if enabled (on user navigation and ad reload), especially developed for SPAs.

The configs can either provide CSS selectors of the html elements that are part of the special/out-of-page formats and should be deleted or JS as single strings that contain the logic to remove the special format.

Please note: if you want to execute more than one statement/line of JS, please provide each line as separate string in the array. Like this we make sure that each line is tried to be executed and if one fails, the next one is still executed. Only global variables can be accessed in the JS strings!

Integration

In your index.ts import the Cleanup module and register the module.

moli.registerModule(createCleanup());

Dspx Skin

The dspx wallpaper can be cleaned as shown in the example above. The dspx_start_called.dspxPageSkin.unload() function is called to remove the wallpaper from the page.

Dspx itself also sets a global variable dspx_start_called.counter on the window object. This variable is used to count the number of times the skin has been loaded. Dspx unloads the skin itself, if the counter holds a value greater than 1 in order to prevent multiple loads on the page.

In SPAs, a value greater than 1 can happen as soon as a user navigates to a sub-page where the wallpaper ad slot is available and refreshed. If we try to unload() a second time, the dspx script crashes. Therefore we have to reset the counter to 0 after each clean-up.

{
bidder: 'dspx',
domId: 'wallpaper',
deleteMethod: {
jsAsString: [
'window.dspx_start_called && window.dspx_start_called.dspxPageSkin.unload();',
'window.dspx_start_called && (window.dspx_start_called.counter = 0);'
]
}
}

GAM-only formats (no bidder) - e.g. anchor ad slots

bidder is optional. If omitted, cleanup always runs for that config and skips the "did this bidder win the last auction on this slot" gate - there is no prebid bidder to check, because the format (e.g. a GAM out-of-page anchor slot) is served by GAM itself.

The destroySlot delete method destroys the googletag slot matching domId OR the resolved adUnitPath via googletag.destroySlots() - out-of-page slots (anchor/interstitial) never get GPT's own element id set to domId, so adUnitPath is required as a fallback (see findGoogletagSlot, the same lookup bridge.ts uses). adUnitPath may contain the same placeholders as elsewhere ({device}, {channel}), resolved via resolveAdUnitPath and the pipeline's own adUnitPathVariables__. It runs in its own dedicated configure step that always executes before defineSlots, scoped to the domIds being (re)requested this cycle - so a stale anchor slot from the previous reload never collides with the newly (re)defined one.

{
// no bidder - GAM serves this slot directly, not through prebid
domId: 'mobile_stickyad',
deleteMethod: { destroySlot: true, adUnitPath: '/1234567/example/{device}/anchor' }
}

This shape is authored manually per publisher, same as any other cleanup config - the Cleanup Module stays independent of the anchor waterfall feature and is not auto-configured from it.

Extends

  • IModule

Properties

configKey

readonly configKey: keyof ModulesConfig

The key under which this module's configuration is stored in modules.ModulesConfig.

Kept separate from name so the display name can be free-form while the config lookup stays type-safe. Typing this as keyof modules.ModulesConfig turns a mismatched key into a compile error instead of a silent runtime miss.

Inherited from

IModule.configKey

description

readonly description: string

Inherited from

IModule.description

moduleType

readonly moduleType: string

Inherited from

IModule.moduleType

name

readonly name: string

Free-form, human-readable display name used only in log/debug output.

This is NOT used to look up the module's configuration - see configKey.

Inherited from

IModule.name

Methods

cleanUp()

cleanUp(context, configs): void

Parameters

context: AdPipelineContext

configs: CleanupConfig[]

Returns

void

config__()

config__(): null | Object

If the module has some sort of configuration this can be fetched with this method

Returns

null | Object

Inherited from

IModule.config__

configureSteps__()

configureSteps__(): ConfigureStep[]

Returns a list of steps that should be executed in the ad pipeline.

Returns

ConfigureStep[]

Inherited from

IModule.configureSteps__

configure__()

configure__(moduleConfig?): void

Initialize the module with the given module configuration. Depending on the configuration the module may become active or inactive.

Parameters

moduleConfig?: ModulesConfig

Returns

void

Inherited from

IModule.configure__

initSteps__()

initSteps__(): InitStep[]

Returns a list of steps that should be executed in the ad pipeline.

Returns

InitStep[]

Inherited from

IModule.initSteps__

prebidBidsBackHandler__()?

optional prebidBidsBackHandler__(): PrebidBidsBackHandler[]

This method is called in the bidsBackHandler of prebid.

A module may provide those callbacks if it needs to alter the requests send to the ad server. The auctionEnd event cannot be used for this, as there's no guarantee the event handler will run before the requestAds step.

Note: Amazon TAM (A9) also has a callback that could be used for similar things. Unfortunately does the callback not provide the necessary information to implement any meaningful business logic. Especially the cpm parameter and bidder

The callback receives additional information coming from the ad pipeline run.

Note: These callbacks should not perform any initialization code or only be created once as this array will be accessed on every pbjs.requestBids() callback.

Use cases

The generic-skin module provides prebid bids back handlers to block certain ad units from being requested.

Returns

PrebidBidsBackHandler[]

See
Inherited from

IModule.prebidBidsBackHandler__

prepareRequestAdsSteps__()

prepareRequestAdsSteps__(): PrepareRequestAdsStep[]

Returns a list of steps that should be executed in the ad pipeline.

Returns

PrepareRequestAdsStep[]

Inherited from

IModule.prepareRequestAdsSteps__

requestBidsSteps__()?

optional requestBidsSteps__(): RequestBidsStep[]

Returns a list of steps that should be executed in the ad pipeline.

This step is optional, as should have been all steps to reduce implementation complexity of modules.

Note: prebid and amazon tam (a9) maybe implemented as modules in the future as they add those steps to the ad pipeline.

Returns

RequestBidsStep[]

Inherited from

IModule.requestBidsSteps__

Functions

createCleanup()

createCleanup(): ICleanupModule

Returns

ICleanupModule