Skip to content

Instantly share code, notes, and snippets.

@grobertson
Created August 17, 2015 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grobertson/8e31f8875c5f1f82e97e to your computer and use it in GitHub Desktop.
Save grobertson/8e31f8875c5f1f82e97e to your computer and use it in GitHub Desktop.
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