Created
August 17, 2015 18:55
-
-
Save grobertson/8e31f8875c5f1f82e97e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ad placements. | |
Google Publisher Tag docs are here: https://developers.google.com/doubleclick-gpt/reference?hl=en | |
-Page loads. | |
dot.ads.AdService | |
1) 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 | |
2) AdService.discover(): scan DOM for elements using "slug" names in the configuration as class, store element handles in an array | |
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L72 | |
The real meat of this happens in _FindElements: | |
https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L123 | |
* 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment