Skip to content
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

Add Plugin Detection Logic to Ads Module Backend Infrastructure #10169

Open
2 tasks done
10upsimon opened this issue Feb 5, 2025 · 6 comments
Open
2 tasks done

Add Plugin Detection Logic to Ads Module Backend Infrastructure #10169

10upsimon opened this issue Feb 5, 2025 · 6 comments
Assignees
Labels
Module: Ads Google Ads module related issues P1 Medium priority PHP Team S Issues for Squad 1 Type: Enhancement Improvement of an existing feature

Comments

@10upsimon
Copy link
Collaborator

10upsimon commented Feb 5, 2025

Feature Description

In order for the WooCommerce redirect logic to be correctly implemented across all areas of the epic, the core foundation of the feature - which is plugin detection - should be implemented with the Ads module backend infrastructure. This logic will aid surfacing of specific plugin related information, name for the the following plugins (including the details for each):

  • WooCommerce
    • Whether the plugin is installed or not
    • Whether the plugin is active or not
  • Google for WooCommerce
    • Whether the plugins is installed or not
    • Wether the plugin is active or not
    • Whether there is an Ads account linked to Google for WooCommerce or not

The status of each of the above plugins is to be surfaced in a new plugins object with the ads module base data. Therefore, plugin detection logic may reside in the main Ads.php file at includes/Modules/Ads.php.

Logic for detecting the presence and active/inactive state for each plugin can be borrowed from the Developer_Plugin_Installer class at includes/Core/Util/Developer_Plugin_Installer.php. This new logic should likely reside within a new plugin detection class, generic or specific to the WooCommerce body of work, whichever is more fitting.

This section is detailed in the design document under the sub heading "Infrastructure > Plugin Detection".


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

Acceptance criteria

  • When adsPax feature flag is enabled, the ads module base data should be extended to contain a new plugins object with the following entries for each:
    • woocommerce - To hold installation and active/inactive status of the WooCommerce plugin using the following properties:
      • active - Boolean, whether the plugin is active or not
      • installed - Boolean, whether the plugin is installed or not
    • google-listings-and-ads - To hold installation status, active/inactive status and linked Ads account status of the Google for WooCommerce plugin using the following properties:
      • active - Boolean, whether the plugin is active or not
      • installed - Boolean, whether the plugin is installed or not
      • adsConnected - Boolean, whether an existing Ads account has been linked to Google for WooCommerce

