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 First-Party Mode site health and value helpers. #9794

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion includes/Core/Tags/First_Party_Mode/First_Party_Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Google\Site_Kit\Core\Tags\First_Party_Mode;

use Google\Site_Kit\Context;
use Google\Site_Kit\Core\Modules\Module_With_Debug_Fields;
use Google\Site_Kit\Core\Storage\Options;
use Google\Site_Kit\Core\Util\Method_Proxy_Trait;

Expand All @@ -21,7 +22,7 @@
* @access private
* @ignore
*/
class First_Party_Mode {
class First_Party_Mode implements Module_With_Debug_Fields {
use Method_Proxy_Trait;

/**
Expand Down Expand Up @@ -72,4 +73,23 @@ public function register() {
$this->first_party_mode_settings->register();
$this->rest_controller->register();
}

/**
* Gets an array of debug field definitions.
*
* @since n.e.x.t
*
* @return array
*/
public function get_debug_fields() {
$settings = $this->first_party_mode_settings->get();

return array(
'first_party_mode_is_enabled' => array(
'label' => __( 'First-Party Mode: Enabled', 'google-site-kit' ),
'value' => $settings['isEnabled'] ? __( 'Yes', 'google-site-kit' ) : __( 'No', 'google-site-kit' ),
'debug' => $settings['isEnabled'] ? 'yes' : 'no',
),
);
}
}
14 changes: 13 additions & 1 deletion includes/Modules/Ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Google\Site_Kit\Core\Modules\Tags\Module_Tag_Matchers;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\Site_Health\Debug_Data;
use Google\Site_Kit\Core\Tags\First_Party_Mode\First_Party_Mode;
use Google\Site_Kit\Modules\Ads\PAX_Config;
use Google\Site_Kit\Modules\Ads\Settings;
use Google\Site_Kit\Modules\Ads\Has_Tag_Guard;
Expand Down Expand Up @@ -307,13 +308,24 @@ public function register_tag() {
public function get_debug_fields() {
$settings = $this->get_settings()->get();

return array(
$debug_fields = array(
'ads_conversion_tracking_id' => array(
'label' => __( 'Ads: Conversion Tracking ID', 'google-site-kit' ),
'value' => $settings['conversionID'],
'debug' => Debug_Data::redact_debug_value( $settings['conversionID'] ),
),
);

// Add fields from First-Party Mode.
// Note: fields are added in both Analytics and Ads so that the debug fields will show if either module is enabled.
if ( Feature_Flags::enabled( 'firstPartyMode' ) ) {
$first_party_mode = new First_Party_Mode( $this->context );
$fields_from_first_party_mode = $first_party_mode->get_debug_fields();

$debug_fields = array_merge( $debug_fields, $fields_from_first_party_mode );
}

return $debug_fields;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions includes/Modules/Analytics_4.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
use Google\Site_Kit_Dependencies\Google_Service_TagManager_Container;
use Google\Site_Kit_Dependencies\Psr\Http\Message\RequestInterface;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use Google\Site_Kit\Core\Tags\First_Party_Mode\First_Party_Mode;
use Google\Site_Kit\Modules\Analytics_4\Conversion_Reporting\Conversion_Reporting_Cron;
use Google\Site_Kit\Modules\Analytics_4\Conversion_Reporting\Conversion_Reporting_Events_Sync;
use Google\Site_Kit\Modules\Analytics_4\Conversion_Reporting\Conversion_Reporting_Provider;
Expand Down Expand Up @@ -593,6 +594,15 @@ public function get_debug_fields() {
);
}

// Add fields from First-Party Mode.
// Note: fields are added in both Analytics and Ads so that the debug fields will show if either module is enabled.
if ( Feature_Flags::enabled( 'firstPartyMode' ) ) {
$first_party_mode = new First_Party_Mode( $this->context );
$fields_from_first_party_mode = $first_party_mode->get_debug_fields();

$debug_fields = array_merge( $debug_fields, $fields_from_first_party_mode );
}

return $debug_fields;
}

Expand Down
Loading