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 Story Paywall] Enable developers to specify a custom subscriptions page index #38175

Merged
merged 11 commits into from
May 16, 2022

Conversation

ychsieh
Copy link
Contributor

@ychsieh ychsieh commented May 9, 2022

Block the story if the index is not resolved yet. After amp-story-subscriptions retrieve the index specified by the developers, it would update it in store service for amp-story to unblock and conditionally show the paywall on the specified page.

From the product perspective, we decided that the index provided by developers has to be larger than 2 and not the last page of the story.

@amp-owners-bot amp-owners-bot bot requested a review from newmuis May 9, 2022 20:30
@amp-owners-bot
Copy link

amp-owners-bot bot commented May 9, 2022

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

extensions/amp-story-subscriptions/0.1/amp-story-subscriptions.js
extensions/amp-story-subscriptions/0.1/test/test-amp-story-subscriptions.js
extensions/amp-story/1.0/amp-story-store-service.js
extensions/amp-story/1.0/amp-story.js
extensions/amp-story/1.0/test/test-amp-story.js

@ychsieh ychsieh requested review from gmajoulet and removed request for newmuis May 9, 2022 20:31
@gmajoulet gmajoulet requested review from mszylkowski and removed request for gmajoulet May 10, 2022 17:39
@gmajoulet
Copy link
Contributor

/to @mszylkowski

subscriptionsState !== SubscriptionsState.DISABLED &&
this.subscriptionsPageIndex_ === -1
) {
return this.blockOnPendingSubscriptionsPageIndex_(
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you're using 2 methods that do almost the same thing: wait for the subscription to initialize. I recommend just having 1 promise that resolves when the subscriptions state and index are both resolved using Promise.all([promise1, promise2]) and do if (anything is missing on the subscriptions) {this.blockOnPendingSubscriptionsState(x, y)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So two states should be blocked and waited at different times. This is because sub state is a network request and takes much longer than getting the sub index from amp-story-subscriptions. This is why the sub index is blocked on the initial layout switchTo and the sub state is only blocked when user is trying to navigate to the page after sub index.

extensions/amp-story/1.0/amp-story.js Outdated Show resolved Hide resolved
extensions/amp-story/1.0/amp-story.js Outdated Show resolved Hide resolved
@@ -328,6 +322,14 @@ export class AmpStory extends AMP.BaseElement {

/** @private {?number} the timeout to show subscriptions dialog after delay */
this.showSubscriptionsUITimeout_ = null;

/** @private {?number} the index of the page where the paywall would be triggered. */
this.subscriptionsPageIndex_ = this.storeService_.get(
Copy link
Contributor

Choose a reason for hiding this comment

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

Getting this number will always be -1, it's not necessary to fetch it from the storeservice

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 is to potentially get the already resolved index from the store service, since the amp-story-subscriptions might already have initialized.

extensions/amp-story/1.0/amp-story.js Show resolved Hide resolved
@mszylkowski
Copy link
Contributor

Normally amp-story-subscriptions element should instantiate faster than amp-story so this should happen only rarely

amp-story has a higher chance in general of being cached in the browser, but it's correct that on new/clean domains it will load faster than amp-story in most cases. However, sometimes on really fast connections both will download at the same time so it's usually best to not assume what will load faster, and just implement your code for both scenarios :)

@ychsieh
Copy link
Contributor Author

ychsieh commented May 11, 2022

Agree and this PR is definitely targeting at taking care of both scenarios. Let me update the PR description to avoid confusions.

@ychsieh ychsieh requested a review from mszylkowski May 13, 2022 15:57
@ychsieh ychsieh requested a review from mszylkowski May 13, 2022 18:38
@ychsieh ychsieh enabled auto-merge (squash) May 13, 2022 19:03
@ychsieh ychsieh disabled auto-merge May 13, 2022 20:06
@ychsieh ychsieh merged commit 3fbb3b4 into ampproject:main May 16, 2022
westonruter added a commit that referenced this pull request May 20, 2022
…a-menu-images-validator-spec

* 'main' of github.com:ampproject/amphtml: (90 commits)
  🔥 [Story mediapool] Fix videos from mediapool with `noaudio` don't have audio when reused. (#38216)
  Hide progress bar on the control group of auto advance experiment (#38215)
  ✨ Add Bento Autocomplete Component (#37837)
  🌐 [Story subscription] Subscription localization async (#38204)
  Dable: add new optional parameter "channel" (#38199)
  ✨ [AMP Story Paywall] Enable developers to specify a custom subscriptions page index (#38175)
  SwG Release 0.1.22.217 (#38187)
  amp-script: implements new size limits for sandboxed scripts (#38185)
  🖍  Hide the system layer and progress bar in preview mode (#38163)
  added minItems (#38177)
  Prevent expandTemplate from ReDOSing (#38178)
  Change amp-story-subscriptions attribute name to reflect its flexibility (#38176)
  🐛 [Story Preview] Enable amp-video to play in preview mode (#38149)
  Added the possibility to get page count to story messaging api (#38170)
  SwG Release 0.1.22.216 (#38168)
  Allow @newmuis to update OWNERS files (#38169)
  ✨ Add Richaudience to RTC callout vendors (#38160)
  🚀  SunMedia: Update amp-ad (#38128)
  Remove option to deploy PR artifacts to a static website (#38152)
  added some vars and requests in gfksensic.json (#37722)
  ...
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.

4 participants