Skip to content

Commit

Permalink
Remove additional references to legacy Analytics class.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfmohit committed Mar 7, 2024
1 parent 5ac4486 commit fd5c722
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 92 deletions.
2 changes: 1 addition & 1 deletion includes/Modules/Analytics_4.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ protected function get_datapoint_definitions() {
$datapoints['GET:audiences'] = array( 'service' => 'analyticsaudiences' );
$datapoints['POST:create-audience'] = array(
'service' => 'analyticsaudiences',
'scopes' => array( Analytics::EDIT_SCOPE ),
'scopes' => array( self::EDIT_SCOPE ),
'request_scopes_message' => __( 'You’ll need to grant Site Kit permission to create new audiences for your Analytics 4 property on your behalf.', 'google-site-kit' ),
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/includes/OptionsTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Google\Site_Kit\Core\Util\Activation_Flag;
use Google\Site_Kit\Core\Util\Beta_Migration;
use Google\Site_Kit\Modules\AdSense;
use Google\Site_Kit\Modules\Analytics;
use Google\Site_Kit\Modules\Analytics_4;
use Google\Site_Kit\Modules\Search_Console;
use Google\Site_Kit\Modules\Tag_Manager;

Expand All @@ -29,7 +29,7 @@ protected function get_option_keys() {
Activation_Flag::OPTION_NEW_SITE_POSTS,
Activation_Flag::OPTION_SHOW_ACTIVATION_NOTICE,
AdSense\Settings::OPTION,
Analytics\Settings::OPTION,
Analytics_4\Settings::OPTION,
Credentials::OPTION,
Search_Console\Settings::OPTION,
Tag_Manager\Settings::OPTION,
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/integration/Core/Modules/ModulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Google\Site_Kit\Core\Storage\Options;
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Modules\AdSense;
use Google\Site_Kit\Modules\Analytics;
use Google\Site_Kit\Modules\Analytics_4;
use Google\Site_Kit\Modules\PageSpeed_Insights;
use Google\Site_Kit\Modules\Search_Console;
Expand Down
40 changes: 0 additions & 40 deletions tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Google\Site_Kit\Context;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\Storage\Options;
use Google\Site_Kit\Modules\Analytics\Settings as Analytics_Settings;
use Google\Site_Kit\Modules\Analytics_4\Settings;
use Google\Site_Kit\Tests\Modules\SettingsTestCase;

Expand Down Expand Up @@ -150,45 +149,6 @@ function( $caps, $cap ) {
$this->assertEquals( $this->user_id, $this->settings->get()['ownerID'] );
}

public function test_retrieve_missing_analytics_4_settings() {
delete_option( Settings::OPTION );

$analytics_settings = new Analytics_Settings( $this->options );
$analytics_settings->register();
$this->settings->register();

$options = new Options( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
$options->set(
Settings::OPTION,
array(
'propertyID' => '123',
'webDataStreamID' => '456',
'measurementID' => 'G-789',
'useSnippet' => true,
'ownerID' => $this->user_id,
'googleTagID' => 'GT-123',
'googleTagAccountID' => '123',
'googleTagContainerID' => '456',
'googleTagLastSyncedAtMs' => 0,
'availableCustomDimensions' => null,
'propertyCreateTime' => 0,
'adSenseLinked' => false,
'adSenseLinkedLastSyncedAt' => 0,
)
);

$keys_to_check = array(
'accountID',
'adsConversionID',
'trackingDisabled',
);
$settings = $options->get( Settings::OPTION );

foreach ( $keys_to_check as $key ) {
$this->assertArrayHasKey( $key, $settings );
}
}

public function data_owned_keys() {
$tests = array();
$keys = ( new Settings( new Options( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ) ) )->get_owned_keys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Google\Site_Kit\Core\Storage\Options;
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Modules\Analytics_4;
use Google\Site_Kit\Modules\Analytics_4\Settings as Analytics_4_Settings;
use Google\Site_Kit\Modules\Analytics\Settings as Analytics_Settings;
use Google\Site_Kit\Modules\Analytics_4\Synchronize_Property;
use Google\Site_Kit\Tests\Fake_Site_Connection_Trait;
use Google\Site_Kit\Tests\TestCase;
Expand Down
50 changes: 4 additions & 46 deletions tests/phpunit/integration/Modules/Analytics_4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use Google\Site_Kit\Core\Storage\Transients;
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Modules\AdSense\Settings as AdSense_Settings;
use Google\Site_Kit\Modules\Analytics;
use Google\Site_Kit\Modules\Analytics\Settings as Analytics_Settings;
use Google\Site_Kit\Modules\Analytics_4;
use Google\Site_Kit\Modules\Analytics_4\Custom_Dimensions_Data_Available;
use Google\Site_Kit\Modules\Analytics_4\GoogleAnalyticsAdmin\EnhancedMeasurementSettingsModel;
Expand Down Expand Up @@ -161,23 +159,6 @@ public function test_register() {
$this->assertTrue( has_action( 'web_stories_story_head' ) );
}

/**
* @dataProvider analytics_sharing_settings_data_provider
* @param array $sharing_settings
* @param array $expected
*/
public function test_register__replicate_analytics_sharing_settings( $sharing_settings, $expected ) {
remove_all_filters( 'option_' . Module_Sharing_Settings::OPTION );
$this->assertFalse( has_filter( 'option_' . Module_Sharing_Settings::OPTION ) );

$this->analytics->register();

$this->assertTrue( has_filter( 'option_' . Module_Sharing_Settings::OPTION ) );

update_option( Module_Sharing_Settings::OPTION, $sharing_settings );
$this->assertEquals( $expected, get_option( Module_Sharing_Settings::OPTION ) );
}

public function test_register__reset_adsense_link_settings() {
$this->analytics->get_settings()->merge(
array(
Expand Down Expand Up @@ -444,7 +425,7 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen

$method = new ReflectionMethod( Analytics_4::class, 'provision_property_webdatastream' );
$method->setAccessible( true );
$method->invoke( $this->analytics, $account_id, new Analytics\Account_Ticket() );
$method->invoke( $this->analytics, $account_id, new Analytics_4\Account_Ticket() );

$this->assertEqualSetsWithIndex(
array(
Expand Down Expand Up @@ -589,7 +570,7 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen

$method = new ReflectionMethod( Analytics_4::class, 'provision_property_webdatastream' );
$method->setAccessible( true );
$method->invoke( $this->analytics, $account_id, new Analytics\Account_Ticket() );
$method->invoke( $this->analytics, $account_id, new Analytics_4\Account_Ticket() );

$this->assertArrayIntersection(
array(
Expand Down Expand Up @@ -707,7 +688,7 @@ function ( Request $request ) use ( $property_id, $webdatastream_id, $measuremen
$options->get( Settings::OPTION )
);

$account_ticket = new Analytics\Account_Ticket();
$account_ticket = new Analytics_4\Account_Ticket();
$account_ticket->set_enhanced_measurement_stream_enabled( true );

$method = new ReflectionMethod( Analytics_4::class, 'provision_property_webdatastream' );
Expand Down Expand Up @@ -1153,26 +1134,6 @@ public function test_get_debug_fields__AdSense_enabled() {
);
}

public function test_get_debug_fields__keyMetrics_disabled() {
$analytics = new Analytics( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );

$this->assertNotContains(
'analytics_4_available_custom_dimensions',
array_keys( $analytics->get_debug_fields() )
);
}

public function test_get_debug_fields__keyMetrics_enabled() {
// Given: Analytics 4 is registered with a specific propertyID.
$this->analytics->register();
$this->analytics->get_settings()->register();

$this->assertContains(
'analytics_4_available_custom_dimensions',
array_keys( $this->analytics->get_debug_fields() )
);
}

/**
* @dataProvider data_google_tag_ids
*
Expand Down Expand Up @@ -2801,16 +2762,13 @@ protected function enable_shared_credentials() {
wp_set_current_user( $admin->ID );

// Ensure the Analytics 4 module is connected and the owner ID is set.
delete_option( Analytics_Settings::OPTION );
delete_option( Settings::OPTION );

$analytics_settings = new Analytics_Settings( $this->options );
$analytics_settings->register();

$analytics_4_settings = new Settings( $this->options );
$analytics_4_settings->register();
$analytics_4_settings->merge(
array(
'accountID' => '100',
'propertyID' => '123',
'webDataStreamID' => '456',
'measurementID' => 'G-789',
Expand Down

0 comments on commit fd5c722

Please sign in to comment.