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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amp-auto-ads: Ad placement configuration errors are user errors #9001

Merged
merged 2 commits into from
Apr 28, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extensions/amp-auto-ads/0.1/ad-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {DataAttributeDef, PlacementState} from './placement';
import {dev} from '../../../src/log';
import {user} from '../../../src/log';

/** @const */
const TAG = 'amp-auto-ads';
Expand Down Expand Up @@ -85,7 +85,7 @@ export class AdStrategy {
placeNextAd_() {
const nextPlacement = this.availablePlacements_.shift();
if (!nextPlacement) {
dev().warn(TAG, 'unable to fulfill ad strategy');
user().warn(TAG, 'unable to fulfill ad strategy');
return Promise.resolve(false);
}
return nextPlacement.placeAd(this.baseAttributes_, this.adTracker_)
Expand Down
8 changes: 6 additions & 2 deletions extensions/amp-auto-ads/0.1/amp-auto-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {AdTracker, getExistingAds} from './ad-tracker';
import {AdStrategy} from './ad-strategy';
import {dev, user} from '../../../src/log';
import {user} from '../../../src/log';
import {xhrFor} from '../../../src/services';
import {getAdNetworkConfig} from './ad-network-config';
import {isExperimentOn} from '../../../src/experiments';
Expand All @@ -40,6 +40,10 @@ export class AmpAutoAds extends AMP.BaseElement {
user().assert(adNetwork, 'No AdNetworkConfig for type: ' + type);

this.getConfig_(adNetwork.getConfigUrl()).then(configObj => {
if (!configObj) {
return;
}

const placements = getPlacementsFromConfigObj(this.win, configObj);
const attributes = Object.assign(adNetwork.getAttributes(),
getAttributesFromConfigObj(configObj));
Expand Down Expand Up @@ -72,7 +76,7 @@ export class AmpAutoAds extends AMP.BaseElement {
return xhrFor(this.win)
.fetchJson(configUrl, xhrInit)
.catch(reason => {
dev().error(TAG, 'amp-auto-ads config xhr failed: ' + reason);
user().error(TAG, 'amp-auto-ads config xhr failed: ' + reason);
return null;
});
}
Expand Down
16 changes: 8 additions & 8 deletions extensions/amp-auto-ads/0.1/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {dev} from '../../../src/log';
import {dev, user} from '../../../src/log';
import {getAttributesFromConfigObj} from './attributes';
import {resourcesForDoc} from '../../../src/services';
import {
Expand Down Expand Up @@ -217,7 +217,7 @@ export class Placement {
export function getPlacementsFromConfigObj(win, configObj) {
const placementObjs = configObj['placements'];
if (!placementObjs) {
dev().warn(TAG, 'No placements in config');
user().warn(TAG, 'No placements in config');
return [];
}
const placements = [];
Expand All @@ -237,18 +237,18 @@ export function getPlacementsFromConfigObj(win, configObj) {
function getPlacementsFromObject(win, placementObj, placements) {
const injector = INJECTORS[placementObj['pos']];
if (!injector) {
dev().warn(TAG, 'No injector for position');
user().warn(TAG, 'No injector for position');
return;
}
const anchor = placementObj['anchor'];
if (!anchor) {
dev().warn(TAG, 'No anchor in placement');
user().warn(TAG, 'No anchor in placement');
return;
}
const anchorElements =
getAnchorElements(win.document.documentElement, anchor);
if (!anchorElements.length) {
dev().warn(TAG, 'No anchor element found');
user().warn(TAG, 'No anchor element found');
return;
}
let margins = undefined;
Expand Down Expand Up @@ -282,7 +282,7 @@ function getPlacementsFromObject(win, placementObj, placements) {
function getAnchorElements(rootElement, anchorObj) {
const selector = anchorObj['selector'];
if (!selector) {
dev().warn(TAG, 'No selector in anchor');
user().warn(TAG, 'No selector in anchor');
return [];
}
let elements = [].slice.call(scopedQuerySelectorAll(rootElement, selector));
Expand Down Expand Up @@ -323,13 +323,13 @@ function isPositionValid(anchorElement, position) {
position == Position.BEFORE || position == Position.AFTER ?
anchorElement.parentElement : anchorElement;
if (!elementToCheckOrNull) {
dev().warn(TAG, 'Parentless anchor with BEFORE/AFTER position.');
user().warn(TAG, 'Parentless anchor with BEFORE/AFTER position.');
return false;
}
const elementToCheck = dev().assertElement(elementToCheckOrNull);
return !BLACKLISTED_ANCESTOR_TAGS.some(tagName => {
if (closestByTag(elementToCheck, tagName)) {
dev().warn(TAG, 'Placement inside blacklisted ancestor: ' + tagName);
user().warn(TAG, 'Placement inside blacklisted ancestor: ' + tagName);
return true;
}
return false;
Expand Down