React DFP Documentation

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

 singleRequestIsEnabled

Use the method singleRequestIsEnabled() to get the current/selected request strategy.

  1. true : Single Request Architecture enabled (SRA).
  2. false : Multi-Request strategy enabled.

Important note: For more details, please see documentation about the method
DFPManager.configureSingleRequest().

Example:

ADS GO HERE...
Single Request Architecture: enabled

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
25
26
27
28
29
30
31
32
33
34
35
36
import React, { Component } from 'react';
import { AdSlot, DFPManager } from 'react-dfp';


export default class Example extends Component {
  constructor(props) {
    super(props);
    this.state = {
      singleRequestEnabled: DFPManager.singleRequestIsEnabled(),
    };
  }

  componentDidMount() {
    DFPManager.configureSingleRequest(true);
    DFPManager.load();
    this.setState({
      singleRequestEnabled: DFPManager.singleRequestIsEnabled(),
    });
  }

  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>
          Single Request Architecture: {this.state.singleRequestEnabled ? 'enabled' : 'disabled'}
        </div>
      </div>
    );
  }
}

Notes:

  1. Line 9: we read the singleRequest configuration using the method  DFPManager.singleRequestIsEnabled() and store its value in the state variable 'singleRequestEnabled'.
  2. Lines 25,28: we define two ad slots using the <AdSlot>component.
  3. Lines 14-18: we manually enable the Single Request Architecture using the method:
    DFPManager.configureSingleRequest() , and load the ads in this page using
    DFPManager.load([id]),   then we read the value of singleRequest configuration using the method: DFPManager.singleRequestIsEnabled() and finally update the state variable 'singleRequestEnabled'.
  4. Line 31: we print the vaue of the state variable.