-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22023 from Yoast/416-implement-organic-session-ba…
…ckend-endpoint-using-the-google-analytics-api 416 implement organic session backend endpoint using the google analytics api
- Loading branch information
Showing
16 changed files
with
790 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/dashboard/application/traffic/organic-sessions-repository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
namespace Yoast\WP\SEO\Dashboard\Application\Traffic; | ||
|
||
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Dashboard_Repository_Interface; | ||
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Data_Container; | ||
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Parameters; | ||
use Yoast\WP\SEO\Dashboard\Infrastructure\Analytics_4\Site_Kit_Analytics_4_Adapter; | ||
|
||
/** | ||
* The data provider for organic sessions data. | ||
*/ | ||
class Organic_Sessions_Repository implements Dashboard_Repository_Interface { | ||
|
||
/** | ||
* The adapter. | ||
* | ||
* @var Site_Kit_Analytics_4_Adapter $site_kit_analytics_4_adapter | ||
*/ | ||
private $site_kit_analytics_4_adapter; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param Site_Kit_Analytics_4_Adapter $site_kit_analytics_4_adapter The adapter. | ||
*/ | ||
public function __construct( | ||
Site_Kit_Analytics_4_Adapter $site_kit_analytics_4_adapter | ||
) { | ||
$this->site_kit_analytics_4_adapter = $site_kit_analytics_4_adapter; | ||
} | ||
|
||
/** | ||
* Gets the organic sessions' data. | ||
* | ||
* @param Parameters $parameters The parameter to use for getting the organic sessions' data. | ||
* | ||
* @return Data_Container | ||
* | ||
* @throws Exception When getting the organic sessions' data fails. | ||
*/ | ||
public function get_data( Parameters $parameters ): Data_Container { | ||
|
||
$organic_sessions_data = $this->site_kit_analytics_4_adapter->get_data( $parameters ); | ||
|
||
return $organic_sessions_data; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/dashboard/domain/analytics-4/failed-request-exception.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
namespace Yoast\WP\SEO\Dashboard\Domain\Analytics_4; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Exception for when an Analytics 4 request fails. | ||
*/ | ||
class Failed_Request_Exception extends Exception { | ||
|
||
/** | ||
* Constructor of the exception. | ||
* | ||
* @param string $error_message The error message of the request. | ||
* @param int $error_status_code The error status code of the request. | ||
*/ | ||
public function __construct( $error_message, $error_status_code ) { | ||
parent::__construct( 'The Analytics 4 request failed: ' . $error_message, $error_status_code ); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/dashboard/domain/analytics-4/invalid-request-exception.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
namespace Yoast\WP\SEO\Dashboard\Domain\Analytics_4; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Exception for when an Analytics 4 request is invalid. | ||
*/ | ||
class Invalid_Request_Exception extends Exception { | ||
|
||
/** | ||
* Constructor of the exception. | ||
* | ||
* @param string $error_message The error message of the request. | ||
*/ | ||
public function __construct( $error_message ) { | ||
parent::__construct( 'The Analytics 4 request is invalid: ' . $error_message, 400 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
namespace Yoast\WP\SEO\Dashboard\Domain\Traffic; | ||
|
||
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Data_Interface; | ||
|
||
/** | ||
* Domain object that represents a single Comparison Traffic record. | ||
*/ | ||
class Comparison_Traffic_Data implements Data_Interface { | ||
|
||
/** | ||
* The current traffic data. | ||
* | ||
* @var Traffic_Data $current_traffic_data | ||
*/ | ||
private $current_traffic_data; | ||
|
||
/** | ||
* The previous traffic data. | ||
* | ||
* @var Traffic_Data $previous_traffic_data | ||
*/ | ||
private $previous_traffic_data; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param Traffic_Data $current_traffic_data The current traffic data. | ||
* @param Traffic_Data $previous_traffic_data The previous traffic data. | ||
*/ | ||
public function __construct( ?Traffic_Data $current_traffic_data = null, ?Traffic_Data $previous_traffic_data = null ) { | ||
$this->current_traffic_data = $current_traffic_data; | ||
$this->previous_traffic_data = $previous_traffic_data; | ||
} | ||
|
||
/** | ||
* Sets the current traffic data. | ||
* | ||
* @param Traffic_Data $current_traffic_data The current traffic data. | ||
* | ||
* @return void | ||
*/ | ||
public function set_current_traffic_data( Traffic_Data $current_traffic_data ): void { | ||
$this->current_traffic_data = $current_traffic_data; | ||
} | ||
|
||
/** | ||
* Sets the previous traffic data. | ||
* | ||
* @param Traffic_Data $previous_traffic_data The previous traffic data. | ||
* | ||
* @return void | ||
*/ | ||
public function set_previous_traffic_data( Traffic_Data $previous_traffic_data ): void { | ||
$this->previous_traffic_data = $previous_traffic_data; | ||
} | ||
|
||
/** | ||
* The array representation of this domain object. | ||
* | ||
* @return array<string|float|int|string[]> | ||
*/ | ||
public function to_array(): array { | ||
return [ | ||
'current' => $this->current_traffic_data->to_array(), | ||
'previous' => $this->previous_traffic_data->to_array(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
namespace Yoast\WP\SEO\Dashboard\Domain\Traffic; | ||
|
||
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Data_Interface; | ||
|
||
/** | ||
* Domain object that represents a single Daily Traffic record. | ||
*/ | ||
class Daily_Traffic_Data implements Data_Interface { | ||
|
||
/** | ||
* The date of the traffic data, in YYYYMMDD format. | ||
* | ||
* @var string $date | ||
*/ | ||
private $date; | ||
|
||
/** | ||
* The traffic data for the date. | ||
* | ||
* @var Traffic_Data $traffic_data | ||
*/ | ||
private $traffic_data; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param string $date The date of the traffic data, in YYYYMMDD format. | ||
* @param Traffic_Data $traffic_data The traffic data for the date. | ||
*/ | ||
public function __construct( string $date, Traffic_Data $traffic_data ) { | ||
$this->date = $date; | ||
$this->traffic_data = $traffic_data; | ||
} | ||
|
||
/** | ||
* The array representation of this domain object. | ||
* | ||
* @return array<string,string,int> | ||
*/ | ||
public function to_array(): array { | ||
$result = []; | ||
$result['date'] = $this->date; | ||
|
||
return \array_merge( $result, $this->traffic_data->to_array() ); | ||
} | ||
} |
Oops, something went wrong.