Ad placements. Google Publisher Tag docs are here: https://developers.google.com/doubleclick-gpt/reference?hl=en
-Page loads.
dot.ads.AdService
- Instantiate dot.ads.AdService
- Singleton
- Declares goog.structs.Map() instances for placements_ and AdSlots_ https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L31 https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L45 (AdSlots_ Map eventually contains each GPT slot, and its associated closure control)
-Read configuration from adData object https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L164
- Inform AdSlotRenderer that we are the controling AdService https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L47
- AdService.discover(): scan DOM for elements using "slug" names in the configuration as class, store element handles in an array
The real meat of this happens in _FindElements:
- If an element matching "MasterSlot" was found it must be the first registered This is handled in AdService.FindElements_ by purposefully arranging the Set() called adElements with the master slot as the first in the Set() regardless of order discovered. Elements are initialized in order, so this causes Master Slot to get initialized first. https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L123
For each placement we found: https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L73 - Get a new AdSlot instance https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L75
- Decorate it. (When we decorate it, this is when it gets added to the map of slots)
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L77
(If something goes wrong, we give up and .dispose() of the Map() entry)
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L111
- Add the instance and the placement slug to adSlots_
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L78
- If it's marked as a lazy load slot, set up the handler to fire on appear.
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L80
- If it's not marked as lazy, call adSlot.display();
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L82
This can be thought of for each placement as Insantiate & Decorate; Then Display, Listen or Dispose. Every
element found will get Instantiated as an Adslot, and Decorated as such. After that, each AdSlot (which can be
thought of as "owning" that element) is either .display()ed, listened for (lazy load) (listenForAdSlot_(AdSlot)) or disposed
on error.
dot.ads.AdSlot
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adslot.js
AdSlot is an "AppearableControl" which is an extended version of Closure's Control.
AdSlot itself does little, but offers setters and getters for the configuration details of an AdSlot
dot.ads.AdSlotRenderer
The real heavy lifiting of the AdSlot is handled in this renderer. Properties that are valid for all AdSlots can be (and seem to be) set on the AdSlotRenderer instead of each AdSlot since the renderer is a singleton.
Knows the AdService: https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adslotrenderer.js#L63
.decorate() sets the placement class (which is equal to the slug) on the AdSlot it's rendering https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adslotrenderer.js#L83
initializeDom() defines the AdSlot in GoogleTags (DFP) https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adslotrenderer.js#L115
when .DefineSlot_ is called, the call as an argument to .getAdSizes_ filters the list of possible sizes and returns the list of sizes to be configured, and those sizes are only the sizes which fit in the viewport: https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adslotrenderer.js#L160