Skip to content

Commit ea1d0f6

Browse files
write detailed error to log again
1 parent 074ae43 commit ea1d0f6

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 1.8.1 - Jun 13, 2025
4+
5+
- Fix issue with optimized endpoint not working introduced in version 1.8.0
6+
7+
38
### 1.8.0 - Jun 12, 2025
49

510
- Added a new tracking method: [cookieless tracking](https://www.kokoanalytics.com/kb/cookie-vs-cookieless-tracking-methods).

src/class-endpoint-installer.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace KokoAnalytics;
1010

11+
use WP_Error;
12+
1113
class Endpoint_Installer
1214
{
1315
public static function get_file_name(): string
@@ -106,14 +108,14 @@ public static function test()
106108
// Check if endpoint returns correct HTTP response
107109
$works = self::verify();
108110

109-
update_option('koko_analytics_use_custom_endpoint', $exists && $works, true);
111+
update_option('koko_analytics_use_custom_endpoint', $exists && !is_wp_error($works), true);
110112

111113
if (! $exists) {
112-
return __('Error creating file', 'koko-analytics');
114+
return __('Error creating file.', 'koko-analytics');
113115
}
114116

115-
if (! $works) {
116-
return __('Error verifying HTTP response', 'koko-analytics');
117+
if (is_wp_error($works)) {
118+
return __('Error verifying HTTP response.', 'koko-analytics') . ' ' . join(', ', $works->get_error_messages());
117119
}
118120

119121
return true;
@@ -122,23 +124,26 @@ public static function test()
122124
/**
123125
* Performs an HTTP request to the optimized endpoint to verify that it works
124126
*/
125-
private static function verify(): bool
127+
private static function verify()
126128
{
127-
$tracker_url = site_url('/koko-analytics-collect.php?p=0&m=n&test=1');
129+
$tracker_url = site_url('/koko-analytics-collect.php?test=1');
128130
$response = wp_remote_post($tracker_url, [
129131
'body' => [
130132
'p' => 0,
131133
'test' => 1,
132-
]
134+
],
135+
'timeout' => 10,
136+
'sslverify' => false,
133137
]);
134138
if (is_wp_error($response)) {
135-
return false;
139+
return $response;
136140
}
137141

138142
$status = wp_remote_retrieve_response_code($response);
139143
$headers = wp_remote_retrieve_headers($response);
140-
if ($status !== 200 || ! isset($headers['Content-Type']) || ! str_contains($headers['Content-Type'], 'text/plain')) {
141-
return false;
144+
if ($status != 200 || ! isset($headers['Content-Type']) || ! str_contains($headers['Content-Type'], 'text/plain')) {
145+
error_log(sprintf("Koko Analaytics: Error verifying optimized endpoint because it did not return the expected HTTP response.\nHTTP code: %s\nHTTP headers: %s\nHTTP body: %s", $status, var_export($headers, true), wp_remote_retrieve_body($response)));
146+
return new WP_Error('response_mismatch', __('Unexpected response headers.', 'koko-analytics'));
142147
}
143148

144149
return true;

0 commit comments

Comments
 (0)