Implementation Brief

  • Add includes/Core/Util/Plugin_Status.php
    • Define new constants representing the states: installed, activated, and not-installed
    • Add new static method get_plugin_status , which can accept 2 arguments: plugin_path, and plugin_url.
      • Use is_plugin_active core function with plugin_path argument to check for active status and you can re-use this implementation to adapt for checking the installed status
        if ( ! function_exists( 'get_plugins' ) ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        $plugins = get_plugins();
        if ( array_key_exists( $plugin, $plugins ) ) {
        $installed = true;
        } else {
        foreach ( $plugins as $plugin_file => $installed_plugin ) {
        if ( $installed_plugin['PluginURI'] === $plugin_uri ) {
        $plugin = $plugin_file;
        $installed = true;
        break;
        }
        }
        }
        Both is_plugin_active and get_plugins need plugin.php from wp-admin/includes folder
    • It should return one of the constant values, based on the final status, so either installed, activated or not-installed string.
    • Add new method get_plugin_file to extract the $plugin_file - check the example here
      } else {
      foreach ( $plugins as $plugin_file => $installed_plugin ) {
      if ( $installed_plugin['PluginURI'] === $plugin_uri ) {
      $plugin = $plugin_file;
  • Update Google\Site_Kit\Modules\Ads::inline_modules_data method:
    • When adsPax feature flag is enabled expand the existing $modules_data['ads'] array to include:
      • woocommerce key, which should hold sub-array with following values:
        • active and installed keys with the boolean values based on the return from Plugin_Status::get_plugin_status method
          • Use woocommerce/woocommerce.php for plugin_path and https://woocommerce.com/ as plugin_url argument
      • google-listings-and-ads key, which should hold sub-array with following values:
        • active and installed - same like above, use boolean values based on the returned values from util class, by passing the google-listings-and-ads/google-listings-and-ads.php as plugin_path, and https://wordpress.org/plugins/google-listings-and-ads as plugin_url arg
        • adsConnected - if gla_ads_id option is not empty, return true
  • Refactor the referenced consent mode callback to use new util where applicable
  • Refactor Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce::is_active method to use new util for checking if plugin is active
  • In includes/Modules/Sign_In_With_Google.php, replace the usage of WooCommerce class from conversion events infrastructure and it's method $this->woocommerce->is_active() to use new util class directly, and also this check
    $is_woocommerce = class_exists( 'woocommerce' );
    to use util class directly to assess if plugin is activated

Test Coverage

  • Update tests/phpunit/integration/Modules/AdsTest.php to include new inline data in tests
  • Add basic test coverage for Plugin_Status

QA Brief

QA Involves testing this body of work, as well as smoke testing Sign in With Google WooCommerce functionality, as well as Consent Mode plugin installation.

  • Set up Site Kit with the adsPax feature flag enabled, set up GA4 at least as we'll need to smoke test Consent Mode as well
  • Type the following into console of your browser: _googlesitekitBaseData.plugins
    • Validate that it has the following data shape:
{
    "woocommerce": {
        "installed": false,
        "active": false
    },
    "google-listings-and-ads": {
        "installed": false,
        "active": false,
        "adsConnected": false
    }
}
  • Next, install WooCommerce, but do not activate it. Type the same command in the console again.
    • Validate that it now has the following data shape:
{
    "woocommerce": {
        "installed": true,
        "active": false
    },
    "google-listings-and-ads": {
        "installed": false,
        "active": false,
        "adsConnected": false
    }
}
  • Next, activate the WooCommerce plugin. Type the same command in the console again.
    • Validate that it now has the following data shape:
{
    "woocommerce": {
        "installed": true,
        "active": true
    },
    "google-listings-and-ads": {
        "installed": false,
        "active": false,
        "adsConnected": false
    }
}
  • Next, install the Google for WooCommerce plugin, but do not activate it. Type the same command in the console again.
    • Validate that it now has the following data shape:
{
    "woocommerce": {
        "installed": true,
        "active": true
    },
    "google-listings-and-ads": {
        "installed": true,
        "active": false,
        "adsConnected": false
    }
}
  • Next, activate the Google for WooCommerce plugin. Type the same command in the console again.
    • Validate that it now has the following data shape:
{
    "woocommerce": {
        "installed": true,
        "active": true
    },
    "google-listings-and-ads": {
        "installed": true,
        "active": true,
        "adsConnected": false
    }
}
  • Finally, connect your existing Ads account to Google for WooCommerce or create a new one via it. Once done, type the same command in the browser console again.
    • Validate that it now has the following data shape:
{
    "woocommerce": {
        "installed": true,
        "active": true
    },
    "google-listings-and-ads": {
        "installed": true,
        "active": true,
        "adsConnected": true
    }
}
  • Perform a brief smoke test of the Sign in With Google functionality related to WooCommerce
  • Perform a brief smoke test of the Consent Mode feature:
    • Validate that the consent API plugin installation process continues to work as expected and that it correctly detects the plugin once installed

Changelog entry

  • Add support for detecting WooCommerce and Google for Woo plugins.
@10upsimon 10upsimon added Module: Ads Google Ads module related issues PHP Team S Issues for Squad 1 Type: Enhancement Improvement of an existing feature labels Feb 5, 2025
@10upsimon 10upsimon self-assigned this Feb 5, 2025
@10upsimon 10upsimon changed the title Add Plugin Detection Logic to Ads Module Backend Infrastructure (WC Redirect) Add Plugin Detection Logic to Ads Module Backend Infrastructure Feb 5, 2025
@10upsimon 10upsimon assigned zutigrm and unassigned 10upsimon Feb 7, 2025
@zutigrm
Copy link
Collaborator

zutigrm commented Feb 7, 2025

Thanks @10upsimon AC ✅

@zutigrm zutigrm assigned 10upsimon and unassigned zutigrm Feb 7, 2025
@eugene-manuilov
Copy link
Collaborator

@zutigrm

  • Add includes/Core/Util/External_Plugin_Status.php

Let's name this class to be Plugin_Status since there don't exist "internal" plugins.

  • Use ... as a starting point

Starting point for what?

  • Add new static method detect_plugin, which can accept 3 arguments: function_to_check, plugin_slug, and plugin_url

This method should be called get_plugin_status, accept plugin_path and plugin_url parameters, and return one of installed/not-installed/activated results.

  • and third key should be plugin which can hold the value of the plugin_file so consent mode can be refactored to use this util method as well in a follow up issue

We should add a new method get_plugin_file for this.

  • Update Google\Site_Kit\Modules\Ads::inline_modules_data method

Let's also add classes that we need to update to use the new approach of detecting whether a plugin is active (and bump estimates accordingly). It should include the consent mode mentioned briefly in IB, plus SiwG and ACR classes that check whether WooCommerce is active.

@eugene-manuilov eugene-manuilov assigned zutigrm and unassigned 10upsimon Feb 9, 2025
@zutigrm
Copy link
Collaborator

zutigrm commented Feb 10, 2025

Thanks @eugene-manuilov , IB updated

@zutigrm zutigrm assigned eugene-manuilov and unassigned zutigrm Feb 10, 2025
@eugene-manuilov
Copy link
Collaborator

Thanks. IB ✔

@eugene-manuilov eugene-manuilov removed their assignment Feb 10, 2025
@10upsimon 10upsimon self-assigned this Feb 10, 2025
@10upsimon
Copy link
Collaborator Author

Noting for reviewers and QA etc, that we had to shift direction and instead include the plugins base data in the Assets()->get_inline_base_data() method. It was missed during initial definition that the Ads module inline base data only surfaces once the module is connected, the minimum requirement being that a user at least starts Ads module setup.

This of course poses a problem for those issues depending on this issue, as we need to be aware of the plugin status regardless of ads being connected.

Changes therefore include the following:

  • The logic for adding inline data has been moved out of includes/Modules/Ads.php and into includes/Core/Assets/Assets.php
  • No updates to the ads test suite has been made, as it is no longer needed
  • Updates to unrelated tests, such as REST_Consent_Mode_ControllerTest, and WooCommerceTest were required due to the integration of the new Plugin_Status class to check the state of the WooCommerce plugin.

@10upsimon
Copy link
Collaborator Author

Also adding, cc @zutigrm , that this did not seem necessary during execution:

Add new method get_plugin_file to extract the $plugin_file - check the example here

@10upsimon 10upsimon removed their assignment Feb 12, 2025
@zutigrm zutigrm assigned zutigrm and 10upsimon and unassigned zutigrm Feb 12, 2025
@10upsimon 10upsimon assigned zutigrm and unassigned 10upsimon Feb 13, 2025
@10upsimon 10upsimon assigned 10upsimon and zutigrm and unassigned zutigrm and 10upsimon Feb 13, 2025
@zutigrm zutigrm removed their assignment Feb 13, 2025
@tofumatt tofumatt self-assigned this Feb 13, 2025
@tofumatt tofumatt added the P1 Medium priority label Feb 13, 2025
@tofumatt tofumatt assigned 10upsimon and unassigned tofumatt Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Ads Google Ads module related issues P1 Medium priority PHP Team S Issues for Squad 1 Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

4 participants