Skip to content

Instantly share code, notes, and snippets.

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

-Read configuration from adData object https://github.com/dailydot/dot_adplacements/blob/master/adplacements/static/js/dot/ads/adservice.js#L164

  1. 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

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