@wwei/dfp

Asynchronous rendering ads with Google Publisher Tag (Doubleclick GPT) for Angular

Usage no npm install needed!

<script type="module">
  import wweiDfp from 'https://cdn.skypack.dev/@wwei/dfp';
</script>

README

@wwei/dfp

@wwei/dfp is an angular module for displaying google dfp ads using Google Publisher Tag (Doubleclick GPT).

This library was generated with Angular CLI version 12.0.4.

Build Status Coverage Status NPM Version Commitizen friendly GitHub License

Install

npm install @wwei/dfp@latest
Angular Version Install
6、7 npm install @wwei/dfp@v7-lts
8 npm install @wwei/dfp@v8-lts
9 npm install @wwei/dfp@v9-lts
10 npm install @wwei/dfp@v10-lts
11 npm install @wwei/dfp@v11-lts
12 npm install @wwei/dfp@v12-lts

Usage

Add DfpModule to the imports of your NgModule.

import { DfpModule } from '@wwei/dfp';

@NgModule({
  imports: [
    ...
    DfpModule,
  ],
  ...
})
export class AppModule {}
...

Use googletag.PubAdsService to customize page-level settings before the service is enabled.

import { DfpService } from '@wwei/dfp';

@Component({
  selector: 'app-app',
  templateUrl: './app.component.html',
})
export class AppComponent {
  constructor(private dfp: DfpService) {
    // Use googletag to customize page-level settings
    this.dfp.cmd(() => {
      googletag.pubads().collapseEmptyDivs();
      googletag.pubads().enableSingleRequest();
      ...
    });
  }
}

Use DfpAdDirective in angular templates to define and display advertisements.

<div
  *dfpAd="{
    unitPath: '/6355419/Travel/Europe',
    id: 'ad-div-id',
    size: [
      [300, 250],
      [728, 90],
      [750, 200]
    ],
    sizeMapping: [
      [
        [750, 0],
        [
          [750, 200],
          [728, 90]
        ]
      ],
      [
        [300, 0],
        [300, 250]
      ],
      [[0, 0], []]
    ],
    categoryExclusion: 'AirlineAd',
    clickUrl: 'http://www.example.com?original_click_url=',
    collapseEmptyDiv: [true, true],
    forceSafeFrame: true,
    safeFrameConfig: { sandbox: true },
    targeting: { test: 'refresh' },
    adsense: { adsense_test_mode: 'on' }
  }"
></div>

The following settings can override the above settings with the same name.

<div
  *dfpAd="
    '/6355419/Travel/Europe';
    id: 'ad-div-id';
    size: [
      [300, 250],
      [728, 90],
      [750, 200]
    ];
    sizeMapping: [
      [
        [750, 0],
        [
          [750, 200],
          [728, 90]
        ]
      ],
      [
        [300, 0],
        [300, 250]
      ],
      [[0, 0], []]
    ];
    categoryExclusion: 'AirlineAd';
    clickUrl: 'http://www.example.com?original_click_url=';
    collapseEmptyDiv: [true, true];
    forceSafeFrame: true;
    safeFrameConfig: { sandbox: true };
    targeting: { test: 'refresh' };
    adsense: { adsense_test_mode: 'on' };
  "
></div>

Links

Name URL
Online Examples https://atwwei.github.io/dfp
Google Publisher Tags https://developers.google.com/publisher-tag

License

MIT © Wei Wang