Repository navigation
Add review prompt for social plugin #27917
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8048265
Initial placement of review prompt in post publish panel
jboland88 c847359
Add ability to dismiss review prompt
jboland88 901e2bc
Update the permission check function name
jboland88 c6e97d5
changelog
jboland88 9b3aa6d
Update conditions for showing the review prompt
jboland88 42e7dd4
Merge branch 'trunk' into add/review-prompt-for-social-plugin
jboland88 f33df82
Fix project versions
jboland88 9cb73e6
Add analytics to review prompt
jboland88 34c81e5
Swap out typed URL
jboland88 86c196c
Conditionally load the connection state
jboland88 e0f1af0
Merge branch 'trunk' into add/review-prompt-for-social-plugin
jboland88 758f901
Updates based on feedback, performance improvements
jboland88 238ab43
Fix connection package JS error
jboland88 8a229b5
move analytics functionality into an existing hook, fix logic error
jboland88 aa17799
changelog
jboland88 22df7ae
Refine conditions for when the review request should show
jboland88 ca735f8
Merge branch 'trunk' into add/review-prompt-for-social-plugin
jboland88 c7085a2
Allow review prompt to be disabled via filter, add check for post alr…
jboland88 a968251
Change method for checking whether post is already shared
jboland88 a51e859
changelog
jboland88 08dcd1a
Fix meta default for already shared
jboland88 bb7faf3
version management
jboland88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/js-packages/publicize-components/changelog/add-review-prompt-for-social-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Add a review request prompt for Jetpack Social plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
projects/js-packages/publicize-components/src/components/review-prompt/index.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * Panel that requests a review of the Jetpack Social Plugin | ||
| * Shows in the post publish panel of the editor | ||
| */ | ||
|
|
||
| import { Button, ThemeProvider } from '@automattic/jetpack-components'; | ||
| import { __, sprintf } from '@wordpress/i18n'; | ||
| import { useCallback } from 'react'; | ||
| import useAnalyticsTracksForConnectedUser from '../../hooks/use-anaytics-tracks-for-connected-user'; | ||
| import styles from './styles.module.scss'; | ||
|
|
||
| const ReviewPrompt = ( { href, onClose } ) => { | ||
| const { recordEvent } = useAnalyticsTracksForConnectedUser( { | ||
| pageViewEventName: 'social_plugin_review_prompt', | ||
| pageViewNamespace: 'jetpack', | ||
| pageViewSuffix: 'view', | ||
| } ); | ||
|
|
||
| const recordReviewClick = useCallback( () => { | ||
| recordEvent( 'jetpack_social_plugin_review_prompt_new_review_click' ); | ||
| }, [ recordEvent ] ); | ||
|
|
||
| const handleDismiss = useCallback( () => { | ||
| recordEvent( 'jetpack_social_plugin_review_prompt_dismiss_click' ); | ||
| onClose(); | ||
| }, [ recordEvent, onClose ] ); | ||
|
|
||
| return ( | ||
| <ThemeProvider> | ||
| <div className={ styles.prompt }> | ||
| <h2 className={ styles.header }> | ||
| { | ||
| /* translators: %s is the celebration emoji */ | ||
| sprintf( __( 'Presto! %s', 'jetpack' ), String.fromCodePoint( 0x1f389 ) ) | ||
| } | ||
| </h2> | ||
| <p> | ||
| { __( | ||
| 'Just like that, Jetpack Social has shared your post to your connected social accounts.', | ||
| 'jetpack' | ||
| ) } | ||
| </p> | ||
| <p> | ||
| { __( | ||
| 'Please leave a review to let others know how easy getting your posts on social media can be!', | ||
| 'jetpack' | ||
| ) } | ||
| </p> | ||
| <div className={ styles.buttons }> | ||
| <Button | ||
| onClick={ recordReviewClick } | ||
| isExternalLink | ||
| href={ href } | ||
| className={ styles.button } | ||
| > | ||
| { __( 'Leave a Review', 'jetpack' ) } | ||
| </Button> | ||
| <Button onClick={ handleDismiss } variant="link" className={ styles.button }> | ||
| { __( 'Dismiss', 'jetpack' ) } | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </ThemeProvider> | ||
| ); | ||
| }; | ||
|
|
||
| export default ReviewPrompt; |
41 changes: 41 additions & 0 deletions
41
projects/js-packages/publicize-components/src/components/review-prompt/styles.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| .prompt { | ||
| border: 2px solid var( --jp-green-40 ); | ||
| border-radius: 4px; | ||
| padding: calc( var( --spacing-base ) * 2 ) calc( var( --spacing-base ) * 3 ); | ||
| display: block; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| gap: calc( var( --spacing-base ) * 3 ); | ||
| text-align: left; | ||
| background: none; | ||
| margin: 0; | ||
| width: 100%; | ||
| text-decoration: none; | ||
| color: var( --jp-gray-90 ); | ||
|
|
||
| &:focus, &:active { | ||
| outline-color: var( --jp-black ); | ||
| } | ||
|
|
||
| // somewhat unfortunate specificity override | ||
| .buttons button.button { | ||
| font-size: var( --font-body-small ); | ||
| } | ||
| } | ||
|
|
||
| .header { | ||
| font-size: var( --font-body ); | ||
| } | ||
|
|
||
| .buttons { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--spacing-base); | ||
| align-content: space-between; | ||
| } | ||
|
|
||
| .button { | ||
| width: 100%; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| } |
24 changes: 24 additions & 0 deletions
24
...publicize-components/src/hooks/use-anaytics-tracks-for-connected-user/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # useAnalyticsTracksForConnectedUser hook | ||
| This hook is used to facilitate recording of tracks analytics events, | ||
| limiting recording of events to when a user has a Jetpack connection. | ||
|
|
||
| The hook function also accepts parameters to record a "page view" event when the component renders. | ||
| ```es6 | ||
|
|
||
| const Component = () => { | ||
| const { recordEvent } = useAnalyticsTracks( { | ||
| pageViewEventName: 'view_event_name', | ||
| pageViewNamespace: 'jetpack', | ||
| pageViewSuffix: '', | ||
| } ); | ||
| const recordReviewClick = useCallback( () => { recordEvent( 'event_name', {} ) }, [] ); | ||
|
|
||
| return ( | ||
| <Button | ||
| onClick={ recordReviewClick } | ||
| > | ||
| { __( 'Leave a Review', 'jetpack' ) } | ||
| </Button> | ||
| ) | ||
| } | ||
| ``` | ||
77 changes: 77 additions & 0 deletions
77
...s-packages/publicize-components/src/hooks/use-anaytics-tracks-for-connected-user/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import jetpackAnalytics from '@automattic/jetpack-analytics'; | ||
| import { useConnection } from '@automattic/jetpack-connection'; | ||
| import { useState, useCallback, useEffect, useMemo } from 'react'; | ||
|
|
||
| const { tracks } = jetpackAnalytics; | ||
| const { recordEvent } = tracks; | ||
|
|
||
| const useAnalyticsTracksForConnectedUser = ( { | ||
| pageViewEventName, | ||
| pageViewNamespace = 'jetpack', | ||
| pageViewSuffix = 'page_view', | ||
| pageViewEventProperties = {}, | ||
| } = {} ) => { | ||
| const [ pageViewRecorded, setPageViewRecorded ] = useState( false ); | ||
| const { isUserConnected, isRegistered, userConnectionData } = useConnection(); | ||
| const { login, ID } = useMemo( () => { | ||
| return userConnectionData.currentUser?.wpcomUser || {}; | ||
| }, [ userConnectionData.currentUser ] ); | ||
|
|
||
| const recordEventAsync = useCallback( | ||
| async ( event, properties = {} ) => { | ||
| // Do nothing if there is not a connected user. | ||
| if ( ! ( isUserConnected && ID && login ) ) { | ||
| return; | ||
| } | ||
| recordEvent( event, properties ); | ||
| }, | ||
| [ isUserConnected, ID, login ] | ||
| ); | ||
|
|
||
| // Initialize Analytics identifying the user. | ||
| useEffect( () => { | ||
| if ( ! ( isUserConnected && ID && login ) ) { | ||
| return; | ||
| } | ||
| jetpackAnalytics.initialize( ID, login ); | ||
| }, [ isUserConnected, ID, login ] ); | ||
|
|
||
| /* | ||
| * Track page-view event. | ||
| * It's considered a page view event | ||
| * when the component is mounted. | ||
| */ | ||
| useEffect( () => { | ||
| const pageViewEvent = pageViewEventName | ||
| ? `${ pageViewNamespace }_${ pageViewEventName }_${ pageViewSuffix }` | ||
| : null; | ||
|
|
||
| // Also, only run if the site is registered. | ||
| if ( ! isRegistered ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( ! pageViewEvent ) { | ||
| return; | ||
| } | ||
|
|
||
| // Ensuring we only record the view event once | ||
| if ( ! pageViewRecorded ) { | ||
| recordEventAsync( pageViewEvent, pageViewEventProperties ); | ||
| setPageViewRecorded( true ); | ||
| } | ||
| }, [ | ||
| pageViewRecorded, | ||
| pageViewNamespace, | ||
| pageViewEventName, | ||
| pageViewSuffix, | ||
| isRegistered, | ||
| pageViewEventProperties, | ||
| recordEventAsync, | ||
| ] ); | ||
|
|
||
| return { | ||
| recordEvent: recordEventAsync, | ||
| }; | ||
| }; | ||
| export default useAnalyticsTracksForConnectedUser; |
4 changes: 4 additions & 0 deletions
4
projects/plugins/social/changelog/add-review-prompt-for-social-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Add a review request prompt for Jetpack Social plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 just happened to create
useAnalytics()that was merged yesterday. :) Maybe we could use that / expand on it in this PR instead of a new hook?I reached out to the Reach team about this here, and they seemed interested:
p1671107976320099-slack-C02JJ910CNL
Maybe that'd be the opportunity to start using in Jetpack Social?
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.
Ah, nice. Yeah seems like your hook is in the same spirit!
Sounds like a good plan to update the one you added instead of adding a new one.
Do you think the check for a Jetpack connected user in the hook I added is too opinionated for the
useAnalyticshook?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 may be fine in
useAnalyticsas well. I must say I haven't tested with disconnected users until now, since I had assumed the Tracks library wouldn't be enqueued anyway, so nothing would happen.