@cnbritain/wc-adsdeprecated

Adverts

Usage no npm install needed!

<script type="module">
  import cnbritainWcAds from 'https://cdn.skypack.dev/@cnbritain/wc-ads';
</script>

README

wc-ads

Adverts

Macro settings

Key Optional Default Description
ad_unit false The ad unit code
ad_zone false The ad zone code
ad_sizes false The sizes of the ads
ad_sizemap true None The sizemapping for the ad
ad_position true None The position of the ad. This is used by GPT
ad_targets true None The ad target information
ad_values true None Key,value information for GPT
ad_group true None The name of the group the ad belongs to
ad_order true None The order of the ad group
ad_placement true None Position of the ad but used for the frontend
lazyload true False Whether to lazyload the ad
allow_bidding true False Whether the slot can be bid on
title true None Title to include on the ad

JS Documentation

Ad

Kind: global class

new Ad(el, manager, options)

Param Type
el HTMLElement
manager AdManager
options Object

ad.el : HTMLElement

The ad element

Kind: instance property of Ad
Access: public

ad.id : String

Unique id of the advert

Kind: instance property of Ad
Access: public

ad.group : AdGroup

The group the ad is part of

Kind: instance property of Ad
Access: public

ad.manager : AdManager

The manager that created the ad

Kind: instance property of Ad
Access: public

ad.renderedSize : Array.<Number>

The rendered size of the advert

Kind: instance property of Ad
Access: public

ad.slot : googletag.Slot

The GPT slot

Kind: instance property of Ad
Access: public

ad.state : Number

Current state of the advert

Kind: instance property of Ad
Access: public

ad.destroy()

Destroys the advert

Kind: instance method of Ad
Access: public

ad.register() ⇒ Promise

Registers the advert with AdManager

Kind: instance method of Ad
Access: public

AdGroup

Kind: global class

new AdGroup(manager, options)

Param Type
manager AdManager
options Object

adGroup.id : String

Unique id of the group

Kind: instance property of AdGroup
Access: public

adGroup.lazyload : Boolean

Whether to lazyload the group

Kind: instance property of AdGroup
Access: public

adGroup.manager : AdManager

The manager that created the group

Kind: instance property of AdGroup
Access: public

adGroup.maxSlots : Number

The maximum amount of slots the group can have

Kind: instance property of AdGroup
Access: public

adGroup.size : Number

The amount of slots in the group

Kind: instance property of AdGroup
Access: public

adGroup.slots : Object

The ad slots

Kind: instance property of AdGroup
Access: public

adGroup.add(ad)

Add an Ad to the group

Kind: instance method of AdGroup
Access: public

Param Type
ad Ad

adGroup.destroy()

Destroys the group

Kind: instance method of AdGroup
Access: public

adGroup.refresh() ⇒ Promise

Refreshes all the slots in the group

Kind: instance method of AdGroup
Access: public

adGroup.register() ⇒ Promise

Registers all the slots in the group

Kind: instance method of AdGroup
Access: public

adGroup.release()

Release all the slots from the group

Kind: instance method of AdGroup
Access: public

adGroup.remove(ad)

Removes an Ad from the group

Kind: instance method of AdGroup
Access: public

Param Type
ad Ad

adGroup.render() ⇒ Promise

Renders all the slots in the group

Kind: instance method of AdGroup
Access: public

adGroup.resize()

Recalculates the top and bottom bounds of the group

Kind: instance method of AdGroup
Access: public

AdModel

Kind: global class

new AdModel(defaults)

Creates an AdModel

Param Type Description
defaults Object Default values that will be set

adModel.clear()

Clears all the properties

Kind: instance method of AdModel
Access: public

adModel.get(key) ⇒ *

Gets the property or throws an error if the key doesn't exist

Kind: instance method of AdModel
Access: public

Param Type
key String

adModel.set(key, value)

Sets the property or throws an error if the key doesn't exist

Kind: instance method of AdModel
Access: public

Param Type
key Object | String
value *

NativeAd

NativeAd~getNativeAdSize(nad) ⇒ Number

Works out what size the native ad is

