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

🚀 Make sure amp-story ad is loaded before display #13618

Merged
merged 2 commits into from
Feb 23, 2018
Merged

🚀 Make sure amp-story ad is loaded before display #13618

merged 2 commits into from
Feb 23, 2018

Conversation

calebcordry
Copy link
Member

The idea with amp-story-auto-ads is to place an ad as the next page after a certain amount of users interactions, but only after that ad is loaded. If the ad is not loaded it will wait for another user interaction before it tries again to place the ad.

This PR ads a more realistic ad implementation (using the fake-ad component), and the logic to make sure that the loaded event has fired on the ad before it will insert the page.

* @private
*/
createPageElement_() {
const id = this.adsPlaced_ + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

adsPlaced_ => adPagesCnt_

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it problematic that this function can return two different elements with the same ID? (since adsPlaced_ is not incremented here)

Copy link
Member Author

@calebcordry calebcordry Feb 23, 2018

Choose a reason for hiding this comment

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

I addressed both of these concerns by adding a new adPagesCreated_ which is incremented inside this method. I think this is the best solution because ads can be created but never placed due to bad fetch, not loading in time etc. so they should be tallied separately. Also this helps mapping the config ad number to the id (e.g.. template ad #2 is never placed, so template ad #3 gets and id of 2)


ampStoryAdPage.appendChild(ampAd);

this.iscurrentAdLoaded_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

isCurrentAdLoaded_

Copy link
Member Author

Choose a reason for hiding this comment

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

done


if (!nextAdElement) {
if (!nextAdPageEl || !this.iscurrentAdLoaded_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

will there be race condition that a new ad is not scheduled, and an old ad gets inserted twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

There shouldn't be. It doesn't start loading the next ad until the previous add is placed. This question does make me realize that there maybe should be some logic in a future to move onto the next ad if we are sure that the previous ad will never load.

* @private
*/
createPageElement_() {
const id = this.adsPlaced_ + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it problematic that this function can return two different elements with the same ID? (since adsPlaced_ is not incremented here)

@calebcordry calebcordry merged commit 3a2d476 into ampproject:master Feb 23, 2018
@calebcordry calebcordry deleted the is-ad-loaded branch February 23, 2018 18:59
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants