React DFP Documentation

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

 targetingArguments

Use the targetingArguments property to configure custom targeting paramters in your ad slots. The property is accepted by the following two components.

  1. DFPSlotsProvider
  2. AdSlot

When you set it via DFPSlotsProvider, all the ad slots will be provided with the configured values. On the other hand, if you only need some ads to have a given set of targeting paramters, you can just pass the prop to them.

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
24
import React, { Component } from 'react';
import { DFPSlotsProvider, AdSlot } from 'react-dfp';

export default class Example extends Component {
  render() {
    return (
      <DFPSlotsProvider
        dfpNetworkId="9999"
        targetingArguments={{ customKw: 'basic example' }}
      >
        <div className="desktop-ads">
          <AdSlot sizes={[[728, 90], [300, 250]]} adUnit="homepage/1" />
        </div>
        <div className="mobile-ads">
          <AdSlot
            sizes={[[320, 50], [300, 50]]}
            adUnit="homepage/mobile"
            targetingArguments={{ customKw2: 'hello' }}
          />
        </div>
      </DFPSlotsProvider>
    );
  }
}

Notes:

  1. Lines 8-10: configure default / global properties using the <DFPSlotProvider>. Notice we use the property 'targetingArguments' to define the custom targeting argument customKw2='basic example'. This argument is getting applied to all the ad slots in the page that do not have a custom definition of the prop 'targetingArguments'
  2. Line 13: define an ad-slot using the <AdSlot> component.
  3. Line 16-20: define a second ad-slot and use the property 'targetingArguments&apos to override the targeting arguments configuration. In this case we set the custom targeting argument customKw2='hello'.