Skip to content

Commit

Permalink
馃悰 Fix story ads in no signing exp (ampproject#30224)
Browse files Browse the repository at this point in the history
* look for more tags

* use single selector

* cleanup
  • Loading branch information
calebcordry authored and ed-bird committed Dec 10, 2020
1 parent a2ddd86 commit ecccfef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
27 changes: 20 additions & 7 deletions extensions/amp-story-auto-ads/0.1/story-ad-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ import {
import {createShadowRootWithStyle} from '../../amp-story/1.0/utils';
import {dev, user, userAssert} from '../../../src/log';
import {dict} from '../../../src/utils/object';
import {getA4AMetaTags, getFrameDoc} from './utils';
import {getFrameDoc, getStoryAdMetaTags} from './utils';
import {getServicePromiseForDoc} from '../../../src/service';
import {parseJson} from '../../../src/json';
import {setStyle} from '../../../src/style';
import {startsWith} from '../../../src/string';

/** @const {string} */
const TAG = 'amp-story-auto-ads:page';
Expand All @@ -56,6 +57,12 @@ const GLASS_PANE_CLASS = 'i-amphtml-glass-pane';
/** @const {string} */
const DESKTOP_FULLBLEED_CLASS = 'i-amphtml-story-ad-fullbleed';

/** @const {string} */
const CTA_META_PREFIX = 'amp-cta-';

/** @const {string} */
const A4A_VARS_META_PREFIX = 'amp4ads-vars-';

/** @enum {string} */
const PageAttributes = {
LOADING: 'i-amphtml-loading',
Expand Down Expand Up @@ -419,15 +426,21 @@ export class StoryAdPage {
}

/**
* Find all `amp4ads-vars-` prefixed meta tags and store them in single obj.
* Find all `amp4ads-vars-` & `amp-cta-` prefixed meta tags and store them
* in single obj.
* @private
*/
extractA4AVars_() {
const tags = getA4AMetaTags(this.adDoc_);
iterateCursor(tags, (tag) => {
const name = tag.name.split('amp4ads-vars-')[1];
const {content} = tag;
this.a4aVars_[name] = content;
const storyMetaTags = getStoryAdMetaTags(this.adDoc_);
iterateCursor(storyMetaTags, (tag) => {
const {name, content} = tag;
if (startsWith(name, CTA_META_PREFIX)) {
const key = name.split('amp-')[1];
this.a4aVars_[key] = content;
} else if (startsWith(name, A4A_VARS_META_PREFIX)) {
const key = name.split(A4A_VARS_META_PREFIX)[1];
this.a4aVars_[key] = content;
}
});
}

Expand Down
6 changes: 3 additions & 3 deletions extensions/amp-story-auto-ads/0.1/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export function getUniqueId(win) {
}

/**
* Finds all meta tags starting with `amp4ads-vars-`.
* Finds all meta tags starting with `amp4ads-vars-` or `amp-cta`.
* @param {Document} doc
* @return {!IArrayLike}
*/
export function getA4AMetaTags(doc) {
const selector = 'meta[name^=amp4ads-vars-]';
export function getStoryAdMetaTags(doc) {
const selector = 'meta[name^=amp4ads-vars-],meta[name^=amp-cta-]';
return doc.querySelectorAll(selector);
}

Expand Down

0 comments on commit ecccfef

Please sign in to comment.