Skip to content

Replace the analytics module with analytics-4 #7932

Closed
@nfmohit

Description

Feature Description

The analytics module should be replaced with analytics-4 completely. This should notably include:

  1. For components and datastore infrastructure still retrieving settings from the analytics module, update them so that they retrieve such module settings from the analytics-4 module instead.
  2. Replace all references to any user-facing string Analytics 4 with Analytics.
  3. Remove any special handling for the analytics-4 module.
  4. Remove module and datastore registration for analytics.
  5. Turn off the internal flag for the analytics-4 module.

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

Acceptance criteria

  • Any remaining usage of the analytics datastore infrastructure should be used with their respective counterpart from analytics-4.
  • Any user-facing reference to Analytics 4 should be replaced with Analytics.
  • Any special handling for the analytics-4 module should be removed (notably in regards to module activation/connection logic & dashboard sharing).
  • Module & datastore registration for the analytics module should be removed.
  • The internal flag should be removed for the analytics-4 module.

Implementation Brief

Datastore and frontend changes

  • Replace selectors using MODULES_ANALYTICS store to use MODULES_ANALYTICS_4 store in relevant components. You can run a search for ( MODULES_ANALYTICS ) in your IDE
  • In assets/js/modules/analytics/components/settings/OptionalSettingsView.js:
    • Remove isUAConnected and anonymizeIP variables and their usage.
    • Remove current useSnippet selector and rename useGA4Snippet to useSnippet
    • Update current selectors using MODULES_ANALYTICS to use Analytics 4 store
    • Remove showIPAnonymizationSettings variable and it's usage
  • Move getServiceURL selector from assets/js/modules/analytics/datastore/service.js to the assets/js/modules/analytics-4/datastore/service.js and update the usage, so it is selected from Analytics 4 store
  • Copy any remaining files (not already migrated) to the analytics-4 counterpart folder:
    • assets/js/modules/analytics/components/settings/.
    • assets/js/modules/analytics/components/common/
    • assets/js/modules/analytics/components/setup/
    • assets/js/modules/analytics/components/dashboard
    • assets/js/modules/analytics/components/module
  • Move the assets/js/modules/analytics/util/countries-data.js and assets/js/modules/analytics/util/countries-timezones.js in case it is not migrated as part of #7928
  • Also move assets/js/modules/analytics/util/parseDimensionStringToDate.js and it's test to the analytics 4 module utils folder
  • Move assets/js/modules/analytics/datastore/__factories__ to the analytics 4 module datastore, and update it's imports
  • Rename, by excluding GA4 from their name - isGA4Connected, ga4Connected, ga4SnippetEnabled and useGA4Snippet selectors and re-visit their usage
  • Search through the codebase for Analytics 4 string, and replace it with Analytics in relevant user facing places
  • Search for filename in IDE, and look for files ending in GA4.js, remove old analytics widget that have analytics 4 counterpart and remove GA4 from analytics 4 widgets name
  • Remove usage, of old analytics, or replace it with analytics-4, where it is not needed across the remaining files. You can search for slug: 'analytics', moduleSlug="analytics", isModuleConnected( 'analytics' ), moduleName: 'analytics', modules: [ 'analytics' ] and lastly analytics.
  • From assets/js/modules/analytics/index.js, move the GA4 widgets registration to the assets/js/modules/analytics-4/index.js
  • Remove assets/js/googlesitekit-modules-analytics.js file and remove it's use from webpack entry
  • Remove assets/js/modules/analytics/

Backend changes

  • In includes/Modules/Tag_Manager.php
  • In includes/Core/Modules/Modules.php
    • Replace Analytics with Analytics_4 in $core_modules variable, and remove it from construct
    • Replace the use of Analytics class with Analytics_4 throughout the file
      • And in is_module_connected, activate_module, set_active_modules_option methods
        • Remove the inline to-do comments where applicable and modify condition to account for Analytics_4 being the only module
  • Edit includes/Core/Modules/REST_Modules_Controller.php
    • In get_rest_routes method
      • Remove this Analytics_4 check, as owner settings are transferred to analytics 4 in #7923
  • In includes/Modules/Analytics_4.php
    • Update setup_info method:
      • Set internal to false
      • Remove depends_on
    • In replicate_analytics_sharing_settings method
      • Replace Analytics class with Analytics_4
    • Search throughout the file for Analytics:: and replace with Analytics_4
    • Modify is_connected method
      • Uncomment accountID, and remove comment and adsConversionID property
  • Remove includes/Modules/Analytics.php
  • Remove includes/Modules/Analytics/

Test Coverage

  • Remove any remaining irrelevant UA related stories and tests that have GA4 counterpart
  • Replace analytics module slug with analytics-4 in tests and stories e.g. in provideModules
  • Replace analytics with analytics-4 in fixtures for module slug, where applicable, and set internal to true in assets/js/googlesitekit/modules/datastore/__fixtures__/list.json
  • Migrate any remaining relevant php tests revolving around old Analytics class to the Analytics_4Test and update Analytics_4Test - replace Analytics:: usage, etc
  • Fix any failing tests

QA Brief

  • Go through the whole Analytics flow, and verify everything is still working as intended

Changelog entry

  • Replace the legacy analytics module with analytics-4.

Metadata

Assignees

No one assigned

    Labels

    Module: AnalyticsGoogle Analytics module related issuesP2Low prioritySp Wk 2Issues to be completed in the second week of the assigned sprintType: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions