Skip to content

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

Open
wants to merge 14 commits into
base: trunk
Choose a base branch
from

Conversation

mehmoodak
Copy link
Member

@mehmoodak mehmoodak commented Apr 22, 2025

Fixes https://github.com/Automattic/loop/issues/446
Dependent on 181198-ghe-Automattic/wpcom

Proposed changes:

  • Show subscribers count from Jetpack for posts older than a day. This change is made to accurately show subscribers count on older posts.
  • Add a link which navigates the user to the Jetpack Email Stats page.
Before After
image image

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

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:

  • Go to wpcom primary site.
  • Go to the edit screen of an already published post.
  • Open Newsletter panel.
  • Here the text This post was sent to %s subscribers shows the count of current subscribers not when the email was sent.
  • Download the branch to your sandbox by following the instructions given in comment.
  • Sandbox the sites that you are going to test on (example below)
[IP ADDRESS] mehmoodak2.wordpress.com
  • Refresh the page and repeat step 3 and 4. It should now show the subscribers count when the email was sent.
  • Verify that the newly added link is taking the users to the right Jetpack Email Stats screen.
  • Verify the functionality on atomic and self hosted sites.

@mehmoodak mehmoodak self-assigned this Apr 22, 2025
Copy link
Contributor

github-actions bot commented Apr 22, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the loop-446/improve-subscriber-stats-on-editor-newsletter-panel branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack loop-446/improve-subscriber-stats-on-editor-newsletter-panel

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [JS Package] Script Data [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ RNA labels Apr 22, 2025
Copy link
Contributor

github-actions bot commented Apr 22, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: May 6, 2025
    • Code freeze: May 5, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Apr 22, 2025
@mehmoodak mehmoodak added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Apr 22, 2025
Copy link

jp-launch-control bot commented Apr 22, 2025

Code Coverage Summary

Coverage changed in 5 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/extensions/store/membership-products/resolvers.js 72/128 (56.25%) -8.84% 19 💔
projects/plugins/jetpack/extensions/shared/memberships/subscribers-affirmation.js 0/69 (0.00%) 0.00% 5 💔
projects/plugins/jetpack/extensions/store/membership-products/actions.js 37/37 (100.00%) 0.00% 0 💚
projects/plugins/jetpack/extensions/store/membership-products/reducer.js 11/12 (91.67%) 0.76% 0 💚
projects/plugins/jetpack/extensions/store/membership-products/selectors.js 25/25 (100.00%) 0.00% 0 💚

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@mehmoodak mehmoodak force-pushed the loop-446/improve-subscriber-stats-on-editor-newsletter-panel branch 4 times, most recently from 976e902 to 63bafef Compare April 23, 2025 14:49
@mehmoodak mehmoodak force-pushed the loop-446/improve-subscriber-stats-on-editor-newsletter-panel branch from 63bafef to 360a098 Compare April 23, 2025 15:02
Comment on lines 113 to 115
path: isSimpleSite()
? `/rest/v1.1/sites/${ siteId }/stats/opens/emails/${ postId }/rate`
: `/jetpack/v4/stats-app/sites/${ siteId }/stats/opens/emails/${ postId }`,
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

In Jetpack we have following stats screen. I noticed that Jetpack is calling different API's for dotcom and self hosted sites so I did the same.

Currenlty I am looking into the code about how Jetpack is making this decision.

image

Copy link
Member Author

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.

Copy link
Member Author

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.

@jeherve jeherve added [Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. and removed [Status] Needs Review This PR is ready for review. labels Apr 24, 2025
@mehmoodak mehmoodak requested a review from jeherve April 25, 2025 18:05
@@ -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();
Copy link
Member

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?

Copy link
Member Author

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.

@mehmoodak mehmoodak requested a review from jeherve April 28, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [JS Package] Script Data [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ RNA [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants