Harmony

Simplify your DFP business logic.

View this project on GitHub.

var SlotFactory = require('./modules/slot-factory.js'),
    GroupFactory = require('./modules/group-factory.js'),
    events = require('./modules/master-event-handler.js'),
    watcher = require('./modules/breakpoint-watcher.js'),
    googletag = require('./modules/googletag.js'),
    bindGPTEvents = require('./util/bind-gpt-events.js');

harmony.on('breakpoint/update', callback)

Params
callback function(number) Called on new breakpoint.
See
types/event-handler.js
See
modules/breakpoint-watcher.js
watcher.on('update', function (bp) {
    events.trigger('breakpoint/update', bp);
});

harmony.on(GPTEventName, callback)

Can be one of:

  • slotRenderEnded
  • impressionViewable
  • slotOnload
  • slotVisibilityChanged
See
util/bind-gpt-events.js
googletag.cmd.push(function () {
    bindGPTEvents(events);
});

harmony

Type
Harmony
module.exports = {

on(name, callback)

See
types/event-handler.js
    on: events.on,

one(name, callback)

See
types/event-handler.js
    one: events.one,

off([name])

See
types/event-handler.js
    off: events.off,

trigger(name, [data])

See
types/event-handler.js
    trigger: events.trigger,

version

Type
string
    version: require('../package.json').version,

load()

Load bulk configurations into the system.

See
actions/load.js
    load: require('./actions/load.js'),

addBreakpoints(set)

Add breakpoint values in pixels.

Params
set Array.<number> Breakpoints in pixels.
See
modules/breakpoint-watcher.js
    addBreakpoints: watcher.add,

getBreakpoints()

Fetch the list of breakpoints already loaded into the system.

Returns
Array.<number>
See
modules/breakpoint-watcher.js
    getBreakpoints: watcher.getAll,

breakpoint()

Fetch the current breakpoint.

Returns
number
See
modules/breakpoint-watcher.js
    breakpoint: watcher.current,

log

Instance of Lumberjack populated with Harmony's data.

See
modules/log.js
    log: require('./modules/log.js'),

slot(name)

Safely fetch an existing ad slot or a mock slot if slot was not found.

Params
name string Name of the ad slot.
Returns
Slot MockSlot
See
modules/slot-factory.js
    slot: SlotFactory.get,

group(name)

Fetch a slot group by name.

Params
name string Name of the slot group.
Returns
Group Collection of 0 or more ad slots.
See
modules/group-factory.js
    group: GroupFactory.create,

slots

Fetch the master group of all slots.

Type
Group
See
modules/master-group.js
    slots: require('./modules/master-group.js'),

defineSlot(config)

Create a new adSlot in the page.

See
modules/slot-factory.js
    defineSlot: SlotFactory.create,

enable

slot(name)

group(name)

Marks slots as eligible to make ad calls.

See
actions/enable.js
    enable: require('./actions/enable.js'),

disable

slot(name)

group(name)

Marks slots as ineligible to make ad calls.

See
actions/disable.js
    disable: require('./actions/disable.js'),

show

slot(name)

group(name)

Show a slot or group of slots.

See
actions/show.js
    show: require('./actions/show.js')
};