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

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

Merged
merged 3 commits into from
Apr 4, 2022

Conversation

powerivq
Copy link
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

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
Copy link
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

extensions/amp-story/1.0/test/test-amp-story.js Outdated Show resolved Hide resolved
extensions/amp-story/1.0/variable-service.js Show resolved Hide resolved
this.variables_[AnalyticsVariable.STORY_PAGE_INDEX] =
pageIndex - adsBeforePage;

const numberOfPages = pageIds.length;
Copy link
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
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
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
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
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
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)

extensions/amp-story/1.0/amp-story.js Outdated Show resolved Hide resolved
extensions/amp-story/1.0/amp-story-store-service.js Outdated Show resolved Hide resolved
Comment on lines 2381 to 2384
this.storeService_.dispatch(Action.INSERT_AD_PAGE, {
pageBeforeId,
pageToBeInsertedId,
});
Copy link
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
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
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

extensions/amp-story/1.0/progress-bar.js Outdated Show resolved Hide resolved
extensions/amp-story/1.0/test/test-amp-story.js Outdated Show resolved Hide resolved
@powerivq
Copy link
Contributor Author

@gmajoulet @mszylkowski Updated for another look.

Copy link
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

@@ -2375,6 +2360,21 @@ export class AmpStory extends AMP.BaseElement {
nextPageEl.setAttribute(Attributes.RETURN_TO, pageToBeInsertedId);
}

// Adjust the ad page's position in this.adPages_ array to reflect the actual.
const adPageIndex = this.getPageIndexById(pageToBeInsertedId);
Copy link
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
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
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
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
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
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
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
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
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -2375,6 +2360,21 @@ export class AmpStory extends AMP.BaseElement {
nextPageEl.setAttribute(Attributes.RETURN_TO, pageToBeInsertedId);
}

// Adjust the ad page's position in this.adPages_ array to reflect the actual.
Copy link
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
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
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