Skip to content

Refactor and consolidate all module inline data into a single method #10988

Description

@zutigrm

Feature Description

Starting in #10165 it was proposed to refactor several methods that hook into the googlesitekit_inline_modules_data filter, so they are consolidated into a single method get_inline_data that will return all data in the single method.

For consistency, we should do this in all modules, and preferably enforce this as with an interface. We can create Module_With_Inline_data interface that will force adding get_inline_data method, and new trait Module_With_Inline_Data_Trait that will include register_inline_data method, which will hook into the googlesitekit_inline_modules_data filter and invoke get_inline_data method.

We can then refactor all modules to use this new interface and trait, and it should be used in all new modules that are created in the future.


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

Acceptance criteria

  • New interface Module_With_Inline_Data is introduced to enforce the presence of a unified method on any module that provides inline data.
  • New trait Module_With_Inline_Data_Trait is introduced to include a registration method - which will hook into the googlesitekit_inline_modules_data and use the interface enforced method as a callback
  • Existing modules with inline data should be refactored to use the interface and trait for consistency.

Implementation Brief

  • Add new interface includes/Core/Modules/Module_With_Inline_Data.php
    • It should enforce get_inline_data method which should return an array
  • Add new trait includes/Core/Modules/Module_With_Inline_Data_Trait.php
    • Include register_inline_data method which hooks into the googlesitekit_inline_modules_data and uses get_inline_data as a callback
  • Update following modules:
    • includes/Modules/Analytics_4.php
    • includes/Modules/Ads.php
    • includes/Modules/Sign_In_With_Google.php
      • Each should implement Module_With_Inline_Data interface and use Module_With_Inline_Data_Trait trait
      • Refactor existing callback for googlesitekit_inline_modules_data hook to use new method get_inline_data
      • In the register method, invoke register_inline_data
  • Search through codebase if any new module was added in the meantime which is also using the inline data, after this IB was written

Test Coverage

  • Update tests for updated modules to adapt the new method name usage

QA Brief (QA:ENG)

  • Set up Site Kit with Analytics and Ads enabled.
  • Go to the Site Kit page.
  • Type _googlesitekitModulesData in the console.
    • The object should have an ads key, whose value is an object containing:
      • supportedConversionEvents: an array of supported conversion events.
        • As a sanity check, install WooCommerce. This array should contain WooCommerce-related events (add-to-cart, purchase).
    • The object should have an analytics-4 key, whose value is an object containing:
      • customDimensionsDataAvailable
      • resourceAvailabilityDates
      • tagIDMismatch
      • newEvents
      • lostEvents
      • newBadgeEvents
    • Without setting up Sign In With Google, the object should not have sign-in-with-google.
    • After setting up Sign In With Google, the object should have the sign-in-with-google key, whose value is an object containing:
      • isWooCommerceActive
      • isWooCommerceRegistrationEnabled

Changelog entry

  • N/A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueGood first issue for new engineersP2Low priorityPHPQA: EngRequires specialized QA by an engineerTeam MIssues for Squad 2Type: EnhancementImprovement of an existing feature

    Type

    No type
    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