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
Don't load responsive ad if tag height is not AdSense whitelisted height #12225
Don't load responsive ad if tag height is not AdSense whitelisted height #12225
Conversation
24bc5c4
to
1b5c373
Compare
0a8639c
to
79f758f
Compare
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. |
5bd7481
to
5b75353
Compare
CLAs look good, thanks! |
67c3617
to
0339447
Compare
@@ -63,6 +63,7 @@ import {insertAnalyticsElement} from '../../../src/extension-analytics'; | |||
import { | |||
getAdSenseAmpAutoAdsExpBranch, | |||
} from '../../../ads/google/adsense-amp-auto-ads'; | |||
import {validateAdSenseData} from '../../../ads/google/utils'; |
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 introduces a dependency to 3p/
directory, which we want to avoid.
there is a TODO in doubleclick impl related to this as well. It might make sense to move the validateData
function out of 3p/
for sharing.
@keithwrightbos any thoughts where we should move this?
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.
Hey @lannka, @keithwrightbos, any updates on this?
c28ce9a
to
24a7abb
Compare
ads/google/utils.js
Outdated
// TODO: check mandatory fields | ||
validateData(data, [], [ | ||
'adClient', 'adSlot', 'adHost', 'adtest', 'tagOrigin', 'experimentId', | ||
'ampSlotIndex', 'adChannel', 'autoFormat', 'a4aUpgradeType', 'fullWidth', |
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 did you add a4aUpgradeType? That element is actually generated as part of the fast fetch flow for debugging purposes and so you can remove.
const height = Number(this.element.getAttribute('height')); | ||
|
||
// TODO: check mandatory fields | ||
validateAdSenseData(this.element.dataset, 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 don't think we should call 3p/validateData as part of Fast Fetch as its mostly related to delayed fetch implementation as adds no real value while introducing a dependency that we'd prefer it not. Instead, can you only check the responsive height requirement and do it within #isValidElement
f88c180
to
2bbad8e
Compare
924f0ba
to
acecba4
Compare
ads/google/adsense.js
Outdated
@@ -29,6 +30,15 @@ export function adsense(global, data) { | |||
['adClient', 'adSlot', 'adHost', 'adtest', 'tagOrigin', 'experimentId', | |||
'ampSlotIndex', 'adChannel', 'autoFormat', 'fullWidth']); | |||
|
|||
if (data['autoFormat'] === 'rspv') { | |||
assert( |
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.
user().assert?
ads/google/utils.js
Outdated
@@ -16,6 +16,11 @@ | |||
|
|||
import {user} from '../../src/log'; | |||
|
|||
/** | |||
* @const {number} ADSENSE_RSPV_WHITELISTED_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.
Nit: put comment above the type declaration
* @private | ||
*/ | ||
hasValidAdSenseHeight_() { | ||
return Number(this.element.getAttribute('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.
Can you user.error when hasValidAdSenseHeight_ is false to ensure there is an actionable error in the console? Also, there is no need to convert to Number as == is a type-less comparison (as opposed to === which is typed). So, '320' == 320 will return true.
@@ -132,6 +132,13 @@ describes.realWin('amp-ad-network-adsense-impl', { | |||
impl = new AmpAdNetworkAdsenseImpl(element); | |||
expect(impl.isValidElement()).to.be.true; | |||
}); | |||
it('should be NOT valid (wrong responsive ad 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.
Can you add a test that verifies that isValidElement will return true when data-auto-format=rsvp and height=320?
@@ -159,6 +160,15 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A { | |||
return this.autoFormat_ == 'rspv'; | |||
} | |||
|
|||
/** | |||
* @return {boolean} |
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.
Add a nice comment here and rename function to hasValidResponsiveHeight (AdSense is not necessary given this is within amp-ad-network-adsense-impl)?
0c3f210
to
bffaa1a
Compare
ads/google/test/test-adsense.js
Outdated
|
||
it('throws on invalid responsive ad unit height', () => { | ||
const data = {'autoFormat': 'rspv', 'height': '666'}; | ||
expect(() => { |
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.
No need for brackets, this can be: expect(() => adsense(env.win, data)).to.throw(...)
@@ -168,6 +180,15 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A { | |||
* to an amp-ad-adsense element. Thus, if we are an amp-ad, we can be sure | |||
* that it has been verified. | |||
*/ | |||
if (this.isResponsive_() && !this.hasValidResponsiveHeight_()) { |
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 looks good, just one minor change which is to remove the hasValidResponsiveHeight_ function entirely as splitting it off doesn't add much IMO:
if (this.isResponsive_() && this.element.getAttribute('height') != ADSENSE_RSPV_WHITELISTED_HEIGHT) { ... }
expect(impl.isValidElement()).to.be.true; | ||
}); | ||
it('should be NOT valid (wrong responsive ad height)', () => { | ||
element = createAdsenseImplElement( |
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.
Curious as to why in one test you create a new element/impl and in another you just set attribute? Seems setAttribute should be sufficient, no?
ads/google/adsense.js
Outdated
@@ -29,6 +31,15 @@ export function adsense(global, data) { | |||
['adClient', 'adSlot', 'adHost', 'adtest', 'tagOrigin', 'experimentId', | |||
'ampSlotIndex', 'adChannel', 'autoFormat', 'fullWidth']); | |||
|
|||
if (data['autoFormat'] === 'rspv') { |
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.
You can remove the if statement entirely by combining rspv check in assert:
user().assert(data['autoFormat'] != 'rspv' || data['height] == ADSENSE_RSPV_WHITELISTED_HEIGHT, ...)
Also do you want == or === when doing height comparison? Do you know it will always be a number as opposed to a string?
bffaa1a
to
1dfeef8
Compare
Prevent tampering with height attribute in AdSense responsive ad tags