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

Andrew s/slimmer even more #53

Merged
merged 12 commits into from
May 29, 2024
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
}]
},
"env": {
"browser": true,
"mocha": true
"browser": true
},
"globals": {
"expect": true,
Expand Down
19 changes: 0 additions & 19 deletions docs/Guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,3 @@ The mock file is used for unit test and potentially catches the breaking changes

There are often cases where undocumented APIs are added to the `gpt.js`, but we will not support those unless it's [officially documented](https://developers.google.com/doubleclick-gpt/reference).

## Test Mode

GPT ad uses iframe to render an ad most of the times and it often fails to render ads within the unit test which itself uses iframe in some unit test libraries such as [karma](https://github.com/karma-runner/karma).
React GPT offers the test mode where it uses the mock GPT instead of requesting `gpt.js`.

Here is an example of how to use the test mode in your unit test using [mocha](https://github.com/mochajs/mocha).

```js
import {Bling as GPT} from "react-gpt";

describe("My module", () => {
beforeEach(() => {
// create a fresh ad manager with test mode for every test.
GPT.createTestManager();
});

// your test goes here.
});
```
1 change: 0 additions & 1 deletion docs/api/ReactGPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Only `adUnitPath` is a required prop, but either `slotSize` or `sizeMapping` nee
* `refresh([slots, options])` - Refreshes the ad specified by an array of slot. If slots are not specified, it will refresh all ads. See [here](https://developers.google.com/doubleclick-gpt/reference#googletag.PubAdsService_refresh) for more details.
* `clear([slots])` - Clears the ad specifid by an array of slot. If slots are not specified, it will clear all ads. See [here](https://developers.google.com/doubleclick-gpt/reference#googletagpubadsservice) for more details.
* `updateCorrelator` - Updates the correlator value that's sent with ad requests. See [here](https://developers.google.com/doubleclick-gpt/reference#googletag.PubAdsService_updateCorrelator) for more details.
* `createTestManager` - Creates a test ad manager to use mocked GPT for unit testing.

In addition to the defined static methods above, all the supported Pubads API are exposed as static methods, too.
The list of the supported API are maintained [here](https://github.com/nfl/react-gpt/blob/master/src/createManager.js#L9) and updated based on the [GPT API Reference](https://developers.google.com/doubleclick-gpt/reference).
Expand Down
2,719 changes: 75 additions & 2,644 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 2 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"eventemitter3": "^2.0.2",
"exenv": "^1.2.2",
"hoist-non-react-statics": "^1.0.5",
"invariant": "^2.2.2",
"throttle-debounce": "^1.0.1"
},
"devDependencies": {
Expand All @@ -52,7 +51,6 @@
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.7.2",
"bundlesize": "^0.14.4",
"codecov.io": "^0.1.6",
"conventional-changelog-cli": "^1.2.0",
"core-js": "^2.2.2",
Expand All @@ -61,7 +59,6 @@
"eslint-config-nfl": "12.0.0",
"eslint-config-prettier": "^2.5.0",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-prettier": "^2.2.0",
"eslint-plugin-react": "7.3.0",
"express": "^4.13.4",
Expand All @@ -72,9 +69,7 @@
"radium": "^0.26.2",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-test-renderer": "^17.0.0",
"rimraf": "^2.5.2",
"serve-static": "^1.10.2",
"webpack": "^1.4.13",
"webpack-dev-middleware": "^1.5.1",
"webpack-dev-server": "^1.14.1"
Expand All @@ -91,25 +86,15 @@
"build:es": "BABEL_ENV=es babel --copy-files ./src -d es",
"build:umd": "NODE_ENV=development webpack src/index.js dist/react-gpt.js",
"build:umd:min": "NODE_ENV=production webpack -p src/index.js dist/react-gpt.min.js",
"bundlesize": "npm run build:umd:min && bundlesize",
"clean": "rimraf lib coverage dist lib es",
"compile": "babel src --out-dir lib",
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples/apps --inline",
"lint": "eslint --fix src test examples",
"start": "npm run build && env BABEL_ENV=examples node examples/server/index.js",
"pretest": "npm run build",
"prepublish": "npm run build && npm run build:es && npm run build:umd && npm run build:umd:min",
"test": "npm run lint && karma start"
"prepublish": "npm run build && npm run build:es && npm run build:umd && npm run build:umd:min"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"bundlesize": [
{
"path": "./dist/react-gpt.min.js",
"maxSize": "8.53 kB"
}
]
}
}
57 changes: 4 additions & 53 deletions src/Bling.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as React from "react";
import PropTypes from "prop-types";
import {debounce} from "throttle-debounce";
import invariant from "invariant";
import deepEqual from "deep-equal";
import hoistStatics from "hoist-non-react-statics";
import {Events, filterProps} from "./oneFile";
Expand Down Expand Up @@ -191,17 +190,7 @@ class Bling extends React.Component {
*
* @property style
*/
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
style: PropTypes.object
};

/**
Expand All @@ -227,13 +216,7 @@ class Bling extends React.Component {
* @property reRenderProps
* @static
*/
static reRenderProps = [
"adUnitPath",
"slotSize",
"outOfPage",
"content",
"npa"
];
static reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content"];
/**
* An instance of ad manager.
*
Expand Down Expand Up @@ -389,11 +372,6 @@ class Bling extends React.Component {
Bling._adManager.updateCorrelator();
}

static set testManager(testManager) {
invariant(testManager, "Pass in createManagerTest to mock GPT");
Bling._adManager = testManager;
}

state = {
scriptLoaded: false,
inViewport: false
Expand Down Expand Up @@ -659,12 +637,10 @@ class Bling extends React.Component {
}

defineSlot() {
const {adUnitPath, outOfPage, npa} = this.props;
const {adUnitPath, outOfPage} = 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 @@ -790,19 +766,12 @@ class Bling extends React.Component {

render() {
const {scriptLoaded} = this.state;
const {id, outOfPage, style} = this.props;
const {id, style} = this.props;
const shouldNotRender = this.notInViewport(this.props, this.state);

if (!scriptLoaded || shouldNotRender) {
let slotSize = this.getSlotSize();

if (!outOfPage) {
invariant(
slotSize,
"Either 'slotSize' or 'sizeMapping' prop needs to be set."
);
}

if (Array.isArray(slotSize) && Array.isArray(slotSize[0])) {
slotSize = slotSize[0];
}
Expand Down Expand Up @@ -835,24 +804,6 @@ 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
3 changes: 0 additions & 3 deletions src/createManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EventEmitter from "eventemitter3";
import {debounce, throttle} from "throttle-debounce";
import invariant from "invariant";
import {canUseDOM} from "exenv";
import {Events, isInViewport} from "./oneFile";

Expand Down Expand Up @@ -434,8 +433,6 @@ export class AdManager extends EventEmitter {
// A better fix to come...
if ("updateCorrelator" in this.googletag.pubads()) {
this.googletag.pubads().updateCorrelator();
} else {
console.warn("Ad: `updateCorrelator` has been removed from GPT");
}
return true;
}
Expand Down
Loading