Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/content service deprecated #18

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions dist/react-gpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ return /******/ (function(modules) { // webpackBootstrap
categoryExclusion = props.categoryExclusion,
collapseEmptyDiv = props.collapseEmptyDiv,
safeFrameConfig = props.safeFrameConfig,
content = props.content,
clickUrl = props.clickUrl,
forceSafeFrame = props.forceSafeFrame;

Expand Down Expand Up @@ -879,42 +878,23 @@ return /******/ (function(modules) { // webpackBootstrap
}

// GPT checks if the same service is already added.
if (content) {
adSlot.addService(Bling._adManager.googletag.content());
} else {
adSlot.addService(Bling._adManager.googletag.pubads());
}
adSlot.addService(Bling._adManager.googletag.pubads());
}
}, {
key: "display",
value: function display() {
var content = this.props.content;

var divId = this._divId;
var adSlot = this._adSlot;

if (content) {
Bling._adManager.googletag.content().setContent(adSlot, content);
} else {
Bling._adManager.googletag.display(divId);
if (Bling._adManager._disableInitialLoad && !Bling._adManager._initialRender) {
this.refresh();
}
Bling._adManager.googletag.display(divId);
if (Bling._adManager._disableInitialLoad && !Bling._adManager._initialRender) {
this.refresh();
}
}
}, {
key: "clear",
value: function clear() {
var adSlot = this._adSlot;
if (adSlot && adSlot.hasOwnProperty("getServices")) {
// googletag.ContentService doesn't clear content
var services = adSlot.getServices();
if (this._divId && services.some(function (s) {
return !!s.setContent;
})) {
document.getElementById(this._divId).innerHTML = "";
return;
}
Bling._adManager.clear([adSlot]);
}
}
Expand Down Expand Up @@ -1195,12 +1175,6 @@ return /******/ (function(modules) { // webpackBootstrap
* @property companionAdService
*/
companionAdService: _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.object]),
/**
* An optional HTML content for the slot. If specified, the ad will render with the HTML content using content service.
*
* @property content
*/
content: _propTypes2.default.string,
/**
* An optional click through URL. If specified, any landing page URL associated with the creative that is served is overridden.
*
Expand Down Expand Up @@ -1303,7 +1277,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @property npa
*/
npa: _propTypes2.default.bool
}, _class.refreshableProps = ["targeting", "sizeMapping", "clickUrl", "categoryExclusion", "attributes", "collapseEmptyDiv", "companionAdService", "forceSafeFrame", "safeFrameConfig"], _class.reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content", "npa"], _class._adManager = (0, _createManager.createManager)(), _class._config = {
}, _class.refreshableProps = ["targeting", "sizeMapping", "clickUrl", "categoryExclusion", "attributes", "collapseEmptyDiv", "companionAdService", "forceSafeFrame", "safeFrameConfig"], _class.reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "npa"], _class._adManager = (0, _createManager.createManager)(), _class._config = {
/**
* An optional string for GPT seed file url to override.
*/
Expand Down Expand Up @@ -1588,7 +1562,9 @@ return /******/ (function(modules) { // webpackBootstrap

if (!this._listening) {
[_Events2.default.SLOT_RENDER_ENDED, _Events2.default.IMPRESSION_VIEWABLE, _Events2.default.SLOT_VISIBILITY_CHANGED, _Events2.default.SLOT_LOADED].forEach(function (eventType) {
["pubads", "content", "companionAds"].forEach(function (service) {
// We have removed the "content" service because it is deprecated
// See https://developers.google.com/publisher-tag/reference#googletag.ContentService
["pubads", "companionAds"].forEach(function (service) {
// there is no API to remove listeners.
_this4.googletag[service]().addEventListener(eventType, _this4._onEvent.bind(_this4, eventType));
});
Expand Down
4 changes: 2 additions & 2 deletions dist/react-gpt.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Guides.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Refresh vs Re-render

GPT [requires ad unit path and size to construct an ad slot](https://developers.google.com/doubleclick-gpt/reference#googletag.defineSlot), for that reason, when `adUnitPath` or `slotSize` props change, React GPT destroys an old ad slot and creates a new one which results in rendering a new ad.
Additionally, when `outOfPage` or `content` props change, React GPT re-renders an ad to create a new ad slot to reflect these props.
Additionally, when `outOfPage`, React GPT re-renders an ad to create a new ad slot to reflect these props.
Any other ad slot related props are reflected by [refreshing an ad](https://developers.google.com/doubleclick-gpt/reference#googletag.PubAdsService_refresh).

## Per instance update vs per page update
Expand Down
1 change: 0 additions & 1 deletion docs/api/ReactGPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ A React component which renders [GPT](https://support.google.com/dfp_sb/answer/1
- `sizeMapping`(optional) - An optional array of object which contains an array of viewport size and slot size. This needs to be set if the ad needs to serve different ad sizes per different viewport sizes (responsive ad). Setting the `slot` to any dimension that's not configured in DFP results in rendering an empty ad. The ad slot size which is provided for the viewport size of [0, 0] will be used as default ad size if none of viewport size matches.
- `outOfPage`(optional) - An optional flag to indicate whether an ad slot should be out-of-page slot.
- `companionAdService`(optional) - An optional flag to indicate whether companion ad service should be enabled for the ad. If an object is passed, it takes as a configuration expecting `enableSyncLoading` or `refreshUnfilledSlots`.
- `content`(optional) - An optional HTML content for the slot. If specified, the ad will render with the HTML content using content service.
- `clickUrl`(optional) - An optional click through URL. If specified, any landing page URL associated with the creative that is served is overridden.
- `categoryExclusion`(optional) - An optional string or an array of string which specifies a page-level ad category exclusion for the given label name.
- `attributes`(optional) - An optional map of key-value pairs for an AdSense attribute on a particular ad slot. see [the list of supported key value](https://developers.google.com/doubleclick-gpt/adsense_attributes#adsense_parameters.googletag.Slot)
Expand Down
36 changes: 5 additions & 31 deletions es/Bling.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ var Bling = (_temp2 = _class = function (_Component) {
categoryExclusion = props.categoryExclusion,
collapseEmptyDiv = props.collapseEmptyDiv,
safeFrameConfig = props.safeFrameConfig,
content = props.content,
clickUrl = props.clickUrl,
forceSafeFrame = props.forceSafeFrame;

Expand Down Expand Up @@ -433,42 +432,23 @@ var Bling = (_temp2 = _class = function (_Component) {
}

// GPT checks if the same service is already added.
if (content) {
adSlot.addService(Bling._adManager.googletag.content());
} else {
adSlot.addService(Bling._adManager.googletag.pubads());
}
adSlot.addService(Bling._adManager.googletag.pubads());
}
}, {
key: "display",
value: function display() {
var content = this.props.content;

var divId = this._divId;
var adSlot = this._adSlot;

if (content) {
Bling._adManager.googletag.content().setContent(adSlot, content);
} else {
Bling._adManager.googletag.display(divId);
if (Bling._adManager._disableInitialLoad && !Bling._adManager._initialRender) {
this.refresh();
}
Bling._adManager.googletag.display(divId);
if (Bling._adManager._disableInitialLoad && !Bling._adManager._initialRender) {
this.refresh();
}
}
}, {
key: "clear",
value: function clear() {
var adSlot = this._adSlot;
if (adSlot && adSlot.hasOwnProperty("getServices")) {
// googletag.ContentService doesn't clear content
var services = adSlot.getServices();
if (this._divId && services.some(function (s) {
return !!s.setContent;
})) {
document.getElementById(this._divId).innerHTML = "";
return;
}
Bling._adManager.clear([adSlot]);
}
}
Expand Down Expand Up @@ -749,12 +729,6 @@ var Bling = (_temp2 = _class = function (_Component) {
* @property companionAdService
*/
companionAdService: _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.object]),
/**
* An optional HTML content for the slot. If specified, the ad will render with the HTML content using content service.
*
* @property content
*/
content: _propTypes2.default.string,
/**
* An optional click through URL. If specified, any landing page URL associated with the creative that is served is overridden.
*
Expand Down Expand Up @@ -857,7 +831,7 @@ var Bling = (_temp2 = _class = function (_Component) {
* @property npa
*/
npa: _propTypes2.default.bool
}, _class.refreshableProps = ["targeting", "sizeMapping", "clickUrl", "categoryExclusion", "attributes", "collapseEmptyDiv", "companionAdService", "forceSafeFrame", "safeFrameConfig"], _class.reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content", "npa"], _class._adManager = (0, _createManager.createManager)(), _class._config = {
}, _class.refreshableProps = ["targeting", "sizeMapping", "clickUrl", "categoryExclusion", "attributes", "collapseEmptyDiv", "companionAdService", "forceSafeFrame", "safeFrameConfig"], _class.reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "npa"], _class._adManager = (0, _createManager.createManager)(), _class._config = {
/**
* An optional string for GPT seed file url to override.
*/
Expand Down
4 changes: 3 additions & 1 deletion es/createManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ var AdManager = exports.AdManager = function (_EventEmitter) {

if (!this._listening) {
[_Events2.default.SLOT_RENDER_ENDED, _Events2.default.IMPRESSION_VIEWABLE, _Events2.default.SLOT_VISIBILITY_CHANGED, _Events2.default.SLOT_LOADED].forEach(function (eventType) {
["pubads", "content", "companionAds"].forEach(function (service) {
// We have removed the "content" service because it is deprecated
// See https://developers.google.com/publisher-tag/reference#googletag.ContentService
["pubads", "companionAds"].forEach(function (service) {
// there is no API to remove listeners.
_this4.googletag[service]().addEventListener(eventType, _this4._onEvent.bind(_this4, eventType));
});
Expand Down
2 changes: 1 addition & 1 deletion es/utils/apiList.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading