seeplusplus / dfp

Google Publisher Tags (Doubleclick GPT) for Angular

Home Page:https://atwwei.github.io/dfp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@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 13.2.5.

Build Status Coverage Status NPM Version Commitizen friendly GitHub License

Dependencies

@types/googletag

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
13 npm install @wwei/dfp@v13-lts

Usage

Add DfpModule to the imports of your NgModule.

import { NgModule } from '@angular/core';
import { DfpModule } from '@wwei/dfp';

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

Use DfpService.

import { Component } from '@angular/core';
import { DfpService, RewardedSlotGrantedEvent } from '@wwei/dfp';

@Component({
  selector: 'app-app',
  templateUrl: './app.component.html',
})
export class AppComponent {
  constructor(private dfp: DfpService) {
    // Customize page-level settings before the service is enabled.
    this.dfp.cmd(() => {
      googletag.pubads().collapseEmptyDivs();
      googletag.pubads().enableSingleRequest();
      // ...
    });
  }
  /**
   * Displays the rewarded ad. This method should not be called
   * until the user has consented to view the ad.
   */
  displayRewardedAd() {
    this.dfp
      .rewarded({
        unitPath: '/22639388115/rewarded_web_example',
      })
      .subscribe((event) => {
        if (event instanceof RewardedSlotGrantedEvent) {
          // The rewarded is granted
        }
        // googletag.destroySlots([event.slot]);
      });
  }
}

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 Samples https://developers.google.com/publisher-tag/samples

License

MIT © Wei Wang

About

Google Publisher Tags (Doubleclick GPT) for Angular

https://atwwei.github.io/dfp/

License:MIT License


Languages

Language:TypeScript 89.2%Language:JavaScript 10.8%