end_date = isset( $options['end_date'] ) ? $options['end_date'] : $dates['end_date']; if ( ! $start_date || ! $end_date ) { return false; } // Request params. $row_limit = isset( $options['row_limit'] ) ? $options['row_limit'] : Api::get()->get_row_limit(); $country = isset( $options['country'] ) ? $options['country'] : ''; if ( ! empty( $stored['country'] ) && 'all' !== $stored['country'] ) { $country = $stored['country']; } // Check the property for old Google Analytics. if ( Str::starts_with( 'UA-', $property_id ) ) { $args = [ 'viewId' => $view_id, 'pageSize' => $row_limit, 'dateRanges' => [ [ 'startDate' => $start_date, 'endDate' => $end_date, ], ], 'dimensionFilterClauses' => [ [ 'filters' => [ [ 'dimensionName' => 'ga:medium', 'operator' => 'EXACT', 'expressions' => 'organic', ], ], ], ], ]; // Include only dates. if ( true === $days ) { $args = wp_parse_args( [ 'dimensions' => [ [ 'name' => 'ga:date' ], ], ], $args ); } else { $args = wp_parse_args( [ 'metrics' => [ [ 'expression' => 'ga:pageviews' ], [ 'expression' => 'ga:users' ], ], 'dimensions' => [ [ 'name' => 'ga:date' ], [ 'name' => 'ga:pagePath' ], [ 'name' => 'ga:hostname' ], ], 'orderBys' => [ [ 'fieldName' => 'ga:pageviews', 'sortOrder' => 'DESCENDING', ], ], ], $args ); // Add country. if ( ! $country ) { $args['dimensionFilterClauses'][0]['filters'][] = [ 'dimensionName' => 'ga:countryIsoCode', 'operator' => 'EXACT', 'expressions' => $country, ]; } } $response = Api::get()->http_post( 'https://analyticsreporting.googleapis.com/v4/reports:batchGet', [ 'reportRequests' => [ $args ], ] ); Api::get()->log_failed_request( $response, 'analytics', $start_date, func_get_args() ); if ( ! Api::get()->is_success() ) { return new WP_Error( 'request_failed', __( 'The Google Analytics request failed.', 'rank-math' ) ); } if ( ! isset( $response['reports'], $response['reports'][0]['data']['rows'] ) ) { return false; } return $response['reports'][0]['data']['rows']; } // Request for GA4 API. $args = [ 'dateRanges' => [ [ 'startDate' => $start_date, 'endDate' => $end_date, ], ], 'dimensionFilter' => [ 'andGroup' => [ 'expressions' => [ [ 'filter' => [ 'fieldName' => 'streamId', 'stringFilter' => [ 'matchType' => 'EXACT', 'value' => $view_id, ], ], ], [ 'filter' => [ 'fieldName' => 'sessionMedium', 'stringFilter' => [ 'matchType' => 'EXACT', 'value' => 'organic', ], ], ], ], ], ], ]; // Include only dates. if ( true === $days ) { $args = wp_parse_args( [ 'dimensions' => [ [ 'name' => 'date' ], ], ], $args ); } else { $args = wp_parse_args( [ 'dimensions' => [ [ 'name' => 'hostname' ], [ 'name' => 'pagePath' ], [ 'name' => 'countryId' ], [ 'name' => 'sessionMedium' ], ], 'metrics' => [ [ 'name' => 'screenPageViews' ], [ 'name' => 'totalUsers' ], ], ], $args ); // Include country. if ( $country ) { $args['dimensionFilter']['andGroup']['expressions'][] = [ 'filter' => [ 'fieldName' => 'countryId', 'stringFilter' => [ 'matchType' => 'EXACT', 'value' => $country, ], ], ]; } } $workflow = 'analytics'; Api::get()->set_workflow( $workflow ); $response = Api::get()->http_post( 'https://analyticsdata.googleapis.com/v1beta/properties/' . $property_id . ':runReport', $args ); Api::get()->log_failed_request( $response, $workflow, $start_date, func_get_args() ); if ( ! Api::get()->is_success() ) { return new WP_Error( 'request_failed', __( 'The Google Analytics Console request failed.', 'rank-math' ) ); } if ( ! isset( $response['rows'] ) ) { return false; } return $response['rows']; } /** * Get view id. * * @return string */ public static function get_view_id() { static $rank_math_view_id; if ( is_null( $rank_math_view_id ) ) { $options = get_option( 'rank_math_google_analytic_options' ); $rank_math_view_id = ! empty( $options['view_id'] ) ? $options['view_id'] : false; } return $rank_math_view_id; } }
Fatal error: Uncaught Error: Class "RankMath\Google\Analytics" not found in /htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/google/class-console.php:23 Stack trace: #0 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/composer/ClassLoader.php(576): include() #1 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/htdocs/wp-cont...') #2 /htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/google/class-api.php(18): Composer\Autoload\ClassLoader->loadClass('RankMath\\Google...') #3 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/composer/ClassLoader.php(576): include('/htdocs/wp-cont...') #4 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/htdocs/wp-cont...') #5 /htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/workflows/class-jobs.php(57): Composer\Autoload\ClassLoader->loadClass('RankMath\\Google...') #6 /htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/workflows/class-jobs.php(45): RankMath\Analytics\Workflow\Jobs->hooks() #7 /htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/class-analytics-common.php(54): RankMath\Analytics\Workflow\Jobs::get() #8 /htdocs/wp-content/plugins/seo-by-rank-math/includes/module/class-manager.php(500): RankMath\Analytics\Analytics_Common->__construct() #9 /htdocs/wp-content/plugins/seo-by-rank-math/includes/module/class-manager.php(480): RankMath\Module\Manager->load_module_common(Object(RankMath\Module\Module)) #10 /htdocs/wp-content/plugins/seo-by-rank-math/includes/module/class-manager.php(467): RankMath\Module\Manager->load_module('analytics', Object(RankMath\Module\Module)) #11 /htdocs/wp-includes/class-wp-hook.php(324): RankMath\Module\Manager->load_modules('') #12 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #13 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #14 /htdocs/wp-settings.php(559): do_action('plugins_loaded') #15 /htdocs/wp-config.php(108): require_once('/htdocs/wp-sett...') #16 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #17 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #18 /htdocs/index.php(17): require('/htdocs/wp-blog...') #19 {main} thrown in /htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/google/class-console.php on line 23