doubleclick-gpt-loader

0.2.1 • Public • Published

doubleclick-gpt-loader

Easy loading Doubleclick GPT script and get a reference to googletag.

Rationale

I wrote this because I don't like my code depending on globals that may or may not have been actually created and I don't like jumping through hoops to load @types/doubleclick-gpt. With doubleclick-gpt-loader, you can import gpt as a typed module.

doubleclick-gpt-loader exports a p-lazy lazy Promise that is resolved with a reference to googletag typed with types from @types/doubleclick-gpt

Usage

import { googletagLoader } from "doubleclick-gpt-loader";

async function showAds() {
  const googletag = await googletagLoader;

  const slot = googletag
    .defineSlot("/12345678/my-ad-slot", [320, 50], "my-ad-slot")
    .addService(googletag.pubads());

  googletag.enableServices();

  googletag.display(slot);
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.1
    24
    • latest

Version History

Package Sidebar

Install

npm i doubleclick-gpt-loader

Weekly Downloads

24

Version

0.2.1

License

ISC

Unpacked Size

4.85 kB

Total Files

12

Last publish

Collaborators

  • joeflateau