React DFP Documentation

  ·  Build Status Npm Downloads Minizipped size GitHub license Dependencies
Minizipped size

 setAdSenseAttribute

Use the method setAdSenseAttribute(name, value) to manually configure an AdSense attribute for your page.

This method takes two parameter:

  1. name: attribute name (string).
  2. value: attribute value (string).

Important note: although this method will be always available and is meant for'public usage',
<DFPSlotProvider adSenseAttributes /> is the recomended way to approach this feature, please use that one if possible.

See google gpt docs for details:  link

Example:

ADS GO HERE...

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import React, { Component } from 'react';
import { AdSlot, DFPManager } from 'react-dfp';


export default class Example extends Component {
  componentDidMount() {
    DFPManager.setAdSenseAttribute('site_url', 'www.foo.bar');
    DFPManager.load();
  }

  render() {
    return (
      <div>
        <div className="desktop-ads">
          <AdSlot slotId="test1" dfpNetworkId="9999" sizes={[[728, 90], [300, 250]]} adUnit="homepage/1" />
        </div>
        <div className="mobile-ads">
          <AdSlot slotId="test2" dfpNetworkId="9999" sizes={[[320, 50], [300, 50]]} adUnit="homepage/mobile" />
        </div>
      </div>
    );
  }
}

Notes:

  1. Lines 15,18: we define two ad slots using the <AdSlot>component.
  2. Lines 7-8: we configure the AdSense attribute 'site_url' using the method
    DFPManager.setAdSenseAttribute(name, value) and load the ads in this page using
    DFPManager.load([id])