Skip to content

Return to the Settings screen on Analytics account creation error, when initiated from that screen #12876

Description

@techanvil

Feature Description

If Analytics account creation is initiated from the Settings screen and an error occurs, the user should be returned to the Settings screen, with the error notice displayed and the account creation form repopulated with the relevant details.

This was raised in the bug bash, see this Asana task.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • When Analytics account creation is initiated from the settings edit screen and an error occurs, the user is returned to the settings edit screen.
  • The error notice is displayed and the account creation form is repopulated with the details of the account, property and data stream to create, as shown in the mock-up below.
  • The error notice looks and behaves as described in Handle Analytics account creation errors on the Analytics setup screen. #12377.
  • All form controls behave as expected - clicking Create account retries account creation, the Back button returns the user to the form variant with the dropdown to select their existing account, etc.
  • This change is gated behind the setupFlowRefresh feature flag.
Image

Implementation Brief

In includes/Modules/Analytics_4.php

  • Update Analytics_4::get_provisioning_callback_error_redirect_url() so that the setupFlowRefresh branch returns the admin URL for 'settings#/connected-services/analytics-4/edit' if $this->is_connected(), with the $error_code passed through as the accountCreationErrorCode param.

In assets/js/modules/analytics-4/components/common/AccountCreate/index.js

In assets/js/modules/analytics-4/components/settings/SettingsEdit.js

Test Coverage

In assets/js/modules/analytics-4/components/common/AccountCreate/index.test.js.

  • Cover clicking Back on a settings URL removing accountCreationErrorCode and keeping the #connected-services/analytics-4/edit route. Seed a saved accountID, dispatch setAccountID( ACCOUNT_CREATE ), and seed one account summary so the Back button renders.

Create assets/js/modules/analytics-4/components/settings/SettingsEdit.test.tsx.

  • Cover the create account form and the error notice rendering when accountCreationErrorCode is in the URL, the setupFlowRefresh flag is on, and the saved accountID points at an existing account, with accountID becoming ACCOUNT_CREATE in the store.
  • Cover SettingsForm rendering when the flag is off, even with the error code present.
  • Cover SettingsForm rendering when there is no error code.
  • Cover clicking Back rendering SettingsForm again, with accountID back at the saved value, the error code removed from the URL, and the route/hash kept.

In assets/js/modules/analytics-4/components/common/AccountCreate/index.stories.js.

  • Add a settings-context account creation error story with accountCreationErrorCode set and no showProgress, following the existing initial setup flow error stories.
  • Render the story with VIEW_CONTEXT_SETTINGS and give it a Backstop scenario.

In tests/phpunit/integration/Modules/Analytics_4Test.php.

  • Add coverage for handle_provisioning_callback() that asserts the expected redirect to the settings page if setupFlowRefresh is enabled and the $this->is_connected() for both successes and failures. Assert that the redirect behaviour is unchanged if the module is not connected.

Update any failing VRT.

QA Brief

Setup

  • Enable the setupFlowRefresh feature flag.
  • Set up Site Kit with Analytics.
  • Go to Site Kit Settings -> Analytics -> edit and choose to set up a new Analytics account.

Triggering errors

The simplest way to trigger an error is to decline the Terms of Service on the Google Analytics ToS screen. This produces the user_cancel error and routes the user back to the Analytics setup screen.

Other error variants (max_accounts_reached, generic backend errors) can be simulated by manually appending the corresponding accountCreationErrorCode query parameter to the Analytics settings edit screen URL, e.g.:

…/wp-admin/admin.php?page=googlesitekit-settings&accountCreationErrorCode=max_accounts_reached#/connected-services/analytics-4/edit

Verify the error state on the Analytics settings edit screen

  • The Analytics settings edit screen is shown in Create Account mode.
  • The form is repopulated with the values you entered before clicking "Create Account" (account name, property name, data stream name, country, timezone, etc.).
  • The error notice is shown above the form, according to the attached mock in the issue description.
  • Clicking Retry triggers a fresh account creation attempt.
  • Clicking Go to Analytics (on the user_cancel variant) navigates back to the Terms of Service screen.

Changelog entry

  • Fix Analytics account creation errors to redirect back to the Settings screen when initiated from there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityTeam MIssues for Squad 2Type: EnhancementImprovement of an existing feature

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions