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
Add NETLETIX to amp-ads plugins #9211
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
@zhouyx Could you review this PR? Thank you! |
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.
Thank you for your PR!
I raised some minor concerns, mostly about style.
Please resolve before approval.
mandatory_data: ['nxkey','nxunit','nxwidth','nxheight'], | ||
data, | ||
}; | ||
|
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.
Please only set one empty newline.
ads/netletix.js
Outdated
+ '&site=' + encodeURIComponent(nxsite) | ||
+ '&ord=' + rand; | ||
const receiveNxAction = function(event) | ||
{ |
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.
Please place the opening bracket on the same line as the assignment.
ads/netletix.js
Outdated
global.context.noContentAvailable(); | ||
break; | ||
case 'nx-identifier': | ||
window.context.reportRenderedEntityIdentifier( |
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.
Is there a reason why you're using window.context
on some lines and global.context
in others?
If not, please use only global.context
.
(If you're seeing that the behavior caused by window.context
is different than global.context
, please let us know. It could be a bug.)
ads/netletix.md
Outdated
data-nxunit="/60343726/netzathleten_.de" | ||
data-nxwidth="300" | ||
data-nxheight="250" | ||
> |
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.
Please set closing >
on the same line as the last attribute.
ads/netletix.js
Outdated
* @param {!Window} global | ||
* @param {!Object} data | ||
*/ | ||
/** @type {{nxasync:string}} */ |
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.
These @type
declarations set here don't do anything and will be ignored by the Closure compiler 🙂 Please remove.
ads/netletix.js
Outdated
const nxheight = (data.nxheight ? data.nxheight : 'fluid'); | ||
const nxv = (data.nxv ? data.nxv : '0002'); | ||
const nxsite = (data.nxsite ? data.nxsite : 'none'); | ||
const url = ls + '/pb/' |
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.
Please use assertHttpsUrl
and addParamsToUrl
from the ../src/url
package.
Three other suggestions:
- Inline the intermediate variable expressions in the params object
- Use JS-style short-circuiting for default values
- Set module-level constants for your defaults
If you employ all of these, the URL assignment snippet should look like this:
const NX_URL_HOST = 'https://call.adadapter.netzathleten-media.de';
const DEFAULT_NX_KEY = 'default';
const DEFAULT_NX_UNIT = 'default';
const DEFAULT_NX_WIDTH = 'fluid';
const DEFAULT_NX_HEIGHT = 'fluid';
const DEFAULT_NX_V = '0002';
const DEFAULT_NX_SITE = 'none';
// ...
export function netletix(global, data) {
// ...
const url = assertHttpsUrl(addParamsToUrl(
NX_URL_HOST + '/pb/' + encodeURIComponent(data.nxkey || DEFAULT_NX_KEY),
{
unit: data.nxunit || DEFAULT_NX_UNIT,
width: data.nxwidth || DEFAULT_NX_WIDTH,
height: data.nxheight || DEFAULT_NX_HEIGHT,
v: data.nxv || DEFAULT_NX_V,
site: data.nxsite || DEFAULT_NX_SITE,
ord: Math.round(Math.random() * 100000000),
}));
// ...
}
extensions/amp-ad/amp-ad.md
Outdated
@@ -31,7 +31,7 @@ limitations under the License. | |||
</tr> | |||
<tr> | |||
<td width="40%"><strong>Required Script</strong></td> | |||
<td><code><script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script></code> Note: amp-ad may still work without this script, but we highly recommend it for future compatibility</td> | |||
<td><code><script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script></code> Note: amp-ad may still work without this script, but we highly recommend it for future compatibility</td> |
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.
Please undo HTML character entity changes.
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.
Thanks for your review - apologies for having you do that many comments - so my turn again ;)
Just a sidenote on this change: i could not get CI through without that change. CI saw them as dead links; will revert nonetheless.
ads/netletix.js
Outdated
+ '&v=' + encodeURIComponent(nxv) | ||
+ '&site=' + encodeURIComponent(nxsite) | ||
+ '&ord=' + rand; | ||
const receiveNxAction = function(event) |
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.
(Nitpicking, optional)
We usually employ fat arrow functions when defining callbacks.
For consistency, it would be preferrable if you inlined the callback handler as a fat-arrow function like this:
window.addEventListener('message', event => {
// ...
});
ads/netletix.js
Outdated
global.context.renderStart(renderconfig); | ||
if (event.data.width != nxwidth || | ||
event.data.height != nxheight) { | ||
window.context.requestResize(event.data.width, event.data.height); |
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.
Overlooked this.
What are the possible values of event.data.width
and event.data.height
?
I'm a little confused since it seems that they're expected to be strings. It's fine if they're pixel values.
Please use parseInt()
in the requestResize
parameters as they're expected to be numbers.
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.
Both will now already be supplied as number so no need for parseInt here but nxwidth still remains String so will parseInt when comparing. Thanks!
ads/netletix.js
Outdated
validateData(data, | ||
global._netletix_amp.mandatory_data, global._netletix_amp.allowed_data); | ||
data.nxwidth = data.nxwidth || DEFAULT_NX_WIDTH; | ||
data.nxheight = data.nxheight || DEFAULT_NX_HEIGHT; |
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.
Please don't mutate passed parameters. There's no need to short-circuit this here since it's done in the param object below.
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.
Unfortunately i could not get around not being able to get "gulp check-types" pass without explicitely (re)setting those for use in the window.eventlistener. Not explicitely restating currently gives me "Property nxwidth never defined on Object" error.
ads/netletix.js
Outdated
global.context.renderStart(renderconfig); | ||
if (event.data.width && | ||
event.data.height && | ||
event.data.width != parseInt(global.context.data.nxwidth, 10) || |
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'm a little confused as to what you're doing here?
My previous comment meant that requestResize()
needs number parameters and the values passed to the data
object are strings.
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.
We just wanted to compare actual size to size returned from our delivered ad to resize if required. Currently Event.data is number, data.nx... is string, so you are right if we compare we have to do it the other way around since otherwise the default 'fluid' is definitely "problematic". Apologies.
ads/netletix.js
Outdated
}), data.ampSlotIndex | ||
); | ||
window.addEventListener('message', event => { | ||
if (event.data.type && startsWith(String(event.data.type), 'nx-')) { |
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.
Please use dev().assertString()
instead of type coercion.
ads/netletix.js
Outdated
site: data.nxsite || DEFAULT_NX_SITE, | ||
ord: Math.round(Math.random() * 100000000), | ||
}), data.ampSlotIndex | ||
); |
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.
Please push closing paren )
to previous line.
/** | ||
* @param {!Window} global | ||
* @param {!Object} data | ||
*/ |
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 JSdoc block should be directly above the netletix
function signature.
ads/netletix.js
Outdated
event.data.identifier | ||
); | ||
break; | ||
case 'nx-info': |
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.
Please remove empty case
.
ads/netletix.js
Outdated
case 'nx-identifier': | ||
global.context.reportRenderedEntityIdentifier( | ||
event.data.identifier | ||
); |
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.
Please push back param to previous line.
If it doesn't fit within the char limit, use 4 extra spaces for indentation and close on the same line.
@alanorozco thanks so far and once again apologies for the number of iterations! Hope i got it right this time. |
ads/netletix.js
Outdated
}), data.ampSlotIndex); | ||
window.addEventListener('message', event => { | ||
if (event.data.type && | ||
startsWith(dev().assertString(event.data.type), 'nx-')) { |
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.
Double indent startsWith
line
ads/netletix.js
Outdated
global.context.renderStart(renderconfig); | ||
if (event.data.width && | ||
event.data.height) { | ||
if (dev().assertString(event.data.width) != data['nxwidth'] || |
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.
Why are you asserting string here?
Why are you using bracket instead of dot syntax for data.nxwidth
?
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.
Switched back to dot syntax and included used parameters in a single if clause. Thanks for pointing me in the right direction.
ads/netletix.js
Outdated
event.data.height) { | ||
if (dev().assertString(event.data.width) != data['nxwidth'] || | ||
dev().assertString(event.data.height) != data['nxheight']) { | ||
global.context.requestResize(event.data.width, |
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.
If the values in event.data.width
and event.data.height
are expected to be strings, they should be parseInt
'd for requestResize
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.
ah, my bad i misunderstood your comment. both are numbers.
ads/netletix.js
Outdated
'height': event.data.height, | ||
}; | ||
global.context.renderStart(renderconfig); | ||
if (event.data.width && |
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.
If you're immediately nesting an if-condition, please only use one conjuncted expression.
ads/netletix.js
Outdated
validateData(data, | ||
global._netletix_amp.mandatory_data, global._netletix_amp.allowed_data); | ||
const url = assertHttpsUrl(addParamsToUrl( | ||
NX_URL_FULL + encodeURIComponent(data.nxkey || DEFAULT_NX_KEY), |
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.
Double-indent function parameters.
Tried to incorporate your comments @alanorozco let me know what you think. Thanks again for your efforts! |
@alanorozco all changes should be made and CI finished OK, can you have a look? thanks! |
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.
Sorry for the delay! I got unexpectedly sick. Ready to continue with this. Only a couple of comments.
ads/netletix.js
Outdated
global.context.data.nxwidth && | ||
global.context.data.nxheight) && | ||
(event.data.width.toString() != global.context.data.nxwidth || | ||
event.data.height.toString() != global.context.data.nxheight)) { |
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 you please explain what you are trying to do with all these conditions?
I believe you can just do
if (event.data.width && event.data.height &&
(event.data.width != data.width || event.data.height != data.height)) {
// ...
}
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.
Except for type conversions between event.data variables I can agree - but if we don't include data.nxwidth & data.nxheight as conditions "gulp check-types" in our local test fails - that was the main reason. Any idea on how to overcome that (or is this something we only see when testing locally?)
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 switch to your pattern by using a local const
const nxh = (data.nxheight || DEFAULT_NX_HEIGHT); const nxw = (data.nxwidth || DEFAULT_NX_WIDTH);
and then using them within the conditions - hope that approach is ok?
ads/netletix.js
Outdated
global.context.data.nxheight) && | ||
(event.data.width.toString() != global.context.data.nxwidth || | ||
event.data.height.toString() != global.context.data.nxheight)) { | ||
global.context.requestResize(event.data.width, |
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.
Please +double indent argument params.
ads/netletix.js
Outdated
ord: Math.round(Math.random() * 100000000), | ||
}), data.ampSlotIndex); | ||
window.addEventListener('message', event => { | ||
if (event.data.type && |
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.
Please +double indent second line of the condition content:
if (event.data.type &&
startsWith(dev().assertString(event.data.type), 'nx-')) {
//...
}
…rtString, conjuncted if vs. nested
Hey, @alanorozco: hope all is fine again and no worries you are still faster in reviewing than us in adapting... So highly appreciate your efforts! Hope you are OK with the solution to the conditions as outlined above - can you have a look? thanks! |
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.
Looks good! Just a few minor style concerns and you should be golden :)
ads/netletix.js
Outdated
'height': event.data.height, | ||
}; | ||
global.context.renderStart(renderconfig); | ||
const nxh = (data.nxheight || DEFAULT_NX_HEIGHT); |
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 see your problem with check-types
and I think using intermediate variables is an OK solution.
One minor request: could you define these two intermediate variables at the function level (i.e. at the beginning of the function, right after validateData
)?
ads/netletix.js
Outdated
if (event.data.width && | ||
event.data.height && | ||
(event.data.width != nxh || | ||
event.data.height != nxw)) { |
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.
Two things:
- Minor request: please fold these in one line when it fits.
- It looks like you're comparing width with
nxh
and height withnxw
and I think it should be the other way around.
if (event.data.width && event.data.height &&
(event.data.width != nxw || event.data.height != nxh)) {
// ...
}
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.
Ups, you are right in re to nxh/w thanks for highlighting!
ads/netletix.js
Outdated
event.data.height && | ||
(event.data.width != nxh || | ||
event.data.height != nxw)) { | ||
global.context.requestResize(event.data.width, |
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.
Please fold function call in one line as it fits in 80 chars.
ads/netletix.js
Outdated
v: data.nxv || DEFAULT_NX_V, | ||
site: data.nxsite || DEFAULT_NX_SITE, | ||
ord: Math.round(Math.random() * 100000000), | ||
}), data.ampSlotIndex); |
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.
Two minor requests:
- Please add one empty newline in between major blocks.
- Please indent the
url
var assignment in a way that reflects the function composition.
Example:
export function netletix(global, data) {
/*eslint "google-camelcase/google-camelcase": 0*/
global._netletix_amp = ...
validateData(...);
const url = assertHttpsUrl(
addParamsToUrl(
NX_URL_FULL + encodeURIComponent(data.nxkey || DEFAULT_NX_KEY),
{
//...
}),
data.ampSlotIndex);
window.addEventListener('message', event => {
//...
});
if (data.async && data.async.toLowerCase() === 'true') {
// ...
} else {
// ...
}
}
Thanks for your comments @alanorozco - looking forward to your thoughts! |
Thank you for your patience working on this! The PR will be merged now. Please wait during the upcoming weeks for release. |
We want to enable amp-ads for our publishers.
Thanks for your support!
(note we closed the existing PR and repopened to rebase).