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 all commits
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
27 changes: 20 additions & 7 deletions extensions/amp-story-auto-ads/0.1/story-ad-page.js
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
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