-
Notifications
You must be signed in to change notification settings - Fork 822
Newsletters: Improve subscriber count available on editor newsletter panel #43193
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
base: trunk
Are you sure you want to change the base?
Newsletters: Improve subscriber count available on editor newsletter panel #43193
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 5 files.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
976e902
to
63bafef
Compare
63bafef
to
360a098
Compare
path: isSimpleSite() | ||
? `/rest/v1.1/sites/${ siteId }/stats/opens/emails/${ postId }/rate` | ||
: `/jetpack/v4/stats-app/sites/${ siteId }/stats/opens/emails/${ postId }`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that we need 2 different endpoints to get this data. Let me know if there is a better way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was curious what the Newsletter debug tool uses and found this lib: fbhepr%2Skers%2Sjcpbz%2Sjc%2Qpbagrag%2Syvo%2Srznvy%2Qfgngf%2Srznvy%2Qfhzznel.cuc%3Se%3Q0rq77969-og
Here's where it's used: fbhepr%2Skers%2Szp%2Sarjfyrggref%2Shgvyf.cuc%3Se%3Q501s5942%26zb%3Q2628%26sv%3Q117%23117-og
Do the endpoints use the same lib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so this page is served via odyssey-stats and we are using emailStatsAlltime method from "wpcom" package to get the url. Adding a dependency just for this doesn't seems like a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also find out that we are extensively hard coding /rest/v1.1/
and /jetpack/v4/
in codebase so hardcoding these here also seems fine.
@@ -247,13 +251,17 @@ function SubscribersAffirmation( { accessLevel, prePublish = false } ) { | |||
} | |||
|
|||
const isPaidPost = accessLevel === accessOptions.paid_subscribers.key; | |||
const { status, date_gmt } = window.wp.data.select( 'core/editor' ).getCurrentPost(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could rely on useSelect
here and below maybe?
diff --git a/projects/plugins/jetpack/extensions/shared/memberships/subscribers-affirmation.js b/projects/plugins/jetpack/extensions/shared/memberships/subscribers-affirmation.js
index 505bd775e8..f65f01d81c 100644
--- a/projects/plugins/jetpack/extensions/shared/memberships/subscribers-affirmation.js
+++ b/projects/plugins/jetpack/extensions/shared/memberships/subscribers-affirmation.js
@@ -187,14 +187,20 @@ function SubscribersAffirmation( { accessLevel, prePublish = false } ) {
.some( block => block.name === paywallBlockMetadata.name )
);
- const { isScheduledPost, postCategories, postMeta } = useSelect( select => {
- const { isCurrentPostScheduled, getEditedPostAttribute } = select( editorStore );
- return {
- isScheduledPost: isCurrentPostScheduled(),
- postCategories: getEditedPostAttribute( 'categories' ),
- postMeta: getEditedPostAttribute( 'meta' ),
- };
- } );
+ const { isScheduledPost, postCategories, postMeta, status, date_gmt, postId } = useSelect(
+ select => {
+ const { isCurrentPostScheduled, getEditedPostAttribute, getCurrentPost, getCurrentPostId } =
+ select( editorStore );
+ return {
+ isScheduledPost: isCurrentPostScheduled(),
+ postCategories: getEditedPostAttribute( 'categories' ),
+ postMeta: getEditedPostAttribute( 'meta' ),
+ status: getCurrentPost()?.status,
+ date_gmt: getCurrentPost()?.date_gmt,
+ postId: getCurrentPostId(),
+ };
+ }
+ );
const isSendEmailEnabled = () => {
// Meta value is negated, "don't send", but toggle is truthy when enabled "send"
@@ -251,7 +257,6 @@ function SubscribersAffirmation( { accessLevel, prePublish = false } ) {
}
const isPaidPost = accessLevel === accessOptions.paid_subscribers.key;
- const { status, date_gmt } = window.wp.data.select( 'core/editor' ).getCurrentPost();
// To display stats from Jetpack. It is necessary to provide the accurate count for historical posts.
const isPostOlderThanADay =
status === 'publish' && new Date( date_gmt ) < new Date( Date.now() - 24 * 60 * 60 * 1000 );
@@ -297,17 +302,16 @@ function SubscribersAffirmation( { accessLevel, prePublish = false } ) {
<p>
{ createInterpolateElement( text, {
strong: <strong />,
- link: <a href={ getJetpackEmailStatsLink() } />,
+ link: <a href={ getJetpackEmailStatsLink( postId ) } />,
} ) }
</p>
);
}
-function getJetpackEmailStatsLink() {
- const { blog_id: siteId } = getSiteData()?.wpcom ?? {};
- const postId = window.wp.data.select( 'core/editor' ).getCurrentPostId();
+function getJetpackEmailStatsLink( postId ) {
+ const { blog_id } = getSiteData()?.wpcom ?? {};
- return `/wp-admin/admin.php?page=stats#!/stats/email/opens/day/${ postId }/${ siteId }`;
+ return `/wp-admin/admin.php?page=stats#!/stats/email/opens/day/${ postId }/${ blog_id }`;
}
export default SubscribersAffirmation;
We could probably do the same for fetchTotalEmailsSentCount
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the good suggestion. a080049 addressed this feedback.
Fixes https://github.com/Automattic/loop/issues/446
Dependent on 181198-ghe-Automattic/wpcom
Proposed changes:
Other information:
Jetpack product discussion
https://github.com/Automattic/loop/issues/446#issuecomment-2810411300
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
This post was sent to %s subscribers
shows the count of current subscribers not when the email was sent.