@advertol/service-google-dfp

Google DFP/Ad Manager service.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@advertol/service-google-dfp
001.1.29 hours ago4 years agoMinified + gzip package size for @advertol/service-google-dfp in KB

Readme

@advertol/service-google-dfp
!Build Statusci-imgci !BrowserStack Statusbrowserstack-imgbrowserstack
Google DFP/Ad Manager service.

Install

npm install @advertol/service-google-dfp --save

Usage

<!doctype html>
<html>
	<head>
		<script async="async" src="https://www.googletagservices.com/tag/js/gpt.js"></script>
		<script>
			window.googletag = window.googletag || {};
			window.googletag.cmd = window.googletag.cmd || [];
		</script>
	</head>
	<body>
		<div id="zone-becky"></div>
	</body>
</html>

import advertol from '@advertol/core';
import GoogleDfpService from '@advertol/service-google-dfp';

const instance = advertol({
	// …
	service: [
		new GoogleDfpService({
			zones: [{
				id: 'becky',
				adUnitPath: '/42/becky',
				slot: () => window.googletag.defineSlot('/42/becky', ['fluid'], 'zone-becky').addService(window.googletag.pubads())
			}]
		})
	]
});

instance.resolve();

API

googleDfpService({ zones, onSetup, refreshZones })

zones

Type: Object[]
List of zones with their slot callback.
| Property | Type | Description | | --- | --- | --- | | slot | Function | Function which returns googletag.defineSlotgoogletag-define-slot or googletag.defineOutOfPageSlotgoogletag-define-outofpage-slot instance. | | adUnitPath | string | Full path of the ad unit with the network code and unit code. | | id | string | Zone ID. |

onSetup

Type: Function
Define additional initialization logic.

refreshZones(slots)

Type: Function
Refresh slots.
By default, it calls refreshgoogletag-refresh method.
slots
Type: googletag.Slot[]
List of slots to refresh.

instance.addZone({ slot, adUnitPath, id })

Add new zone with slot callback.
| Property | Type | Description | | --- | --- | --- | | slot | Function | Function which returns googletag.defineSlotgoogletag-define-slot or googletag.defineOutOfPageSlotgoogletag-define-outofpage-slot instance. | | adUnitPath | string | Full path of the ad unit with the network code and unit code. | | id | string | Zone ID. |

Browser support

Tested in IE9+ and all modern browsers.

Test

For automated tests, run npm run test:automated (append :watch for watcher support).

License

MIT © Ivan Nikolić