diff --git a/ads/google/adsense.js b/ads/google/adsense.js index 9d7ff5b43703c..495dfb4fb0765 100644 --- a/ads/google/adsense.js +++ b/ads/google/adsense.js @@ -15,8 +15,10 @@ */ import {validateData} from '../../3p/3p'; +import {user} from '../../src/log'; import {setStyles} from '../../src/style'; import {camelCaseToDash} from '../../src/string'; +import {ADSENSE_RSPV_WHITELISTED_HEIGHT} from './utils'; /** * Make an adsense iframe. @@ -29,6 +31,15 @@ export function adsense(global, data) { ['adClient', 'adSlot', 'adHost', 'adtest', 'tagOrigin', 'experimentId', 'ampSlotIndex', 'adChannel', 'autoFormat', 'fullWidth']); + if (data['autoFormat'] === 'rspv') { + user().assert( + data['height'] === ADSENSE_RSPV_WHITELISTED_HEIGHT, + 'Specified height ' + data['height'] + + ' in tag is not equal to the required height of ' + + ADSENSE_RSPV_WHITELISTED_HEIGHT + + ' for responsive AdSense ad units.'); + } + if (global.context.clientId) { // Read by GPT for GA/GPT integration. global.gaGlobal = { diff --git a/ads/google/test/test-adsense.js b/ads/google/test/test-adsense.js index 6e1605f3c4486..9fedefb8514c9 100644 --- a/ads/google/test/test-adsense.js +++ b/ads/google/test/test-adsense.js @@ -71,4 +71,12 @@ describes.realWin('adsenseDelayedFetch', {}, env => { hid: pageViewId, }); }); + + it('throws on invalid responsive ad unit height', () => { + const data = {'autoFormat': 'rspv', 'height': '666'}; + expect(() => { + adsense(env.win, data); + }).to.throw( + /Specified height 666 in tag is not equal to the required/); + }); }); diff --git a/ads/google/utils.js b/ads/google/utils.js index 1388d16186245..470545100981c 100644 --- a/ads/google/utils.js +++ b/ads/google/utils.js @@ -16,6 +16,12 @@ import {user} from '../../src/log'; +/** + * Approved height for AdSense full-width responsive ads. + * @const {number} + */ +export const ADSENSE_RSPV_WHITELISTED_HEIGHT = 320; + /** * Given the amp-ad data attribute containing the multi-size dimensions, and a * set of primary dimensions, this function will return all valid multi-size diff --git a/examples/a4a-fullwidth.amp.html b/examples/a4a-fullwidth.amp.html index b0389b87d9cca..571059d5972a3 100644 --- a/examples/a4a-fullwidth.amp.html +++ b/examples/a4a-fullwidth.amp.html @@ -76,7 +76,7 @@

Content!

ac posuere velit semper.

- Content!
- Content! nec lectus finibus rutrum vel sed orci.

- tag is not equal to the required height of ' + + ADSENSE_RSPV_WHITELISTED_HEIGHT + + ' for responsive AdSense ad units.'); + return false; + } return !!this.element.getAttribute('data-ad-client') && this.isAmpAdElement(); } diff --git a/extensions/amp-ad-network-adsense-impl/0.1/test/test-amp-ad-network-adsense-impl.js b/extensions/amp-ad-network-adsense-impl/0.1/test/test-amp-ad-network-adsense-impl.js index c68d6e4f7c815..7934f59c56634 100644 --- a/extensions/amp-ad-network-adsense-impl/0.1/test/test-amp-ad-network-adsense-impl.js +++ b/extensions/amp-ad-network-adsense-impl/0.1/test/test-amp-ad-network-adsense-impl.js @@ -132,6 +132,18 @@ describes.realWin('amp-ad-network-adsense-impl', { impl = new AmpAdNetworkAdsenseImpl(element); expect(impl.isValidElement()).to.be.true; }); + it('should be valid (correct responsive ad height)', () => { + element.setAttribute('data-auto-format', 'rspv'); + element.setAttribute('height', '320'); + expect(impl.isValidElement()).to.be.true; + }); + it('should be NOT valid (wrong responsive ad height)', () => { + element = createAdsenseImplElement( + {'data-auto-format': 'rsvp', 'height': '666'}, doc, + 'amp-ad-network-adsense-impl'); + impl = new AmpAdNetworkAdsenseImpl(element); + expect(impl.isValidElement()).to.be.false; + }); }); describe('#extractSize', () => {