Toolbox πŸ› οΈ
GPTProvider

GPTProvider

The GPTProvider needs to be defined in order for ad units to load. Ideally it should be defined on a per-page basis, and as low down the component tree as possible.

import { GPTProvider } from 'goopubtag';
 
const MyPage = () => {
  return (
    <GPTProvider networkId={123456} debug={true}>
      <MyComponent />
    </GPTProvider>
  );
};
 
export default MyPage;

Props

Here is a complete list of props available for GPTProvider, with details of each below:

PropTypeRequired
networkIdnumberβœ…
childrenReactNodeβœ…
debugboolean❌
personalizedAdsboolean❌
singleRequestboolean❌
disableInitialLoadboolean❌
limitedAdsboolean❌
autoLoadboolean❌
lazyLoadboolean | LazyLoad❌
autoReloadAutoReload❌
fallbackCollapse❌
outOfPageOutOfPage❌
adUnitstring❌
sizeMappingSizeMapping[]❌
adSenseAttributesAttributes❌
targetingArgumentsAttributes❌

It is important to note that some of the props can be overwritten at a slot level.

networkId βœ…

This is a unique identifier for the Ad Manager network the ad unit belongs to.

children βœ…

Children components are required and excluding will result in errors. It is useful to note that useGPT cannot be used outside of the GPTProvider, so best practice involves nesting your components one layer deep from where the context is declared.

debug βœ…

When enabled, a floating icon appears in the bottom right corner that when clicked opens the GPT console. Useful for development, should NOT be enabled in production.

personalizedAds βœ…

TBD

singleRequest πŸ‘·

When enabled, this will bundle requests for multiple ads into a single request.

disableInitialLoad πŸ‘·

TBD

limitedAds βœ…

When enabled, limited ads will be rendered for each ad slot defined.

autoLoad πŸ‘·

TBD

lazyLoad βœ…

Allows for lazy loading of ad units based on scroll position in viewport. See lazy load example.

autoReload πŸ‘·

TBD

fallback βœ…

This prop specifies the global collapseEmptyDivs behaviour, and takes the following options:

  • default: Acts the same as if prop is not provided
  • expand: All ads will initially take no space, and each ad slot that gets filled will expand to fill its space
  • collapse: All ads will initally take space configured, and each slot that fails to fill will collapse to no size.

outOfPage βœ…

This prop determines the out of page behaviour, currently supporting the following types:

  • anchor
  • rewarded

The props are dynamic depending on the outOfPage type set. To gain a better understanding, have a look at the following examples:

adUnit βœ…

This defines the parent-ad-unit-code at a top level for all contained ad slots.

sizeMapping βœ…

TBD

adSenseAttributes βœ…

TBD

targetingArguments βœ…

This prop is a simple key-value object that defines the page level targeting attributes for your GPT configuration.