
MonsterInsights Error: The firewall of your server is blocking outbound calls. Please contact your hosting provider to fix this issue. cURL error 28: Failed to connect to www.google.com port 443 after 1201 ms: Couldn’t connect to server

This error is caused by cURL (Client for URLs) – a command line tool that is used to transfer data to and from a server. To fix the error first check if curl is available in your php.info file:
Check if curl is enabled
Create a new file info.php in your website folder with the following content:
<?php
phpinfo();
?>
Save the file and open it in your browser: example.com/info.php
Then search for “curl” and if you see the section then curl is enabled and working:

Another way to test if curl is enabled is directly from the terminal:
curl -V
You should see the version if curl is enabled:

After we have confirmed that curl is enabled, lets test outgoing connections in the same way as the MonsterInsights plugin does.
Test curl from terminal
curl -v https://www.google.com
If curl is working, you should see a bunch of text like this:

But if it is not, and for example you receive any of these errors:
| Error Code | Description |
|---|---|
| 6 | Could not resolve host |
| 7 | Failed to connect to host |
| 28 | Operation timed out |
| 35 | SSL connect error |
| 47 | Maximum redirects reached |
| 60 | SSL certificate problem |
| 77 | Error reading ca cert file |
| 78 | Error writing to socket |
| 52 | Empty reply from server |
| 51 | SSL peer certificate status does not match |
Then contact your hosting provider immediately so that they can check for ongoing DDoS attacks or network problems.
Edit MonsterInsights code to bypass the check
If curl is working, then the check in plugin code is failing and you can bypass it by editing the file wp-content/plugins/google-analytics-for-wordpress/includes/api-request.php and in it comment our the code for the check:

Replace:
public function request( $extra_params = [] ) {
// Make sure we're not blocked
$blocked = $this->is_blocked( $this->url );
if ( $blocked || is_wp_error( $blocked ) ) {
if ( is_wp_error( $blocked ) ) {
// Translators: Placeholder gets replaced with the error message.
return new WP_Error( 'api-error', sprintf( __( 'The firewall of your server is blocking outbound calls. Please contact your hosting provider to fix this issue. %s', 'google-analytics-for-wordpress' ), $blocked->get_error_message() ) );
} else {
return new WP_Error( 'api-error', __( 'The firewall of your server is blocking outbound calls. Please contact your hosting provider to fix this issue.', 'google-analytics-for-wordpress' ) );
}
}
with:
public function request( $extra_params = [] ) {
// Make sure we're not blocked
/* $blocked = $this->is_blocked( $this->url );
if ( $blocked || is_wp_error( $blocked ) ) {
if ( is_wp_error( $blocked ) ) {
// Translators: Placeholder gets replaced with the error message.
return new WP_Error( 'api-error', sprintf( __( 'The firewall of your server is blocking outbound calls. Please contact your hosting provider to fix this issue. %s', 'google-analytics-for-wordpress' ), $blocked->get_error_message() ) );
} else {
return new WP_Error( 'api-error', __( 'The firewall of your server is blocking outbound calls. Please contact your hosting provider to fix this issue.', 'google-analytics-for-wordpress' ) );
}
}
*/
Just add /* bfore the code and */ after it to comment it out.
Then save the file and navigate back to the plugins page where you will see a prompt to reconnect your GoogleAnalytics account. After you do so, the plugin should work:


