Component responsible for requesting ads from DFP, both lazyloaded and normal.
- Source:
Members
(private, static) ads :array
- Type:
- array
- Source:
- Type:
- array
- Source:
- Type:
- boolean
- Source:
- Type:
- string
- Source:
- Type:
- number
- Source:
- Type:
- array
- Source:
- Type:
- boolean
- Source:
- Type:
- number
- Source:
- Type:
- number
- Source:
- Source:
- Source:
- Source:
- Type
- object
- Source:
- Source:
- Type
- array
- Source:
- Source:
- Source:
- Source:
- Source:
- Source:
- Source:
- Type
- number
- Source:
- Type
- number
- Source:
- Type
- number
- Source:
- Source:
- Source:
(private, static) lazyAds :array
(private, static) listenersAdded :boolean
(private, static) name :string
(private, static) offset :number
(private, static) renderedAds :array
(private, static) scrollIsBound :boolean
(private, static) scrollTop :number
(private, static) threshold :number
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.
(private, static) addSlotRenderEndedListener()
Adds a listener that's called each time an ad on the page has finished rendering.
(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 |
Returns:
(private, static) bindScroll()
Bind the scroll event that handles when to do requests for lazyloaded ads.
(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 |
Returns:
(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. |
(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.
(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 |
(private, static) enableAndListen()
Enables the googletag services if it hasn't been enabled already. Also starts listeners for slot events.
(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.
(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.
(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 |
Returns:
(private, static) getScrollTop() → {number}
Get the scroll from the top.
Returns:
(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 |
Returns:
(private, static) init()
Initialize the component.
(private, static) initialize()
Initialize ads loading and bind scroll-listener.
(private, static) reflow()
Reflow the component. Is for example called when lazyloading the rest of the Dagbladet frontpage on mobile.