Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ use the following channels:
option is enabled under
Enhanced Measurements. For examples, read
the [documentation on Pageview Properties](https://plausible.io/docs/custom-props/for-pageviews).
- `plausible_analytics_api_timeout`: Allows you to modify the timeout for the total duration of Plausible API requests.
- `plausible_analytics_api_connect_timeout`: Allows you to modify the connection timeout for Plausible API requests.

### Actions

Expand Down
17 changes: 10 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Plausible\Analytics\WP\Client\Model\UnprocessableEntityError;

/**
* This class acts as middleware between our OpenAPI generated API client and our WP plugin, and takes care of setting
* This class acts as middleware between our OpenAPI generated API client and our WP plugin and takes care of setting
* the required configuration, so we can use the Client in a unified manner.
*/
class Client {
Expand All @@ -33,13 +33,16 @@ class Client {
/**
* Setup basic authorization, basic_auth.
*
* @param string $token Allows to specify the token, e.g. when it's not stored in the DB yet.
* @param string $token Allows specifying the token, e.g., when it's not stored in the DB yet.
*/
public function __construct( $token = '' ) {
$config = Configuration::getDefaultConfiguration()->setUsername( 'WordPress' )->setPassword(
$token
)->setHost( Helpers::get_hosted_domain_url() );
$this->api_instance = new DefaultApi( new GuzzleClient(), $config );
$config = Configuration::getDefaultConfiguration()
->setUsername( 'WordPress' )
->setPassword( $token )
->setHost( Helpers::get_hosted_domain_url() );
$timeout = (float) apply_filters( 'plausible_analytics_api_timeout', 10.0 );
$connect_timeout = (float) apply_filters( 'plausible_analytics_api_connect_timeout', 5.0 );
$this->api_instance = new DefaultApi( new GuzzleClient( [ 'timeout' => $timeout, 'connect_timeout' => $connect_timeout ] ), $config );
Comment thread
Dan0sz marked this conversation as resolved.
}

/**
Expand Down Expand Up @@ -239,7 +242,7 @@ public function update_tracker_script_configuration( $tracker_script_config_upda

/**
* @param Exception $e
* @param string $error_message The human-readable part of the error message, requires a %s at the end!
* @param string $error_message The human-readable part of the error message, requires a %s at the end!
*
* @return void
*
Expand Down
Loading