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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix story ads in no signing exp #30224

Merged
merged 3 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 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,7 +39,7 @@ 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 {getA4AVarsMetaTags, getAmpCtaMetaTags, getFrameDoc} from './utils';
import {getServicePromiseForDoc} from '../../../src/service';
import {parseJson} from '../../../src/json';
import {setStyle} from '../../../src/style';
Expand Down Expand Up @@ -419,16 +419,23 @@ 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 a4aVarsTags = getA4AVarsMetaTags(this.adDoc_);
iterateCursor(a4aVarsTags, (tag) => {
const name = tag.name.split('amp4ads-vars-')[1];
const {content} = tag;
this.a4aVars_[name] = content;
});
const ampCtaTags = getAmpCtaMetaTags(this.adDoc_);
iterateCursor(ampCtaTags, (tag) => {
const name = tag.name.split('amp-')[1];
const {content} = tag;
this.a4aVars_[name] = content;
});
}

/**
Expand Down
11 changes: 10 additions & 1 deletion extensions/amp-story-auto-ads/0.1/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ export function getUniqueId(win) {
* @param {Document} doc
* @return {!IArrayLike}
*/
export function getA4AMetaTags(doc) {
export function getA4AVarsMetaTags(doc) {
const selector = 'meta[name^=amp4ads-vars-]';
return doc.querySelectorAll(selector);
}

/**
* Finds all story ad meta tags starting with `amp-cta-`.
* @param {Document} doc
* @return {!IArrayLike}
*/
export function getAmpCtaMetaTags(doc) {
return doc.querySelectorAll('meta[name^=amp-cta-]');
Copy link
Contributor

Choose a reason for hiding this comment

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

did you try one query to select both?
meta[name^=amp-cta-],meta[name^=amp4ads-vars-]

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to single selector.

}

/**
* Returns document from given iframe, or null if non FIE.
* @param {HTMLIFrameElement} iframe
Expand Down