Skip to content

Commit

Permalink
Andrew s/dev week (#38)
Browse files Browse the repository at this point in the history
* Enable non-personalized Ads (#1)

*  Enable non-personalized Ads

According to EU regulations, it is mandatory to enable users to opt-out to tracking cookies
GPT allows us to respect this law using the `npa` flag on Ads.

* Adding npa flag to re-render props

* Fix npa variable in componentWillReceiveProps

* Increase the bundle-size to accept the new amount of code

* Changed the place where NPA is set

* Update Bling.js

Fixes an issue where `setAttributes` can be called when there is no ad slot

* Bump to 2.0.2

* chore: Update package.json

Update package.json name and urls after forking

* chore: Update API list

Update GPT API list to latest

* chore: Add prettier config (#3)

Add prettier config and fix bracket spacing mismatch

* Fixing things

* fix: Don't setState on unmounted ad (#5)

Don't set state on an unmounted ad. Cribbed from
axioscode@9425436.

* fix: Fix undefined function if apiNotReady (#6)

Fix undefined function if apiNotReady. Cribbed from
ticketmaster@5ef19b1.

* fix: Replace hasOwnProperty with more reliable check (#7)

Replace hasOwnProperty with more reliable check. Cribbed from
nfl@8826ee3.

* fix: Do not refresh all ads when new component loads (#8)

Fixes an issue where all ad slots would reload when syncCorrelator was true and a new slot was added

* refactor: Check for updateCorrelator (#9)

Check for deprecated updateCorrelator method before calling

* build: Update radium (#10)

* build: Update radium

Update radium to fix "TypeError: Cannot read property 'object' of undefined" when running examples

* Use ^

* Fixing things

* fix: Stop multiple refresh on mq change (#11)

* fix: Stop multiple refresh on mq change

Stops multiple calls to instance.refresh() on media query change. This can happen when an instance
is associated with multiple instances.

* Only debounce this.refresh

* Fix comment

* Merge it

* feat: Add support for custom refresh function (#14)

Adds the ability to specify a custom refresh function using `configure`. This function replaces the
call to `pubads().refresh`. This is useful for certain header bidding configurations, such as App
Nexus that requires to `pbjs.refresh` to be called.

* work this time

* perf: Use googletag.cmd.push instead of timeout to process queue (#16)

Use googletag.cmd.push instead of timeout to check if pubads is ready. Fixes issue with recurring
handler.

* work this time

* Update all instances of googletagservices gpt url to securepubads gpt url (#20)

* Update all instances of googletagservices gpt url to securepubads gpt url

* Add UNSAFE so we can look to update REACT

* update remaining paths; use https to avoid redirect

Co-authored-by: Andrew Berry <andrewb@users.noreply.github.com>

* update linking instructions; some cleanup (#21)

* remove enableServices timeout from GPT mock (#22)

* Release 2.1.2 (#24)

* Remove deprecated ContentService (#23)

* Remove deprecated ContentService usage

* Update test

* doc updates

Co-authored-by: Andrew Sotiriou <andrew.sotiriou@apartmenttherapy.com>

* update changelog and version in package.json (#25)

* Ton of MI updates (#26)

* Ton of MI updates

* Minor changes

* change release and update changelog (#27)

* Gregt/negative viewable threshold (#28)

* Can work with negative viewability threshold.

* Offset in log remark is now VT for clarity.

* Checking for isNaN

* removed logging

Co-authored-by: Engywook2005 <greg.thorson@apartmenttherapy.com>

* Changed version and updated changelog (#29)

* Changed version and updated changelog

* Fixed typo in package.json

Co-authored-by: Engywook2005 <greg.thorson@apartmenttherapy.com>

* Andrew s/neg vt issue (#30)

* Fixes for neg VT

* Update isHidden

* Cleanup

* Remove log

* Update call

* Release 2 1 6 (#31)

* update packageJSON version

* Update changelog

* add prepare script

* Revert "add prepare script"

This reverts commit 49fcf5b.

* React v17 support (#32)

* update deps

* update radium to version supporting react 17

* add prepare script

* remove prepare script

* findDOMNode is deprecated

* make peerDependencies more lenient

* ref needs to be on different node

* Reverting the version as i will do that in another step

---------

Co-authored-by: Andrew Sotiriou <andrew.sotiriou@apartmenttherapy.com>

* release branch (#33)

* Remove console log (#34)

* Update package and remove console log (#35)

* Gregt/lazy load (#36)

* Add stuff for lazy load

* First shot at ignoring isInViewport response.

* Will render ads even if the inviewport check fails

* Removed commented out line of code

* Version bump and changelog update

---------

Co-authored-by: Andrew Sotiriou <andrew.sotiriou@apartmenttherapy.com>
Co-authored-by: Greg Thorson <gregthorson@AT-227.local>

---------

Co-authored-by: Carlos A. Gomes <carlos-algms@users.noreply.github.com>
Co-authored-by: Carlos Gomes <carlos.gomes@omio.com>
Co-authored-by: Michael Blanchard <michael.james.blanchard@gmail.com>
Co-authored-by: Mike Kruk <mike@slytrunk.com>
Co-authored-by: Andrew Berry <andy+github@berry.email>
Co-authored-by: Andrew Berry <andrewb@users.noreply.github.com>
Co-authored-by: Greg Thorson <Engywook2005@gmail.com>
Co-authored-by: Engywook2005 <greg.thorson@apartmenttherapy.com>
Co-authored-by: Stephen Sauceda <stephen.sauceda@gmail.com>
Co-authored-by: Greg Thorson <gregthorson@AT-227.local>
  • Loading branch information
11 people committed Jan 8, 2024
1 parent 4a76651 commit d89e380
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"bundlesize": [
{
"path": "./dist/react-gpt.min.js",
"maxSize": "8.5 kB"
"maxSize": "8.53 kB"
}
]
}
49 changes: 42 additions & 7 deletions src/Bling.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,17 @@ class Bling extends React.Component {
*
* @property style
*/
style: PropTypes.object
style: PropTypes.object,
/**
* An optional property to control non-personalized Ads.
* https://support.google.com/admanager/answer/7678538
*
* Set to `true` to mark the ad request as NPA, and to `false` for ad requests that are eligible for personalized ads
* It is `false` by default, according to Google's definition.
*
* @property npa
*/
npa: PropTypes.bool
};

/**
Expand All @@ -222,7 +232,13 @@ class Bling extends React.Component {
* @property reRenderProps
* @static
*/
static reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content"];
static reRenderProps = [
"adUnitPath",
"slotSize",
"outOfPage",
"content",
"npa"
];
/**
* An instance of ad manager.
*
Expand Down Expand Up @@ -456,10 +472,9 @@ class Bling extends React.Component {
this.props,
nextProps
);
const shouldRender = !propsEqual(
reRenderProps.props,
reRenderProps.nextProps
);
const shouldRender =
!this._adSlot ||
!propsEqual(reRenderProps.props, reRenderProps.nextProps);
const shouldRefresh =
!shouldRender &&
!propsEqual(refreshableProps.props, refreshableProps.nextProps);
Expand Down Expand Up @@ -656,10 +671,12 @@ class Bling extends React.Component {
}

defineSlot() {
const {adUnitPath, outOfPage} = this.props;
const { adUnitPath, outOfPage, npa } = this.props;
const divId = this._divId;
const slotSize = this.getSlotSize();

this.handleSetNpaFlag(npa);

if (!this._adSlot) {
// May need additional OOP logic later
if (outOfPage) {
Expand Down Expand Up @@ -830,6 +847,24 @@ class Bling extends React.Component {

return <div id={this._divId} style={style} />;
}

/**
* Call pubads and set the non-personalized Ads flag, if it is not undefined.
*
* @param {boolean} npa
*/
handleSetNpaFlag(npa) {
if (npa === undefined) {
return;
}

Bling._adManager.pubadsProxy({
method: "setRequestNonPersonalizedAds",
args: [npa ? 1 : 0],
resolve: null,
reject: null
});
}
}

// proxy pubads API through Bling
Expand Down
39 changes: 39 additions & 0 deletions test/Bling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,45 @@ describe("Bling", () => {
);
});

it("call pubads API to set non-personalized Ads when npa prop is set", done => {
const spy = sinon.stub(Bling._adManager, "pubadsProxy");
const expectedParamTrue = {
method: "setRequestNonPersonalizedAds",
args: [1],
resolve: null,
reject: null
};
const expectedParamFalse = {
...expectedParamTrue,
args: [0]
};

Bling.once(Events.RENDER, () => {
expect(spy.calledWith(expectedParamTrue)).to.be.true;
expect(spy.calledWith(expectedParamFalse)).to.be.true;
spy.restore();
done();
});

// Render once to test with non-personalized ads
ReactTestUtils.renderIntoDocument(
<Bling
adUnitPath="/4595/nfl.test.open"
npa={true}
slotSize={["fluid"]}
/>
);

// Render a second time to test re-enable personalized ads
ReactTestUtils.renderIntoDocument(
<Bling
adUnitPath="/4595/nfl.test.open"
npa={false}
slotSize={["fluid"]}
/>
);
});

it("fires once event", done => {
const events = Object.keys(Events).map(key => Events[key]);

Expand Down

0 comments on commit d89e380

Please sign in to comment.