Skip to content

♻️ Story: refactor to treat story ad pages as story pages#37940

Merged
powerivq merged 3 commits intoampproject:mainfrom
powerivq:story-list-refactor
Apr 4, 2022
Merged

♻️ Story: refactor to treat story ad pages as story pages#37940
powerivq merged 3 commits intoampproject:mainfrom
powerivq:story-list-refactor

Conversation

@powerivq
Copy link
Copy Markdown
Contributor

@powerivq powerivq commented Mar 23, 2022

This is so that we can put ads into the progress bar more eloquently.

@amp-owners-bot amp-owners-bot bot requested a review from gmajoulet March 23, 2022 06:13
@amp-owners-bot
Copy link
Copy Markdown

amp-owners-bot bot commented Mar 23, 2022

Hey @gmajoulet, @newmuis! These files were changed:

extensions/amp-story/1.0/amp-story.js
extensions/amp-story/1.0/progress-bar.js
extensions/amp-story/1.0/test/test-amp-story-viewer-messaging-handler.js
extensions/amp-story/1.0/test/test-amp-story.js
extensions/amp-story/1.0/test/test-variable-service.js
extensions/amp-story/1.0/variable-service.js

@powerivq powerivq removed the request for review from gmajoulet March 23, 2022 06:14
@powerivq powerivq changed the title Story: refactor to treat story ad pages as story pages ♻️ Story: refactor to treat story ad pages as story pages Mar 23, 2022
@powerivq powerivq requested a review from mszylkowski March 28, 2022 20:03
@powerivq powerivq force-pushed the story-list-refactor branch from 431f02c to 6e3078b Compare March 28, 2022 20:43
@powerivq powerivq requested a review from calebcordry March 28, 2022 20:43
@powerivq powerivq force-pushed the story-list-refactor branch from 6e3078b to 948999e Compare March 29, 2022 06:52
@powerivq powerivq force-pushed the story-list-refactor branch from 948999e to 3adbe51 Compare March 29, 2022 09:41
Copy link
Copy Markdown
Contributor

@mszylkowski mszylkowski left a comment

Choose a reason for hiding this comment

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

Would be great to have a list of things that you want to update, I've caught a few that you need to include, or keep track of them somewhere for future implementation

this.variables_[AnalyticsVariable.STORY_PAGE_INDEX] =
pageIndex - adsBeforePage;

const numberOfPages = pageIds.length;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't the number of pages here not contain the ad pages? So that the variables don't care about the ad pages.

My suggestion is at the beginning do pageIds = storeService.get().filter((id) => id.startsWith...) and then you just work with the pageIds without the ads.

You can also do if pageId.startsWith('i-amphtml-ad') {return} so that you don't run this variable update if the current page is an ad

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem is that we have this CURRENT_PAGE_INDEX, which is the index in pageIds (incl. ads). If we filter out non-ad pages beforehand, we won't be able to figure out how many ad pages we should exclude from CURRENT_PAGE_INDEX to ensure that analytics will get the same number (page index without regards to ads) as before.

});
/** @type {!Array} */ (pageIds)
// Do not show progress bar for the ad page.
.filter((id) => !id.startsWith('i-amphtml-ad-'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this not add into the progress bar the section for the ad pages? That's exactly what we want to show. You'd also need to update buildSegmentEl_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as a first step we don't show any UI change:

  1. Refactoring
  2. UI change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we want to do a pure refactoring before having another PR to show ad segments in the progress bar.

Copy link
Copy Markdown
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

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

(Did not review the variable service yet)

Comment on lines +2381 to +2384
this.storeService_.dispatch(Action.INSERT_AD_PAGE, {
pageBeforeId,
pageToBeInsertedId,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All the logic inside of the INSERT_AD_PAGE is not needed, you already have the pages array with all the IDs.
Plz delete the action, and all you need is:

    this.storeService_.dispatch(Action.SET_PAGE_IDS, this.pages_.map((el) => el.id));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This won't work as ad page elements are not ordered.

});
/** @type {!Array} */ (pageIds)
// Do not show progress bar for the ad page.
.filter((id) => !id.startsWith('i-amphtml-ad-'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as a first step we don't show any UI change:

  1. Refactoring
  2. UI change

@powerivq
Copy link
Copy Markdown
Contributor Author

@gmajoulet @mszylkowski Updated for another look.

@powerivq powerivq force-pushed the story-list-refactor branch from f490e46 to 664503e Compare March 31, 2022 22:07
@powerivq powerivq requested a review from gmajoulet March 31, 2022 23:28
Copy link
Copy Markdown
Contributor

@mszylkowski mszylkowski left a comment

Choose a reason for hiding this comment

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

In order to ensure the behavior stays consistent can you add some more tests? Eg: check variable service contains the correct index of a page that comes after an ad; check the variable service contains the correct page length, etc

}

// Adjust the ad page's position in this.adPages_ array to reflect the actual.
const adPageIndex = this.getPageIndexById(pageToBeInsertedId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is already calculated above: pageToBeInserted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This line gets the index of the page, so it is different from pageToBeInserted.

pageToBeInserted
);

this.storeService_.dispatch(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From this reordering, why not insert the ad in the right place from the start, if possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We query and insert the ad page early, way before we know where to insert it. We only determine to inject it one page before the ad page is scheduled to show. At that point, we would need to move the DOM to have it in the right place.

I suspect there could be a performance hit, but not sure if it is the reason why we don't do it. I am for it but let's leave this out of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right this is so that we can create/preload the ad element before we know if it will actually load, or even if the server will respond with an ad.

]);
await story.layoutCallback();
// Getting all the AmpStoryPage objets.
const pageElements =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pageElements is the return of createStoryWithPages, you can get it from there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.


const numberOfPages = pageIds.length;
if (numberOfPages > 0) {
if (numberOfPages === 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This if statement can be cleaner: if (numberOfPages === 1) {} else if (numberOfPages > 1) {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@powerivq powerivq force-pushed the story-list-refactor branch from 778859d to 889cdf4 Compare April 1, 2022 20:41
nextPageEl.setAttribute(Attributes.RETURN_TO, pageToBeInsertedId);
}

// Adjust the ad page's position in this.adPages_ array to reflect the actual.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this.pages_

pageToBeInserted
);

this.storeService_.dispatch(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right this is so that we can create/preload the ad element before we know if it will actually load, or even if the server will respond with an ad.

@powerivq powerivq merged commit e75f657 into ampproject:main Apr 4, 2022
@powerivq powerivq deleted the story-list-refactor branch April 4, 2022 20:17
@ampprojectbot
Copy link
Copy Markdown
Member

Warning: disparity between this PR Percy build and its main build

The Percy build for this PR was approved (either manually by a member of the AMP team, or automatically if there were no visual diffs). However, during a continuous integration step we generated another Percy build using the commit on the main branch that this PR was merged into, and there appears to be a mismatch between the two.

This is possibly an indication of an issue with this pull request, but could also be the result of flakiness. Please inspect the two builds < This PR's Percy build / main commit's Percy build > and determine further action:

  • If the disparity appears to be caused by this PR, please create an bug report or send out a new PR to fix
  • If the disparity appears to be a flake, please @-mention ampproject/wg-approvers in a comment
  • If there is no disparity and this comment was created by mistake, please @-mention ampproject/wg-infra
  • If unsure, @-mention ampproject/wg-approvers

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.

5 participants