Namespace: adsDefer

db.libs.adsDefer

Component responsible for requesting ads from DFP, both lazyloaded and normal.

Source:

Members

(private, static) ads :array

The array for all the ads to be requested on load.
Type:
array
Source:

(private, static) lazyAds :array

The array for all the ads to be lazyloaded.
Type:
array
Source:

(private, static) listenersAdded :boolean

Boolean to check if listeners for ads have been added.
Type:
boolean
Source:

(private, static) name :string

The name of the component.
Type:
string
Source:

(private, static) offset :number

Is set to the sum of scrollTop + window.innerHeight + threshold.
Type:
number
Source:

(private, static) renderedAds :array

Array of ad objects that have been rendered, meaning they have received response from DFP.
Type:
array
Source:

(private, static) scrollIsBound :boolean

Boolean to check if a scroll listener has been added to the window.
Type:
boolean
Source:

(private, static) scrollTop :number

The amount of scroll in the browser's window.
Type:
number
Source:

(private, static) threshold :number

The threshold of how many pixels before an adunit comes into view the request to DFP should be made.
Type:
number
Source:

Methods

(private, static) addImpressionViewableListener()

Adds a listener that's called each time an ad has been considered viewed based on some criterias (see docs). Here we also calculate how long it took for an ad to be viewable from the time it was rendered.

Source:

(private, static) addSlotRenderEndedListener()

Adds a listener that's called each time an ad on the page has finished rendering.

Source:

(private, static) assertValidAdUnit(HTMLElement) → {object}

Checks if an adunit has the right attributes to be considered valid. These attributes are required to make a correct request to DFP.

Parameters:
Name Type Description
HTMLElement HTMLElement The HTMLElement to check
Source:
Returns:
An object representing the adunit
Type
object

(private, static) bindScroll()

Bind the scroll event that handles when to do requests for lazyloaded ads.

Source:

(private, static) createArray(nodeList) → {array}

Creates an array of HTMLElements from a NodeList that have not already been configured. It also sets the adunit's topoffset and offsetheight data attributes on the element.

Parameters:
Name Type Description
nodeList NodeList The NodeList
Source:
Returns:
An array with HTMLElements
Type
array

(private, static) createLazySlot(ad)

Create a slot for an adunit that has the data-load-on="view" attribute.

Parameters:
Name Type Description
ad object The DOM element representing the adunit.
Source:

(private, static) createOnLoadSlots()

Creates slots for each adunit that has data-load-on="load" attribute. The request for these slots are then made to DFP in a single request. This enables roadblocking.

Source:

(private, static) defineSlot(ad)

Defines a single slot which is pushed to the googletag.cmd object.

Parameters:
Name Type Description
ad object An object representing the adunit
Source:

(private, static) enableAndListen()

Enables the googletag services if it hasn't been enabled already. Also starts listeners for slot events.

Source:

(private, static) findAdunits()

Find adunits with either the data-load-on="load" or data-load-on="view" attribute. Populate the two arrays ads and lazyAds with these adunits respectively.

Source:

(private, static) getAdunitsWithinViewThreshold()

Searches for adunits with data-load-on="view" attribute that are within the viewport threshold. If found, a slot for this adunit is defined.

Source:

(private, static) getOffsetHeight(element) → {number}

Get the offsetHeight of an element. The offsetHeight is the height of an element including its padding, borders and horizontal scrollbar (if present).

Parameters:
Name Type Description
element HTMLElement The element of which to get the offsetHeight
Source:
Returns:
The element's offsetHeight
Type
number

(private, static) getScrollTop() → {number}

Get the scroll from the top.

Source:
Returns:
The scroll amount
Type
number

(private, static) getTopOffset(element) → {number}

Get the top offset of an element.

Parameters:
Name Type Description
element HTMLElement The element of which to get the offset
Source:
Returns:
The top offset
Type
number

(private, static) init()

Initialize the component.

Source:

(private, static) initialize()

Initialize ads loading and bind scroll-listener.

Source:

(private, static) reflow()

Reflow the component. Is for example called when lazyloading the rest of the Dagbladet frontpage on mobile.

Source: