-
Notifications
You must be signed in to change notification settings - Fork 800
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
Blog Stats Block: Include Visitors Data #35427
Conversation
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 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. 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. |
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.
It tests well and looks good to me! ❤️
@@ -34,6 +38,13 @@ function BlogStatsEdit( { attributes, className, setAttributes } ) { | |||
} | |||
}, [ postId, isModuleActive ] ); | |||
|
|||
// We don't collect visitor data for individual posts. | |||
useEffect( () => { |
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.
👍
@@ -19,10 +20,30 @@ describe( 'BlogStatsControls', () => { | |||
} ); | |||
|
|||
describe( 'Inspector settings', () => { | |||
test( 'loads and displays settings', () => { | |||
test( 'loads and displays views or visitors settings', () => { |
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 the build process is throwing an error complaining:
|
Err, it should still be there: jetpack/projects/plugins/jetpack/extensions/blocks/blog-stats/edit.js Lines 60 to 61 in 6e4ad75
Any idea on what the issue might be? |
} | ||
} | ||
|
||
$label = $attributes['label'] ? $attributes['label'] : esc_html( | ||
$fallback_label = $attributes['statsData'] === 'visitors' ? esc_html( | ||
_n( 'visitor', 'visitors', $stats, 'jetpack' ) |
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.
_n( 'visitor', 'visitors', $stats, 'jetpack' ) | |
/* Translators: Number of visitors */ | |
_n( 'visitor', 'visitors', $stats, 'jetpack' ) |
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.
Let's try 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.
Build is still failing 🤔
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.
Looks a bit ugly, but I think it relates to where the comment goes: #28351 (comment)
Just added a commit that will maybe fix it? Not sure.
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.
Was worth a try, but nope, issue seems to persist!
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.
You should be able to work around that by adding a dummy third argument, like it's done here:
jetpack/projects/plugins/jetpack/extensions/blocks/map/styles.js
Lines 22 to 25 in 7693bbd
label: | |
provider === 'mapkit' | |
? __( 'Muted', 'jetpack', /* dummy arg to avoid bad minification */ 0 ) | |
: __( 'Black & White', 'jetpack' ), |
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, done! Not sure how to check locally, but hopefully that fixes the tests.
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.
Part of the confusion is that this isn't the code causing that error, it's the JS code in edit.js
. I'll comment there with details.
You should be able to check locally with jetpack build --production plugins/jetpack
, or in projects/plugins/jetpack/
run pnpm build-production-extensions
.
Head branch was pushed to by a user without write access
Yup, this should be good! I don't believe this was previously available for single posts in the API, but from what you're saying I'm getting that this is now available? 🥳 |
@jeherve I'm afraid that we still don't have visitor data for individual posts. I think that's because it was never collected as opposed to not being exposed in the API though. We do have visitor data for the whole site though (which I think is what the original issue was about - the Blog Stats widget never allowed access to this!), so that's what this PR adds to the block. :) I've got around this by disabling the "Visitors" + "Individual post" combination. |
} | ||
} | ||
|
||
$label = $attributes['label'] ? $attributes['label'] : esc_html( | ||
$fallback_label = $attributes['statsData'] === 'visitors' ? esc_html( | ||
_n( 'visitor', 'visitors', $stats, 'jetpack' ) |
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.
Part of the confusion is that this isn't the code causing that error, it's the JS code in edit.js
. I'll comment there with details.
You should be able to check locally with jetpack build --production plugins/jetpack
, or in projects/plugins/jetpack/
run pnpm build-production-extensions
.
/* Translators: Number of visitors */ | ||
const visitorsPlaceholder = _n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 ); | ||
|
||
/* Translators: Number of views */ | ||
const viewsPlaceholder = _n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 ); |
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.
The error
[plugins/jetpack 2:10.354] [build-production-extensions] ERROR in editor-beta.js: Translator comments have gone missing for "hit"
is actually coming from here. There's a detailed explanation of what's going on at https://www.npmjs.com/package/@automattic/i18n-check-webpack-plugin#lost-comments-due-to-expression-movement, but the TL;DR is that this code is getting transformed to look something like this instead:
/* Translators: Number of visitors */
const visitorsPlaceholder = _n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 ),
viewsPlaceholder = _n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 );
/* Translators: Number of views */
(i.e. it deletes the first const
and moves the second assignment into the first one, but leaves the comment behind where it was)
This seems to work
/* Translators: Number of visitors */ | |
const visitorsPlaceholder = _n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 ); | |
/* Translators: Number of views */ | |
const viewsPlaceholder = _n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 ); | |
const | |
/* Translators: Number of visitors */ | |
visitorsPlaceholder = _n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 ), | |
/* Translators: Number of views */ | |
viewsPlaceholder = _n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 ); |
Or this
/* Translators: Number of visitors */ | |
const visitorsPlaceholder = _n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 ); | |
/* Translators: Number of views */ | |
const viewsPlaceholder = _n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 ); | |
const visitorsPlaceholder = | |
/* Translators: Number of visitors */ | |
_n( 'visitor', 'visitors', parseInt( stats ), 'jetpack', 0 ); | |
const viewsPlaceholder = | |
/* Translators: Number of views */ | |
_n( 'hit', 'hits', parseInt( stats ), 'jetpack', 0 ); |
I don't know why 924d9be didn't work. Possibly I should remove the corresponding suggestion from the doc I linked if it doesn't work anymore.
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've moved the comment and added a parameter - hopefully that works! Thanks for taking a look. :)
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.
[plugins/jetpack 2:10.961] [build-production-extensions] ERROR in editor-beta.js: Translator comments have gone missing for "visitor"
[plugins/jetpack 2:10.961] [build-production-extensions] - Translators: Number of visitors
[plugins/jetpack 2:10.961] [build-production-extensions]
[plugins/jetpack 2:10.961] [build-production-extensions] ERROR in editor-beta.js: Translator comments have gone missing for "hit"
[plugins/jetpack 2:10.961] [build-production-extensions] - Translators: Number of views
[plugins/jetpack 2:10.961] [build-production-extensions]
🤔
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.
Sorry, it looks like I committed the wrong thing. 🤦 It works fine locally for me too - re-added your suggestion now!
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.
🎉
* Add changelog * Blog Stats block: Include visitors data * Remove unneeded class name * Update projects/plugins/jetpack/extensions/blocks/blog-stats/blog-stats.php * Try fix tests * Fix translator comment * Update translator string * Fix comments again --------- Co-authored-by: Jasper Kang <[email protected]>
* Add changelog * Blog Stats block: Include visitors data * Remove unneeded class name * Update projects/plugins/jetpack/extensions/blocks/blog-stats/blog-stats.php * Try fix tests * Fix translator comment * Update translator string * Fix comments again --------- Co-authored-by: Jasper Kang <[email protected]>
Fixes #11428
Proposed changes:
Jetpack product discussion
See original issue (technically relates to the Legacy Widget, but I think it's reasonable for the block to supersede that).
Does this pull request change what data or activity we track or use?
We already use this data elsewhere, but it makes it visible in a new way.
Testing instructions:
Enable Beta blocks and add the "Blog Stats" widget to your site. You should now see two radios (an option dropdown felt very overkill for just two options, so I think a radio is most appropriate here). The new one should enable you to display your site visitors instead of views.
Note: we don't collect data of unique visitors for individual posts. You should be prevented from selecting the "Visitors" and "This individual post" combination.
cc @kangzj - sorry to give you something else to review :) for what it's worth, I think this is the only significant issue for the Legacy Widget in the backlog, so would be nice to fix it with this new block!
@jeherve - I'd appreciate your advice here regarding what you said in #11428 (comment):
My understanding is that
visitors
in the API is just that, unique visitors. WordPress.com uses that term precisely from launch here and refer to it still here. As such, I believe that the comment in #11428 (comment) was mistaken, but just wanted to make sure.