-
Notifications
You must be signed in to change notification settings - Fork 328
Enhancement/11435 Create EmailReporting Settings Analytics Disconnected notice #11831
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
jimmymadon
wants to merge
20
commits into
develop
Choose a base branch
from
enhancement/11435-create-emailreporting-settings-analytics-disconnected-notice
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+458
−4
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
088c28a
Add a new setting to track if analytics was connected.
jimmymadon 0ada451
Expose the setting at a new core site endpoint.
jimmymadon 92409c2
Update constructor signature of REST controller.
jimmymadon 3e5bb7c
Set the analytics was connected flag to true when analytics is deacti…
jimmymadon 962cd7b
Add a simple fetch store to access the was analytics connected endpoint.
jimmymadon a7d1b4a
Add a selector to access the analytics 4 was connected setting.
jimmymadon 555e05e
Add a resolver for the was analytics 4 connected setting.
jimmymadon efc0c1e
Add a notice when analytics is disconnected but was connected once.
jimmymadon 09f114e
Use the new notice in Settings Admin.
jimmymadon 8664721
Style the notice.
jimmymadon 392adaf
Update dismissed item ID.
jimmymadon 2677434
Check for email reporting enabled state instead of user subscription …
jimmymadon bd7827e
Fix selector.
jimmymadon 7575fdd
Add tests for the analytics disconnected notice.
jimmymadon 023e314
Fix existing tests.
jimmymadon 748adca
Fix other existing tests.
jimmymadon 7df48f8
Update constructor signature in PHPUnit.
jimmymadon f7218ad
Add REST route test.
jimmymadon d09f3ff
Update release version to be next.
jimmymadon 3e286ab
Add tests for new resolver and selector.
jimmymadon 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
99 changes: 99 additions & 0 deletions
99
assets/js/components/email-reporting/AnalyticsDisconnectedNotice.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,99 @@ | ||
| /** | ||
| * AnalyticsDisconnectedNotice component. | ||
| * | ||
| * Site Kit by Google, Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { useCallback } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { useDispatch, useSelect } from 'googlesitekit-data'; | ||
| import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants'; | ||
| import Notice from '@/js/components/Notice'; | ||
| import { TYPES } from '@/js/components/Notice/constants'; | ||
| import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants'; | ||
| import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants'; | ||
| import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants'; | ||
| import useActivateModuleCallback from '@/js/hooks/useActivateModuleCallback'; | ||
|
|
||
| export const EMAIL_REPORTING_ANALYTICS_DISCONNECTED_NOTICE_DISMISSED_ITEM = | ||
| 'email-reporting-analytics-disconnected-notice'; | ||
|
|
||
| export default function AnalyticsDisconnectedNotice() { | ||
| const isEmailReportingEnabled = useSelect( ( select ) => | ||
| select( CORE_SITE ).isEmailReportingEnabled() | ||
| ); | ||
|
|
||
| const isAnalyticsConnected = useSelect( ( select ) => | ||
| select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ANALYTICS_4 ) | ||
| ); | ||
|
|
||
| const wasAnalyticsConnected = useSelect( ( select ) => | ||
| select( CORE_SITE ).getWasAnalytics4Connected() | ||
| ); | ||
|
|
||
| const isDismissed = useSelect( ( select ) => | ||
| select( CORE_USER ).isItemDismissed( | ||
| EMAIL_REPORTING_ANALYTICS_DISCONNECTED_NOTICE_DISMISSED_ITEM | ||
| ) | ||
| ); | ||
|
|
||
| const { dismissItem } = useDispatch( CORE_USER ); | ||
|
|
||
| const activateAnalytics = useActivateModuleCallback( | ||
| MODULE_SLUG_ANALYTICS_4 | ||
| ); | ||
|
|
||
| const handleDismiss = useCallback( async () => { | ||
| await dismissItem( | ||
| EMAIL_REPORTING_ANALYTICS_DISCONNECTED_NOTICE_DISMISSED_ITEM | ||
| ); | ||
| }, [ dismissItem ] ); | ||
|
|
||
| if ( | ||
| ! isEmailReportingEnabled || | ||
| isDismissed !== false || | ||
| isAnalyticsConnected || | ||
| ! wasAnalyticsConnected | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Notice | ||
| className="googlesitekit-email-reporting__analytics-disconnected-notice" | ||
| type={ TYPES.WARNING } | ||
| title={ __( 'Analytics is disconnected', 'google-site-kit' ) } | ||
| description={ __( | ||
| 'Email reports won’t include Analytics data and metrics', | ||
| 'google-site-kit' | ||
| ) } | ||
| ctaButton={ { | ||
| label: __( 'Connect Analytics', 'google-site-kit' ), | ||
| onClick: activateAnalytics, | ||
| } } | ||
| dismissButton={ { | ||
| label: __( 'Got it', 'google-site-kit' ), | ||
| onClick: handleDismiss, | ||
| } } | ||
| /> | ||
| ); | ||
| } |
167 changes: 167 additions & 0 deletions
167
assets/js/components/email-reporting/AnalyticsDisconnectedNotice.test.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,167 @@ | ||
| /** | ||
| * AnalyticsDisconnectedNotice component tests. | ||
| * | ||
| * Site Kit by Google, Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { waitFor } from '@testing-library/react'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import AnalyticsDisconnectedNotice, { | ||
| EMAIL_REPORTING_ANALYTICS_DISCONNECTED_NOTICE_DISMISSED_ITEM, | ||
| } from './AnalyticsDisconnectedNotice'; | ||
| import { | ||
| createTestRegistry, | ||
| render, | ||
| fireEvent, | ||
| provideModules, | ||
| provideUserCapabilities, | ||
| provideUserAuthentication, | ||
| provideModuleRegistrations, | ||
| provideSiteInfo, | ||
| } from '../../../../tests/js/test-utils'; | ||
| import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants'; | ||
| import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants'; | ||
| import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants'; | ||
| import { mockLocation } from '../../../../tests/js/mock-browser-utils'; | ||
|
|
||
| describe( 'AnalyticsDisconnectedNotice', () => { | ||
| mockLocation(); | ||
| let registry; | ||
|
|
||
| const fetchDismissItem = new RegExp( | ||
| '^/google-site-kit/v1/core/user/data/dismiss-item' | ||
| ); | ||
| const fetchGetDismissedItems = new RegExp( | ||
| '^/google-site-kit/v1/core/user/data/dismissed-items' | ||
| ); | ||
|
|
||
| beforeEach( () => { | ||
| registry = createTestRegistry(); | ||
| provideSiteInfo( registry ); | ||
| provideUserAuthentication( registry ); | ||
| provideUserCapabilities( registry ); | ||
| provideModules( registry, [ | ||
| { | ||
| slug: MODULE_SLUG_ANALYTICS_4, | ||
| active: false, | ||
| connected: false, | ||
| }, | ||
| ] ); | ||
| provideModuleRegistrations( registry ); | ||
|
|
||
| registry.dispatch( CORE_USER ).receiveGetDismissedItems( [] ); | ||
| registry.dispatch( CORE_SITE ).receiveGetEmailReportingSettings( { | ||
| enabled: true, | ||
| } ); | ||
| registry.dispatch( CORE_SITE ).receiveGetWasAnalytics4Connected( true ); | ||
| } ); | ||
|
|
||
| it( 'renders the notice when email reporting is enabled, analytics is disconnected but was once connected and notice is not dismissed', () => { | ||
| const { getByText } = render( <AnalyticsDisconnectedNotice />, { | ||
| registry, | ||
| } ); | ||
|
|
||
| // Title and description should be present. | ||
| expect( getByText( /Analytics is disconnected/i ) ).toBeInTheDocument(); | ||
| expect( | ||
| getByText( | ||
| /Email reports won’t include Analytics data and metrics/i | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| } ); | ||
|
|
||
| it( 'renders the "Reconnect Analytics" button and activates the module on click', async () => { | ||
| const moduleActivationEndpoint = RegExp( | ||
| 'google-site-kit/v1/core/modules/data/activation' | ||
| ); | ||
|
|
||
| const userAuthenticationEndpoint = RegExp( | ||
| '^/google-site-kit/v1/core/user/data/authentication' | ||
| ); | ||
|
|
||
| fetchMock.getOnce( userAuthenticationEndpoint, { | ||
| body: { needsReauthentication: false }, | ||
| } ); | ||
|
|
||
| fetchMock.postOnce( moduleActivationEndpoint, { | ||
| body: { success: true }, | ||
| } ); | ||
|
|
||
| const { getByRole } = render( <AnalyticsDisconnectedNotice />, { | ||
| registry, | ||
| } ); | ||
|
|
||
| fireEvent.click( | ||
| getByRole( 'button', { | ||
| name: /connect analytics/i, | ||
| } ) | ||
| ); | ||
|
|
||
| await waitFor( () => | ||
| expect( fetchMock ).toHaveFetched( moduleActivationEndpoint ) | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'dismisses the notice when "Got it" is clicked', async () => { | ||
| fetchMock.getOnce( fetchGetDismissedItems, { body: [] } ); | ||
| fetchMock.postOnce( fetchDismissItem, { | ||
| body: [ | ||
| EMAIL_REPORTING_ANALYTICS_DISCONNECTED_NOTICE_DISMISSED_ITEM, | ||
| ], | ||
| } ); | ||
|
|
||
| const { getByRole } = render( <AnalyticsDisconnectedNotice />, { | ||
| registry, | ||
| } ); | ||
|
|
||
| fireEvent.click( getByRole( 'button', { name: /got it/i } ) ); | ||
|
|
||
| await waitFor( () => | ||
| expect( fetchMock ).toHaveFetched( fetchDismissItem ) | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'does not render when email reporting is disabled', () => { | ||
| registry.dispatch( CORE_SITE ).receiveGetEmailReportingSettings( { | ||
| enabled: false, | ||
| } ); | ||
|
|
||
| const { container } = render( <AnalyticsDisconnectedNotice />, { | ||
| registry, | ||
| } ); | ||
|
|
||
| expect( container ).toBeEmptyDOMElement(); | ||
| } ); | ||
|
|
||
| it( 'does not render when notice is dismissed', () => { | ||
| registry | ||
| .dispatch( CORE_USER ) | ||
| .receiveGetDismissedItems( [ | ||
| EMAIL_REPORTING_ANALYTICS_DISCONNECTED_NOTICE_DISMISSED_ITEM, | ||
| ] ); | ||
|
|
||
| const { container } = render( <AnalyticsDisconnectedNotice />, { | ||
| registry, | ||
| } ); | ||
|
|
||
| expect( container ).toBeEmptyDOMElement(); | ||
| } ); | ||
| } ); |
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
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.
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.
We can complete the coverage by including two more cases to verify that notice is not showing in these scenarios:
does not render when Analytics is activedoes not render if Analytics was once connected