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: implements more versatile constraints around ad placement #8293

Merged
merged 1 commit into from Mar 22, 2017
Merged

amp-auto-ads: implements more versatile constraints around ad placement #8293

merged 1 commit into from Mar 22, 2017

Conversation

tlong2
Copy link
Contributor

@tlong2 tlong2 commented Mar 21, 2017

Allows networks to specify the ad density and also define a variable spacing strategy, where ads get further spaced as more are added to the page.

@ampprojectbot
Copy link
Member

Hi, ampproject bot here! Here are a list of the owners that can approve your files.

You may leave an issue comment stating "@ampprojectbot retry!" to force me to re-evaluate this Pull Request's status

/to cramforce dvoytenko jridgewell

  • extensions/amp-auto-ads/0.1/ad-network-config.js
  • extensions/amp-auto-ads/0.1/ad-strategy.js
  • extensions/amp-auto-ads/0.1/ad-tracker.js
  • extensions/amp-auto-ads/0.1/amp-auto-ads.js
  • extensions/amp-auto-ads/0.1/test/test-ad-network-config.js
  • extensions/amp-auto-ads/0.1/test/test-ad-strategy.js
  • extensions/amp-auto-ads/0.1/test/test-ad-tracker.js
  • extensions/amp-auto-ads/0.1/test/test-amp-auto-ads.js
  • extensions/amp-auto-ads/0.1/test/test-placement.js

For any issues please file a bug at https://github.com/google/github-owners-bot/issues

@jridgewell
Copy link
Contributor

Re the failing check-types: This is due to a bad regex to include files in our closure-complier compile step. Fix is:

diff --git a/build-system/tasks/compile.js b/build-system/tasks/compile.js
index 53e004e5..4870d566 100644
--- a/build-system/tasks/compile.js
+++ b/build-system/tasks/compile.js
@@ -141,7 +141,7 @@ function compile(entryModuleFilenames, outputDir,
       // Strange access/login related files.
       'build/all/v0/*.js',
       // A4A has these cross extension deps.
-      'extensions/**/*-config.js',
+      'extensions/amp-ad-network*/**/*-config.js',
       'extensions/amp-ad/**/*.js',
       'extensions/amp-a4a/**/*.js',
       // Currently needed for crypto.js and visibility.js.

@ampprojectbot
Copy link
Member

Hi, ampproject bot here! Here are a list of the owners that can approve your files.

You may leave an issue comment stating "@ampprojectbot retry!" to force me to re-evaluate this Pull Request's status

/to cramforce dvoytenko jridgewell

  • extensions/amp-auto-ads/0.1/ad-network-config.js
  • extensions/amp-auto-ads/0.1/ad-strategy.js
  • extensions/amp-auto-ads/0.1/ad-tracker.js
  • extensions/amp-auto-ads/0.1/amp-auto-ads.js
  • extensions/amp-auto-ads/0.1/test/test-ad-network-config.js
  • extensions/amp-auto-ads/0.1/test/test-ad-strategy.js
  • extensions/amp-auto-ads/0.1/test/test-ad-tracker.js
  • extensions/amp-auto-ads/0.1/test/test-amp-auto-ads.js
  • extensions/amp-auto-ads/0.1/test/test-placement.js

/to cramforce erwinmombay

  • build-system/tasks/compile.js

For any issues please file a bug at https://github.com/google/github-owners-bot/issues

@tlong2
Copy link
Contributor Author

tlong2 commented Mar 22, 2017

Thanks Justin. Have incorporated your fix into this PR.

@lannka lannka self-requested a review March 22, 2017 18:31
@lannka lannka self-assigned this Mar 22, 2017
*/
getMinAdSpacing_() {
const adCount = this.getAdCount();
if (this.subsequentMinSpacing_.length == 0 ||
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified into a min search:

const adCount = this.getAdCount();
let spacing = this.initialMinSpacing_;
for (let i = 0; i < this.subsequentMinSpacing_.length; i++) {
  const item = this.subsequentMinSpacing_[i];
  if (item.adCount <= adCount) {
    spacing = item.spacing;
  }
}

return spacing;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const adTracker = new AdTracker(getExistingAds(this.win), MIN_AD_SPACING);
new AdStrategy(placements, attributes, adTracker, TARGET_AD_COUNT).run();
const adTracker =
new AdTracker(getExistingAds(this.win), adNetwork.getAdConstraints());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just pass in the adNetwork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From a re-usability and testability perspective it's better to only pass in what you need and adTracker only needs the AdConstraints.


/**
* Network specific constraints on the placement of ads on the page.
* @return {!./ad-tracker.AdConstraints}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jridgewell

Note: this line is causing gulp check-types to throw a WARNING: WARNING - Failed to load module "./ad-tracker.js"

Redefining the type here makes the problem go away, but that's not ideal. Is there a way to fix gulp check-types so it does the right thing? (or maybe I am missing something stupid?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Again?

const adTracker = new AdTracker(getExistingAds(this.win), MIN_AD_SPACING);
new AdStrategy(placements, attributes, adTracker, TARGET_AD_COUNT).run();
const adTracker =
new AdTracker(getExistingAds(this.win), adNetwork.getAdConstraints());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From a re-usability and testability perspective it's better to only pass in what you need and adTracker only needs the AdConstraints.

*/
getMinAdSpacing_() {
const adCount = this.getAdCount();
if (this.subsequentMinSpacing_.length == 0 ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@lannka lannka merged commit cc5560f into ampproject:master Mar 22, 2017
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants