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

Add NETLETIX to amp-ads plugins #9211

Merged
merged 14 commits into from May 17, 2017
Merged

Add NETLETIX to amp-ads plugins #9211

merged 14 commits into from May 17, 2017

Conversation

mschwage
Copy link
Contributor

@mschwage mschwage commented May 8, 2017

We want to enable amp-ads for our publishers.
Thanks for your support!
(note we closed the existing PR and repopened to rebase).

@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@mschwage
Copy link
Contributor Author

mschwage commented May 8, 2017

I signed it!
CLA was signed for corporation Netletix GmbH

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels May 9, 2017
@mschwage
Copy link
Contributor Author

mschwage commented May 9, 2017

@zhouyx Could you review this PR? Thank you!

Copy link
Member

@alanorozco alanorozco left a 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,
};

Copy link
Member

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)
{
Copy link
Member

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(
Copy link
Member

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"
>
Copy link
Member

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}} */
Copy link
Member

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/'
Copy link
Member

@alanorozco alanorozco May 9, 2017

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),
      }));

  // ...
}

@@ -31,7 +31,7 @@ limitations under the License.
</tr>
<tr>
<td width="40%"><strong>Required Script</strong></td>
<td><code>&lt;script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js">&lt;/script></code> Note: amp-ad may still work without this script, but we highly recommend it for future compatibility</td>
<td><code>&lt;script async custom-element="amp-ad" src="https:&sol;&sol;cdn.ampproject.org&sol;v0&sol;amp-ad-0.1.js">&lt;/script></code> Note: amp-ad may still work without this script, but we highly recommend it for future compatibility</td>
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

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!

@lannka lannka moved this from Backlog to In Review in 3P Ads & Analytics Support May 9, 2017
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;
Copy link
Member

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.

Copy link
Contributor Author

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) ||
Copy link
Member

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.

Copy link
Contributor Author

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-')) {
Copy link
Member

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
);
Copy link
Member

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
*/
Copy link
Member

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':
Copy link
Member

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
);
Copy link
Member

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.

@mschwage
Copy link
Contributor Author

@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-')) {
Copy link
Member

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'] ||
Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Member

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

Copy link
Contributor Author

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 &&
Copy link
Member

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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-indent function parameters.

@mschwage
Copy link
Contributor Author

Tried to incorporate your comments @alanorozco let me know what you think. Thanks again for your efforts!

@mschwage
Copy link
Contributor Author

@alanorozco all changes should be made and CI finished OK, can you have a look? thanks!

Copy link
Member

@alanorozco alanorozco left a 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)) {
Copy link
Member

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)) {
  // ...
}

Copy link
Contributor Author

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?)

Copy link
Contributor Author

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,
Copy link
Member

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 &&
Copy link
Member

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-')) {
  //...
}

@mschwage
Copy link
Contributor Author

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!

Copy link
Member

@alanorozco alanorozco left a 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);
Copy link
Member

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)) {
Copy link
Member

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 with nxw 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)) {
// ...
}

Copy link
Contributor Author

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,
Copy link
Member

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);
Copy link
Member

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 {
    // ...
  }
}

@mschwage
Copy link
Contributor Author

Thanks for your comments @alanorozco - looking forward to your thoughts!

@alanorozco
Copy link
Member

Thank you for your patience working on this!

The PR will be merged now. Please wait during the upcoming weeks for release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants