Freestar Pubfig Ad Slot React Component
Install
npm install --save @freestar/pubfig-adslot-react-component
Usage
import React, { Component } from 'react'
import FreestarAdSlot from '@freestar/pubfig-adslot-react-component'
import './demo.css'
class Demo extends Component {
state = {
adRefresh: 0
}
onAdRefresh = () => {
const { adRefresh } = this.state
this.setState({
adRefresh: adRefresh + 1
})
}
render() {
const placementName = 'PublisherName_970x250_728x90_320x50'
const publisher = 'publisherName'
const targeting = { key1: 'value1', key2: 'value2' }
const { adRefresh } = this.state
return (
<div>
<FreestarAdSlot
publisher={publisher}
placementName={placementName}
targeting={targeting}
channel='custom_channel'
classList={['m-30', 'p-15', 'b-thin-red']}
adRefresh={adRefresh}
onNewAdSlotsHook={(placementName) => console.log('creating ad', placementName)}
onDeleteAdSlotsHook={(placementName) => console.log('destroying ad', placementName)}
onAdRefreshHook={(placementName) => console.log('refreshing ad', placementName)}
/>
<button onClick={this.onAdRefresh}>Trigger Refresh</button>
</div>
)
}
}
export default Demo
Props
publisher
A required string of the publisher, which will be provided by Freestar.
placementName
A required string of the ad unit placement, which will be provided by Freestar.
targeting
An optional object of key/value pairs for targeting.
channel
An optional string of a custom channel to use.
classList
An optional array of strings representing any additional classes that should be applied to the wrapper dom element of the ad slot.
adRefresh
An optional number bound to the ad refresh. Increment this value to trigger a refresh of the ad slot.
onNewAdSlotsHook
An optional event hook that returns the placementName
when the component mounts and an ad is requested.
onDeleteAdSlotsHook
An optional event hook that returns the placementName
when the component unmounts.
onAdRefreshHook
An optional event hook that returns the placementName
when the component refreshes an ad.
API Methods
FreestarAdSlot.setPageTargeting
Proxy for the GPT setTargeting call to set page level targeting. See GPT documentation for more details
FreestarAdSlot.clearPageTargeting
Proxy for the GRP clearTargeting call to clear page level targeting. See GPT documentation for more details
Glossary
placementName
A value acquired from Google Ad Manager (previously known as DFP/Adx), which will be provided by Freestar.
targeting
A set of targeting values for the ad unit placement. See GPT Documentation for more details
Bypassing Freestar Ad Placements
If you would like to bypass Freestar Ad placements and render GAM ad units yourself directly please follow the instructions here
Developer instructions
To publish your changes to npm do the following:
- PR your changes to Master
- Once approved, merge your branch to master
- Switch to the master branch and run the build
npm run build
- Publish the package using np
np major|minor|patch