Kind: inner method of NativeAd

Param Type
nad NativeAd

NativeAd~getNativeAdSizeName(index) ⇒ String

Gets the size name of the native ad

Kind: inner method of NativeAd

Param Type
index Number

NativeAd~getNativeAdTemplateUrl(size, json) ⇒ String

Creates a template url

Kind: inner method of NativeAd

Param Type
size Size
json Object

NativeAd~objectToQueryString(obj) ⇒ String

Converts an object into an encoded string

Kind: inner method of NativeAd

Param Type
obj Object

Utils

Utils.buildDFPUrl(attribs) ⇒ String

Creates the DFP url

Kind: static method of Utils

Param Type
attribs Object

Utils.getAdElementAttributes(el) ⇒ Object

Gets the attributes from the Ad element

Kind: static method of Utils

Param Type
el HTMLElement

Utils.getSlot(ad) ⇒ googletag.Slot

Get the slot from the Ad

Kind: static method of Utils

Param Type
ad Ad

Utils.hasGroup(ad) ⇒ Boolean

Checks if the Ad is part of a group

Kind: static method of Utils

Param Type
ad Ad

Utils.isAdDestroyed(ad) ⇒ Boolean

Checks if an advert has been destroyed

Kind: static method of Utils

Param Type Description
ad Ad The advert to check

Utils.isAdInitialised(ad) ⇒ Boolean

Checks if an advert has been initialised

Kind: static method of Utils

Param Type Description
ad Ad The advert to check

Utils.isAdRendered(ad) ⇒ Boolean

Checks if an advert has been rendered

Kind: static method of Utils

Param Type Description
ad Ad The advert to check

Utils.isElInitialised(el) ⇒ Boolean

Checks if an advert element has been initialised

Kind: static method of Utils

Param Type
el HTMLElement

Utils.loadGPTLibrary() ⇒ Promise

Loads the GPT library

Kind: static method of Utils

Utils.parseAdKeyValues(value) ⇒ Object

Parses the ad key value pairs. These need to be unescaped as jinja super encodes the json

Kind: static method of Utils

Param Type
value String

Utils.parseAdAttributes(el) ⇒ Object

Parses the attributes for the ads

Kind: static method of Utils

Param Type
el HTMLElement

Utils.mapAdElementAttributes(attribs) ⇒ Object

Maps the ad attributes

Kind: static method of Utils

Param Type
attribs Object

Utils.pushToGoogleTag(callback) ⇒ Promise

Adds a callback to GPT's cmd queue

Kind: static method of Utils

Param Type
callback function

Utils.setAdStateToDestroyed(ad) ⇒ Ad

Sets the state of the Ad to destroyed

Kind: static method of Utils

Param Type
ad Ad

Utils.setAdStateToRendered(ad) ⇒ Ad

Sets the state of the Ad to rendered

Kind: static method of Utils

Param Type
ad Ad

Utils.setAdStateToStopped(ad) ⇒ Ad

Sets the state of the Ad to stopped

Kind: static method of Utils

Param Type
ad Ad

Utils~AD_STATES : enum

Different states for the advert

Kind: inner enum property of Utils
Read only: true
Properties

Name Type Default
UNINITIALISED Number 0
INITIALISED Number 1
RENDERED Number 2
STOPPED Number 3
DESTROYED Number 4

Utils~DEFAULT_AD_ELEMENT_ATTRIBUTES : Object

Default properties for the Ad element

Kind: inner property of Utils
Read only: true

Utils~AD_ATTRIBUTE_MAP : Object

Parser for Ad element attributes

Kind: inner property of Utils
Read only: true

Utils~GPT_URL : String

GPT Script url

Kind: inner constant of Utils
Read only: true

Themes

Prerequisites:

  • Node.jsbrew install node
  • Grunt - npm install -g grunt-cli
  • Other prereqs? Python? Virtualenv?

Demo:

Install dependencies:

npm install

Build the things:

npm run sass
npm run js
npm run docs

Hint your JS

npm run jshint

Python the pythons:

npm run demo-install

Start the demo server:

python demo.py