-
Notifications
You must be signed in to change notification settings - Fork 42
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
[Component] GPT component #26
Conversation
@craigbilner can you please review and merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think:
Testing needs to be a little clearer with a lot less theatre around setting everything up. It's very unit test heavy and would be nice to have integration tests to verify the whole piece
The components don't seem like they all belong under the one gpt
package? There's clearly a separation between the managers and the react component. The story has a Wrapper
component which seems to glue everything together, how does this work in the real world? Would you not import the components separately?
I appreciate working within the storybook with the iframe is a bit of a hassle but would be good to see multiple ads and making sure the managers are doing their jobs? Also do we need different types/sizes of ads?
packages/gpt/ad-manager.js
Outdated
import gptManager from "./gpt-manager"; | ||
import pbjsManager from "./pbjs-manager"; | ||
|
||
function AdManager(options = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ES2015 classes across the board for consistency/readability etc.?
packages/gpt/ad-manager.js
Outdated
import pbjsManager from "./pbjs-manager"; | ||
|
||
function AdManager(options = {}) { | ||
if (!(this instanceof AdManager)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're quite far from serving ES2015+ code to the browser? So there'll be a transpile step - https://www.npmjs.com/package/babel-plugin-transform-class
packages/gpt/ad-manager.js
Outdated
} | ||
|
||
this.adQueue = []; | ||
this.adUnit = options.adUnit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use Object.assign(this, {...props})
here
packages/gpt/ad-manager.js
Outdated
this.initialised = false; | ||
} | ||
|
||
AdManager.prototype.isReady = function isReady() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can change to a get
packages/gpt/ad-manager.js
Outdated
gptManager.loadScript(); | ||
pbjsManager.loadScript(); | ||
|
||
series( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these libraries here? What's their value add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well.. async
helps to avoid callback hell and to better structure and organise your code and thinking. So, I would say yes, we need.
packages/gpt/ad-manager.js
Outdated
AdManager.prototype._pushAdToGPT = function pushAdToGPT( | ||
adSlotId, | ||
sizingMap, | ||
options = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
packages/gpt/ad-manager.test.js
Outdated
let AdManager; | ||
|
||
beforeEach(() => { | ||
const window = new JSDOM().window; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if we didn't do any integration testing like this at all. Everything ideally should be injectable and mockable through HOCs or other patterns. Also I'd probably make more use of jest
/enzyme
here to render into real DOMs and mock things in perhaps a more elegant way
packages/gpt/ad-manager.test.js
Outdated
it("constructor returns an AdManager instance with correct props", () => { | ||
const adManager = AdManager(managerOptions); | ||
expect(adManager).toBeInstanceOf(AdManager); | ||
expect(adManager.adUnit).toBe(managerOptions.adUnit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we wouldn't have so many asserts for a single test and at the very least have descriptions so a failure can easily be identified
packages/gpt/gpt.test.js
Outdated
.create(<GPT adManager={adManager} code="ad-header" />) | ||
.toJSON(); | ||
|
||
expect(tree).toBeTruthy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we snapshot test?
packages/gpt/gpt.web.js
Outdated
|
||
render() { | ||
const props = this.props; | ||
return <div id={props.code} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.props.code
?
076bafc
to
d8a014f
Compare
Changes Unknown when pulling da81ecc on feature/gpt-component into ** on master**. |
Changes Unknown when pulling 71af2ae on feature/gpt-component into ** on master**. |
I think all the needed changes have been addressed, can you confirm @craigbilner? |
Changes Unknown when pulling 431d9a1 on feature/gpt-component into ** on master**. |
Changes Unknown when pulling 44118f3 on feature/gpt-component into ** on master**. |
packages/gpt/ad-composer.js
Outdated
super(props); | ||
|
||
this.adManager = new AdManager({ | ||
networkId: "25436805", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be a prop for different environments
packages/gpt/ad-manager.js
Outdated
} | ||
|
||
display(callback) { | ||
if (!this.initialised) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make an assumption that this won't happen? Can we remove the defensive code to keep things cleaner? Can add a README if devs need to understand how to use it better
packages/gpt/ad-manager.js
Outdated
slot.addService(this.gptManager.googletag.pubads()); | ||
slot.defineSizeMapping(this._generateSizings(sizingMap)); | ||
|
||
// const targeting = omit(options, 'iuPartsSuffix'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
packages/gpt/gpt-manager.js
Outdated
|
||
const googletag = this.googletag; | ||
|
||
googletag.cmd.push(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this all seem quite mysterious, are there some docs we can point to with a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, all the config setup calls are commented (except probably for the first one, whose comment doesn't make much sense (fixing it now). I can also leave a comment with a link for https://developers.google.com/doubleclick-gpt/reference#googletagpubadsservice
const pbs = d.createElement("script"); | ||
pbs.async = true; | ||
pbs.type = "text/javascript"; | ||
pbs.src = "https://www.thetimes.co.uk/d/js/vendor/prebid.min-4812861170.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we raise an issue to revisit this, as it's open source shouldn't we just bundle the code as a normal vendor dependency?
44118f3
to
eb06190
Compare
Storybook relies on iframes to render stories, gpt map sizes, used to build responsive ads don't seem to work with it. This hack solves it for now until further developments on storybookjs/storybook#862
c6edee6
to
c1b1f82
Compare
fe0dfb8
to
acb59a9
Compare
* feature: add gpt component with support for header biding * fix: deal with some issues in the gpt story * fix: render ad inside storybook Storybook relies on iframes to render stories, gpt map sizes, used to build responsive ads don't seem to work with it. This hack solves it for now until further developments on storybookjs/storybook#862 * chore: document gpt story hack * chore: add tests for gpt, pbjs and ad managers * chore: add more tests for ad manager * add more tests to ad-manager * fixes here and there (console.log, typos, etc) * classes instead of functions * corrected most comments [WIP] * snapshot test * change story to render two ads in article page * quick refactor on ad manager test * alternative using react broadcast * fix tests [WIP] * snapshot tests; pbjs config; tests adapted * fix: add missing react-broadcast dep * chore: redo initialisation checks on ad, gpt and pbjs managers * remove old test * fix: jest config on gpt component * chore: remove unneeded JSDOM dev dep * fix: add section as a prop of ad composer * fix: return on all callbacks * chore: lint gpt component * fix: network id should be a prop of AdManager * chore: add comments on gpt config * chore: use promises on the gpt, pbjs and ad managers * chore: remove errors on improper class usage * CC linting err fixed; adUnit as prop * remove new.target as class constructors need to be called with new anyway * chore: increase coverage * one more test * chore: update jest configuration * prebid settings unit tests * fix: change test assumption titles * fix: test message to remember to turn ad blocker off * fix: throw error if slot does not exist * fix: use storybook url and remove transform
* feature: add gpt component with support for header biding * fix: deal with some issues in the gpt story * fix: render ad inside storybook Storybook relies on iframes to render stories, gpt map sizes, used to build responsive ads don't seem to work with it. This hack solves it for now until further developments on storybookjs/storybook#862 * chore: document gpt story hack * chore: add tests for gpt, pbjs and ad managers * chore: add more tests for ad manager * add more tests to ad-manager * fixes here and there (console.log, typos, etc) * classes instead of functions * corrected most comments [WIP] * snapshot test * change story to render two ads in article page * quick refactor on ad manager test * alternative using react broadcast * fix tests [WIP] * snapshot tests; pbjs config; tests adapted * fix: add missing react-broadcast dep * chore: redo initialisation checks on ad, gpt and pbjs managers * remove old test * fix: jest config on gpt component * chore: remove unneeded JSDOM dev dep * fix: add section as a prop of ad composer * fix: return on all callbacks * chore: lint gpt component * fix: network id should be a prop of AdManager * chore: add comments on gpt config * chore: use promises on the gpt, pbjs and ad managers * chore: remove errors on improper class usage * CC linting err fixed; adUnit as prop * remove new.target as class constructors need to be called with new anyway * chore: increase coverage * one more test * chore: update jest configuration * prebid settings unit tests * fix: change test assumption titles * fix: test message to remember to turn ad blocker off * fix: throw error if slot does not exist * fix: use storybook url and remove transform
An ad component and its related parts, already supporting header biding also. It's still a work in progress, probably lacking further tests for the
ad-manager
.