Adding a4a support to TripleLift amp-ads#6884
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.
|
| import {AmpA4A} from '../../amp-a4a/0.1/amp-a4a'; | ||
| import {base64UrlDecodeToBytes} from '../../../src/utils/base64'; | ||
|
|
||
| const AMP_SIGNATURE_HEADER = 'X-AmpAdSignature'; |
| /** | ||
| * @param {!Element} element | ||
| */ | ||
| constructor(element) { |
There was a problem hiding this comment.
Given you're only calling super, why is this necessary?
There was a problem hiding this comment.
This was actually in our template code as a placeholder, to show where initialization code could go. I'm adding comments to the template code that this is an optional block and can be removed if there is no content.
|
|
||
| /** @override */ | ||
| extractCreativeAndSignature(responseText, responseHeaders) { | ||
| var signature = null; |
There was a problem hiding this comment.
replace var with let
|
|
||
| /** @override */ | ||
| isValidElement() { | ||
| return this.element.hasAttribute('src') && this.isAmpAdElement(); |
There was a problem hiding this comment.
you should check for the src attribute within isA4A predicate as isValidElement returning false will cause the ad request to be dropped meaning it does not fallback to 3p
There was a problem hiding this comment.
I would suggest at least the same check as you have in your current 3p implementation (https://github.com/ampproject/amphtml/blob/master/ads/triplelift.js):
validateSrcPrefix('https://ib.3lift.com/', src);
|
|
||
| /** @override */ | ||
| getAdUrl() { | ||
| return this.element.getAttribute('src').replace(TRIPLELIFT_BASE_URL, TRIPLELIFT_BASE_A4A_URL); |
There was a problem hiding this comment.
Do you want to verify that the src attribute has the TRIPLELIFT_BASE_URL to start? I noticed that you're 3p implementation includes validateSrcPrefix('https://ib.3lift.com/'. Without it, this could allow a callout to ANY XHR CORS end point (e.g. src to doubleclick). This is supplied by the publisher so what if it includes javascript(sendMeYourCookies())?
There was a problem hiding this comment.
I would add check in the config use A4A predicate as well as isValidElement. Both will ensure proper value well before getAdUrl would execute.
| */ | ||
| export function tripleliftIsA4AEnabled(win, element) { | ||
| const a4aRequested = element.getAttribute('data-use-a4a'); | ||
| return !!a4aRequested; |
There was a problem hiding this comment.
Why not just
return !!element.getAttribute('data-use-a4a');
|
I have reopened the PR. Sorry I did not see notifications because the PR was closed. |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
|
||
| /** @override */ | ||
| isValidElement() { | ||
| return this.isAmpAdElement(); |
There was a problem hiding this comment.
Let's add check for src attribute and starting with base url you expect just to be safe.
There was a problem hiding this comment.
I was being overly cautious... we do not need to include it
| sandbox.restore(); | ||
| }); | ||
|
|
||
| describe('#isValidElement', () => { |
There was a problem hiding this comment.
Can we add a negative test here (create instance of amp-ad-network-triplelift element instead of amp-ad) as well as checks regarding src.
745bc5b to
f2f1af4
Compare
|
CLAs look good, thanks! |
9519e59 to
0b5bc58
Compare
| import {createElementWithAttributes} from '../../../../src/dom'; | ||
| import {createIframePromise} from '../../../../testing/iframe'; | ||
|
|
||
| describe.only('triplelift-a4a-config', () => { |
0b5bc58 to
072ba30
Compare
Issue #6883