React DFP Documentation

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

 setTargetingArguments

Use the method setTargetingArguments({...attributes}) to manually configure custom targeting parameters for your ad slots.

This method takes an object as parameter, you can use it to pass any amount of arbitrary variables.

Important note: Although this method will be always available and is meant for 'public usage',
<DFPSlotProvider targetingArguments /> or <AdSlot targetingArguments /> are the recomended ways to approach this feature, so, if possible you should use them instead.

You can find more information about this topic in the official gpt documentation:  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.setTargetingArguments({ foo: 'bar', baz: 'qux' });
    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 targeting attributes 'foo' and 'baz' using the method
    DFPManager.setTargetingArguments({...args}) and load the ads in this page using
    DFPManager.load([id])