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:
Prop | Type | Required |
---|---|---|
networkId | number | โ |
children | ReactNode | โ |
debug | boolean | โ |
personalizedAds | boolean | โ |
singleRequest | boolean | โ |
disableInitialLoad | boolean | โ |
limitedAds | boolean | โ |
autoLoad | boolean | โ |
lazyLoad | boolean | LazyLoad | โ |
autoReload | AutoReload | โ |
fallback | Collapse | โ |
outOfPage | OutOfPage | โ |
adUnit | string | โ |
sizeMapping | SizeMapping[] | โ |
adSenseAttributes | Attributes | โ |
targetingArguments | Attributes | โ |
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
TBD
autoReload
TBD
fallback
This prop specifies the global collapseEmptyDivs
behaviour, and takes the following options:
default
: Acts the same as if prop is not providedexpand
: All ads will initially take no space, and each ad slot that gets filled will expand to fill its spacecollapse
: 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.