Skip to content

Commit 67b147e

Browse files
authored
Merge pull request nfl#97 from carlos-algms/master
Enable non-personalized Ads to support GDPR compliance
2 parents 60f6ce0 + 63391a4 commit 67b147e

File tree

3 files changed

+82
-6
lines changed

3 files changed

+82
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"bundlesize": [
127127
{
128128
"path": "./dist/react-gpt.min.js",
129-
"maxSize": "8.5 kB"
129+
"maxSize": "8.53 kB"
130130
}
131131
]
132132
}

src/Bling.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,17 @@ class Bling extends Component {
191191
*
192192
* @property style
193193
*/
194-
style: PropTypes.object
194+
style: PropTypes.object,
195+
/**
196+
* An optional property to control non-personalized Ads.
197+
* https://support.google.com/admanager/answer/7678538
198+
*
199+
* Set to `true` to mark the ad request as NPA, and to `false` for ad requests that are eligible for personalized ads
200+
* It is `false` by default, according to Google's definition.
201+
*
202+
* @property npa
203+
*/
204+
npa: PropTypes.bool
195205
};
196206

197207
/**
@@ -217,7 +227,13 @@ class Bling extends Component {
217227
* @property reRenderProps
218228
* @static
219229
*/
220-
static reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content"];
230+
static reRenderProps = [
231+
"adUnitPath",
232+
"slotSize",
233+
"outOfPage",
234+
"content",
235+
"npa"
236+
];
221237
/**
222238
* An instance of ad manager.
223239
*
@@ -387,8 +403,9 @@ class Bling extends Component {
387403
}
388404

389405
componentWillReceiveProps(nextProps) {
390-
const { propsEqual } = Bling._config;
391-
const { sizeMapping } = this.props;
406+
const {propsEqual} = Bling._config;
407+
const {sizeMapping} = this.props;
408+
392409
if (
393410
(nextProps.sizeMapping || sizeMapping) &&
394411
!propsEqual(nextProps.sizeMapping, sizeMapping)
@@ -601,10 +618,12 @@ class Bling extends Component {
601618
}
602619

603620
defineSlot() {
604-
const { adUnitPath, outOfPage } = this.props;
621+
const { adUnitPath, outOfPage, npa } = this.props;
605622
const divId = this._divId;
606623
const slotSize = this.getSlotSize();
607624

625+
this.handleSetNpaFlag(npa);
626+
608627
if (!this._adSlot) {
609628
if (outOfPage) {
610629
this._adSlot = Bling._adManager.googletag.defineOutOfPageSlot(
@@ -779,6 +798,24 @@ class Bling extends Component {
779798

780799
return <div id={this._divId} style={style} />;
781800
}
801+
802+
/**
803+
* Call pubads and set the non-personalized Ads flag, if it is not undefined.
804+
*
805+
* @param {boolean} npa
806+
*/
807+
handleSetNpaFlag(npa) {
808+
if (npa === undefined) {
809+
return;
810+
}
811+
812+
Bling._adManager.pubadsProxy({
813+
method: "setRequestNonPersonalizedAds",
814+
args: [npa ? 1 : 0],
815+
resolve: null,
816+
reject: null
817+
});
818+
}
782819
}
783820

784821
// proxy pubads API through Bling

test/Bling.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,45 @@ describe("Bling", () => {
163163
);
164164
});
165165

166+
it("call pubads API to set non-personalized Ads when npa prop is set", done => {
167+
const spy = sinon.stub(Bling._adManager, "pubadsProxy");
168+
const expectedParamTrue = {
169+
method: "setRequestNonPersonalizedAds",
170+
args: [1],
171+
resolve: null,
172+
reject: null
173+
};
174+
const expectedParamFalse = {
175+
...expectedParamTrue,
176+
args: [0]
177+
};
178+
179+
Bling.once(Events.RENDER, () => {
180+
expect(spy.calledWith(expectedParamTrue)).to.be.true;
181+
expect(spy.calledWith(expectedParamFalse)).to.be.true;
182+
spy.restore();
183+
done();
184+
});
185+
186+
// Render once to test with non-personalized ads
187+
ReactTestUtils.renderIntoDocument(
188+
<Bling
189+
adUnitPath="/4595/nfl.test.open"
190+
npa={true}
191+
slotSize={["fluid"]}
192+
/>
193+
);
194+
195+
// Render a second time to test re-enable personalized ads
196+
ReactTestUtils.renderIntoDocument(
197+
<Bling
198+
adUnitPath="/4595/nfl.test.open"
199+
npa={false}
200+
slotSize={["fluid"]}
201+
/>
202+
);
203+
});
204+
166205
it("fires once event", done => {
167206
const events = Object.keys(Events).map(key => Events[key]);
168207

0 commit comments

Comments
 (0)