Version Description
10.08.2022
- Tweak: Performance improvements for the new diagnostics report.
Download this release
Release Info
Developer | alekv |
Plugin | Pixel Manager for WooCommerce – Track Google Analytics, Google Ads, Facebook and more |
Version | 1.19.1 |
Comparing to | |
See all releases |
Code changes from version 1.19.0 to 1.19.1
- classes/admin/class-debug-info.php +139 -14
- readme.txt +5 -1
- wgact.php +13 -2
classes/admin/class-debug-info.php
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
namespace WCPM\Classes\Admin;
|
4 |
|
5 |
use WC_Order_Query;
|
|
|
6 |
|
7 |
if (!defined('ABSPATH')) {
|
8 |
exit; // Exit if accessed directly
|
@@ -170,6 +171,23 @@ class Debug_Info {
|
|
170 |
return $html;
|
171 |
}
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
public function get_gateway_analysis() {
|
174 |
|
175 |
$per_gateway_analysis = $this->get_gateway_analysis_array();
|
@@ -213,9 +231,8 @@ class Debug_Info {
|
|
213 |
|
214 |
public function get_gateway_analysis_weighted() {
|
215 |
|
216 |
-
$count_active_gateways = count(
|
217 |
-
|
218 |
-
$per_gateway_analysis = $this->get_gateway_analysis_weighted_array($count_active_gateways * 100);
|
219 |
|
220 |
$html = '';
|
221 |
|
@@ -252,32 +269,40 @@ class Debug_Info {
|
|
252 |
return $html;
|
253 |
}
|
254 |
|
255 |
-
public function get_gateway_analysis_array() {
|
256 |
|
257 |
-
|
258 |
-
|
|
|
259 |
|
260 |
$analysis = [];
|
261 |
|
262 |
foreach ($this->get_pmw_tracked_payment_methods() as $gateway) {
|
263 |
|
264 |
$gateway_orders = $this->get_last_orders_by_gateway_id($gateway, 100);
|
|
|
|
|
265 |
|
266 |
$analysis[] = [
|
267 |
'gateway_id' => $gateway,
|
268 |
'order_count_total' => count($gateway_orders),
|
269 |
'order_count_measured' => $this->get_count_of_measured_orders($gateway_orders),
|
270 |
-
'percentage' => $this->get_percentage($this->get_count_of_measured_orders($gateway_orders), count($gateway_orders)),
|
271 |
];
|
272 |
}
|
273 |
|
|
|
|
|
274 |
return $analysis;
|
275 |
}
|
276 |
|
277 |
-
public function get_gateway_analysis_weighted_array( $limit ) {
|
|
|
|
|
|
|
|
|
278 |
|
279 |
$analysis = [];
|
280 |
-
$orders = $this->get_pmw_tracked_orders($limit);
|
281 |
$enabled_gateways = $this->get_enabled_payment_gateways();
|
282 |
|
283 |
// Prep array with all gateway IDs
|
@@ -286,6 +311,15 @@ class Debug_Info {
|
|
286 |
}, $enabled_gateways);
|
287 |
|
288 |
// Prep analysis array with all gateways
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
foreach ($gateway_ids as $gateway_id) {
|
290 |
$analysis[$gateway_id] = [
|
291 |
'gateway_id' => $gateway_id,
|
@@ -295,6 +329,8 @@ class Debug_Info {
|
|
295 |
];
|
296 |
}
|
297 |
|
|
|
|
|
298 |
// Analyse all orders
|
299 |
foreach ($orders as $order) {
|
300 |
|
@@ -310,7 +346,7 @@ class Debug_Info {
|
|
310 |
|
311 |
// Calculate percentage for each gateway
|
312 |
foreach ($analysis as $gateway_id => $gateway_analysis) {
|
313 |
-
$analysis[$gateway_id]['percentage'] = $this->get_percentage($gateway_analysis['order_count_measured'], $gateway_analysis['order_count_total']);
|
314 |
}
|
315 |
|
316 |
// Sort analysis by order_count_total descending
|
@@ -318,6 +354,8 @@ class Debug_Info {
|
|
318 |
return $b['order_count_total'] - $a['order_count_total'];
|
319 |
});
|
320 |
|
|
|
|
|
321 |
return $analysis;
|
322 |
}
|
323 |
|
@@ -435,8 +473,9 @@ class Debug_Info {
|
|
435 |
private function get_last_orders_by_gateway_id( $gateway_id, $limit ) {
|
436 |
// Get most recent order IDs in date descending order, filtered by gateway_id.
|
437 |
|
438 |
-
|
439 |
|
|
|
440 |
return wc_get_orders([
|
441 |
'payment_method' => $gateway_id,
|
442 |
'limit' => $limit,
|
@@ -445,10 +484,51 @@ class Debug_Info {
|
|
445 |
'order' => 'DESC',
|
446 |
'status' => ['completed', 'processing', 'on-hold', 'pending'],
|
447 |
'meta_key' => '_wpm_process_through_wpm',
|
448 |
-
'meta_value' => true,
|
449 |
'meta_compare' => '=',
|
|
|
450 |
'return' => 'ids',
|
451 |
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
}
|
453 |
|
454 |
private function get_pmw_tracked_orders( $limit ) {
|
@@ -469,13 +549,58 @@ class Debug_Info {
|
|
469 |
]);
|
470 |
}
|
471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
// Get paymeent methods that have been used on all orders directly from database
|
473 |
-
private function get_pmw_tracked_payment_methods() {
|
474 |
global $wpdb;
|
475 |
|
476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
"SELECT DISTINCT meta_value FROM {$wpdb->prefix}postmeta WHERE `meta_key` = '_payment_method' AND meta_value != ''"
|
478 |
);
|
|
|
|
|
|
|
|
|
479 |
}
|
480 |
}
|
481 |
|
3 |
namespace WCPM\Classes\Admin;
|
4 |
|
5 |
use WC_Order_Query;
|
6 |
+
use WP_Query;
|
7 |
|
8 |
if (!defined('ABSPATH')) {
|
9 |
exit; // Exit if accessed directly
|
171 |
return $html;
|
172 |
}
|
173 |
|
174 |
+
public function run_tracking_accuracy_analysis() {
|
175 |
+
|
176 |
+
// Start measuring time
|
177 |
+
// $start_time = microtime(true);
|
178 |
+
|
179 |
+
$this->get_pmw_tracked_payment_methods(true);
|
180 |
+
|
181 |
+
$this->get_gateway_analysis_array(true);
|
182 |
+
|
183 |
+
$count_active_gateways = count($this->get_enabled_payment_gateways());
|
184 |
+
$this->get_gateway_analysis_weighted_array($count_active_gateways * 100, true);
|
185 |
+
|
186 |
+
// End measuring time
|
187 |
+
// $end_time = microtime(true);
|
188 |
+
// error_log('Time elapsed: ' . ( $end_time - $start_time ));
|
189 |
+
}
|
190 |
+
|
191 |
public function get_gateway_analysis() {
|
192 |
|
193 |
$per_gateway_analysis = $this->get_gateway_analysis_array();
|
231 |
|
232 |
public function get_gateway_analysis_weighted() {
|
233 |
|
234 |
+
$count_active_gateways = count($this->get_enabled_payment_gateways());
|
235 |
+
$per_gateway_analysis = $this->get_gateway_analysis_weighted_array($count_active_gateways * 100);
|
|
|
236 |
|
237 |
$html = '';
|
238 |
|
269 |
return $html;
|
270 |
}
|
271 |
|
272 |
+
public function get_gateway_analysis_array( $refresh = false ) {
|
273 |
|
274 |
+
if (false === $refresh && get_transient('pmw_tracking_accuracy_analysis')) {
|
275 |
+
return get_transient('pmw_tracking_accuracy_analysis');
|
276 |
+
}
|
277 |
|
278 |
$analysis = [];
|
279 |
|
280 |
foreach ($this->get_pmw_tracked_payment_methods() as $gateway) {
|
281 |
|
282 |
$gateway_orders = $this->get_last_orders_by_gateway_id($gateway, 100);
|
283 |
+
// $gateway_orders = $this->get_last_orders_by_gateway_id_wp_query_new($gateway, 100);
|
284 |
+
// $gateway_orders = $this->get_last_orders_by_gateway_id_wp_query($gateway, 100);
|
285 |
|
286 |
$analysis[] = [
|
287 |
'gateway_id' => $gateway,
|
288 |
'order_count_total' => count($gateway_orders),
|
289 |
'order_count_measured' => $this->get_count_of_measured_orders($gateway_orders),
|
290 |
+
'percentage' => floor($this->get_percentage($this->get_count_of_measured_orders($gateway_orders), count($gateway_orders))),
|
291 |
];
|
292 |
}
|
293 |
|
294 |
+
set_transient('pmw_tracking_accuracy_analysis', $analysis, 60 * 60 * 24 * 2);
|
295 |
+
|
296 |
return $analysis;
|
297 |
}
|
298 |
|
299 |
+
public function get_gateway_analysis_weighted_array( $limit, $refresh = false ) {
|
300 |
+
|
301 |
+
if (false === $refresh && get_transient('pmw_tracking_accuracy_analysis_weighted')) {
|
302 |
+
return get_transient('pmw_tracking_accuracy_analysis_weighted');
|
303 |
+
}
|
304 |
|
305 |
$analysis = [];
|
|
|
306 |
$enabled_gateways = $this->get_enabled_payment_gateways();
|
307 |
|
308 |
// Prep array with all gateway IDs
|
311 |
}, $enabled_gateways);
|
312 |
|
313 |
// Prep analysis array with all gateways
|
314 |
+
// foreach ($gateway_ids as $gateway_id) {
|
315 |
+
// $analysis[$gateway_id] = [
|
316 |
+
// 'gateway_id' => $gateway_id,
|
317 |
+
// 'order_count_total' => count($this->get_last_orders_by_gateway_id($gateway_id, $limit)),
|
318 |
+
// 'order_count_measured' => count($this->get_last_orders_by_gateway_id_pmw_measured_wp_query($gateway_id, $limit)),
|
319 |
+
// 'percentage' => 0,
|
320 |
+
// ];
|
321 |
+
// }
|
322 |
+
|
323 |
foreach ($gateway_ids as $gateway_id) {
|
324 |
$analysis[$gateway_id] = [
|
325 |
'gateway_id' => $gateway_id,
|
329 |
];
|
330 |
}
|
331 |
|
332 |
+
$orders = $this->get_pmw_tracked_orders($limit);
|
333 |
+
|
334 |
// Analyse all orders
|
335 |
foreach ($orders as $order) {
|
336 |
|
346 |
|
347 |
// Calculate percentage for each gateway
|
348 |
foreach ($analysis as $gateway_id => $gateway_analysis) {
|
349 |
+
$analysis[$gateway_id]['percentage'] = floor($this->get_percentage($gateway_analysis['order_count_measured'], $gateway_analysis['order_count_total']));
|
350 |
}
|
351 |
|
352 |
// Sort analysis by order_count_total descending
|
354 |
return $b['order_count_total'] - $a['order_count_total'];
|
355 |
});
|
356 |
|
357 |
+
set_transient('pmw_tracking_accuracy_analysis_weighted', $analysis, 60 * 60 * 24 * 2);
|
358 |
+
|
359 |
return $analysis;
|
360 |
}
|
361 |
|
473 |
private function get_last_orders_by_gateway_id( $gateway_id, $limit ) {
|
474 |
// Get most recent order IDs in date descending order, filtered by gateway_id.
|
475 |
|
476 |
+
// error_log('get_last_orders_by_gateway_id');
|
477 |
|
478 |
+
// TODO include custom order statutes that have been added with a pmw filter
|
479 |
return wc_get_orders([
|
480 |
'payment_method' => $gateway_id,
|
481 |
'limit' => $limit,
|
484 |
'order' => 'DESC',
|
485 |
'status' => ['completed', 'processing', 'on-hold', 'pending'],
|
486 |
'meta_key' => '_wpm_process_through_wpm',
|
|
|
487 |
'meta_compare' => '=',
|
488 |
+
'meta_value' => true,
|
489 |
'return' => 'ids',
|
490 |
]);
|
491 |
+
|
492 |
+
|
493 |
+
}
|
494 |
+
|
495 |
+
|
496 |
+
private function get_last_orders_by_gateway_id_pmw_measured_wp_query( $gateway_id, $limit ) {
|
497 |
+
// Get most recent order IDs in date descending order, filtered by gateway_id.
|
498 |
+
|
499 |
+
// TODO include custom order statutes that have been added with a pmw filter
|
500 |
+
|
501 |
+
$query = new WP_Query([
|
502 |
+
'fields' => 'ids',
|
503 |
+
'post_type' => 'shop_order',
|
504 |
+
'posts_per_page' => $limit,
|
505 |
+
'post_status' => ['wc-completed', 'wc-processing', 'wc-on-hold', 'wc-pending'],
|
506 |
+
'orderby' => 'ID',
|
507 |
+
'order' => 'DESC',
|
508 |
+
'meta_query' => [
|
509 |
+
[
|
510 |
+
'relation' => 'AND',
|
511 |
+
[
|
512 |
+
'key' => '_payment_method',
|
513 |
+
'compare' => '=',
|
514 |
+
'value' => $gateway_id,
|
515 |
+
],
|
516 |
+
[
|
517 |
+
'key' => '_wpm_process_through_wpm',
|
518 |
+
'compare' => '=',
|
519 |
+
'value' => true
|
520 |
+
],
|
521 |
+
[
|
522 |
+
'key' => '_wpm_conversion_pixel_fired',
|
523 |
+
'compare' => '=',
|
524 |
+
'value' => true
|
525 |
+
]
|
526 |
+
]
|
527 |
+
|
528 |
+
]
|
529 |
+
]);
|
530 |
+
|
531 |
+
return $query->get_posts();
|
532 |
}
|
533 |
|
534 |
private function get_pmw_tracked_orders( $limit ) {
|
549 |
]);
|
550 |
}
|
551 |
|
552 |
+
private function get_pmw_tracked_order_wp_query( $limit ) {
|
553 |
+
|
554 |
+
$query = new WP_Query([
|
555 |
+
'fields' => 'ids',
|
556 |
+
'post_type' => 'shop_order',
|
557 |
+
'posts_per_page' => $limit,
|
558 |
+
'post_status' => ['wc-completed', 'wc-processing', 'wc-on-hold', 'wc-pending'],
|
559 |
+
'orderby' => 'ID',
|
560 |
+
'order' => 'DESC',
|
561 |
+
'meta_query' => [
|
562 |
+
[
|
563 |
+
'relation' => 'AND',
|
564 |
+
[
|
565 |
+
'key' => '_payment_method',
|
566 |
+
'compare' => '=',
|
567 |
+
'value' => $gateway_id,
|
568 |
+
],
|
569 |
+
[
|
570 |
+
'key' => '_wpm_process_through_wpm',
|
571 |
+
'compare' => '=',
|
572 |
+
'value' => true
|
573 |
+
],
|
574 |
+
// [
|
575 |
+
// 'key' => 'order_printed',
|
576 |
+
// 'compare' => '=',
|
577 |
+
// 'value' => 0
|
578 |
+
// ]
|
579 |
+
]
|
580 |
+
|
581 |
+
]
|
582 |
+
]);
|
583 |
+
|
584 |
+
return $query->get_posts();
|
585 |
+
}
|
586 |
+
|
587 |
// Get paymeent methods that have been used on all orders directly from database
|
588 |
+
private function get_pmw_tracked_payment_methods( $refresh = false ) {
|
589 |
global $wpdb;
|
590 |
|
591 |
+
if (get_transient('pmw_tracked_payment_methods') && !$refresh) {
|
592 |
+
|
593 |
+
error_log('get transient pmw_tracked_payment_methods');
|
594 |
+
return get_transient('pmw_tracked_payment_methods');
|
595 |
+
}
|
596 |
+
|
597 |
+
$tracked_payment_methods = $wpdb->get_col(
|
598 |
"SELECT DISTINCT meta_value FROM {$wpdb->prefix}postmeta WHERE `meta_key` = '_payment_method' AND meta_value != ''"
|
599 |
);
|
600 |
+
|
601 |
+
set_transient('pmw_tracked_payment_methods', $tracked_payment_methods, DAY_IN_SECONDS * 2);
|
602 |
+
|
603 |
+
return $tracked_payment_methods;
|
604 |
}
|
605 |
}
|
606 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: woocommerce, google ads, google analytics, facebook pixel, conversion trac
|
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 6.0
|
6 |
Requires PHP: 7.3
|
7 |
-
Stable tag: 1.19.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -198,6 +198,10 @@ You can send the link to the front page of your shop too if you think it would b
|
|
198 |
|
199 |
== Changelog ==
|
200 |
|
|
|
|
|
|
|
|
|
201 |
= 1.19.0 = 10.08.2022
|
202 |
|
203 |
* New: Introduced new diagnostics section in the settings page.
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 6.0
|
6 |
Requires PHP: 7.3
|
7 |
+
Stable tag: 1.19.1
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
198 |
|
199 |
== Changelog ==
|
200 |
|
201 |
+
= 1.19.1 = 10.08.2022
|
202 |
+
|
203 |
+
* Tweak: Performance improvements for the new diagnostics report.
|
204 |
+
|
205 |
= 1.19.0 = 10.08.2022
|
206 |
|
207 |
* New: Introduced new diagnostics section in the settings page.
|
wgact.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* Developer URI: https://sweetcode.com
|
11 |
* Text Domain: woocommerce-google-adwords-conversion-tracking-tag
|
12 |
* Domain path: /languages
|
13 |
-
* * Version: 1.19.
|
14 |
*
|
15 |
* WC requires at least: 3.7
|
16 |
* WC tested up to: 6.8
|
@@ -19,7 +19,7 @@
|
|
19 |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
20 |
*
|
21 |
**/
|
22 |
-
const WPM_CURRENT_VERSION = '1.19.
|
23 |
// TODO export settings function
|
24 |
// TODO add option checkbox on uninstall and ask if user wants to delete options from db
|
25 |
|
@@ -29,6 +29,7 @@ if ( !defined( 'ABSPATH' ) ) {
|
|
29 |
}
|
30 |
|
31 |
use WCPM\Classes\Admin\Admin ;
|
|
|
32 |
use WCPM\Classes\Admin\Environment_Check ;
|
33 |
use WCPM\Classes\Db_Upgrade ;
|
34 |
use WCPM\Classes\Default_Options ;
|
@@ -155,6 +156,10 @@ if ( function_exists( 'wpm_fs' ) ) {
|
|
155 |
$this->environment_check->flush_cache_on_plugin_changes();
|
156 |
register_activation_hook( __FILE__, [ $this, 'plugin_activated' ] );
|
157 |
register_deactivation_hook( __FILE__, [ $this, 'plugin_deactivated' ] );
|
|
|
|
|
|
|
|
|
158 |
|
159 |
if ( $this->is_woocommerce_active() ) {
|
160 |
add_action( 'woocommerce_init', [ $this, 'init' ] );
|
@@ -270,8 +275,14 @@ if ( function_exists( 'wpm_fs' ) ) {
|
|
270 |
// startup all functions
|
271 |
public function init()
|
272 |
{
|
|
|
|
|
|
|
273 |
|
274 |
if ( is_admin() ) {
|
|
|
|
|
|
|
275 |
// display admin views
|
276 |
new Admin( $this->options );
|
277 |
// ask visitor for rating
|
10 |
* Developer URI: https://sweetcode.com
|
11 |
* Text Domain: woocommerce-google-adwords-conversion-tracking-tag
|
12 |
* Domain path: /languages
|
13 |
+
* * Version: 1.19.1
|
14 |
*
|
15 |
* WC requires at least: 3.7
|
16 |
* WC tested up to: 6.8
|
19 |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
20 |
*
|
21 |
**/
|
22 |
+
const WPM_CURRENT_VERSION = '1.19.1' ;
|
23 |
// TODO export settings function
|
24 |
// TODO add option checkbox on uninstall and ask if user wants to delete options from db
|
25 |
|
29 |
}
|
30 |
|
31 |
use WCPM\Classes\Admin\Admin ;
|
32 |
+
use WCPM\Classes\Admin\Debug_Info ;
|
33 |
use WCPM\Classes\Admin\Environment_Check ;
|
34 |
use WCPM\Classes\Db_Upgrade ;
|
35 |
use WCPM\Classes\Default_Options ;
|
156 |
$this->environment_check->flush_cache_on_plugin_changes();
|
157 |
register_activation_hook( __FILE__, [ $this, 'plugin_activated' ] );
|
158 |
register_deactivation_hook( __FILE__, [ $this, 'plugin_deactivated' ] );
|
159 |
+
register_deactivation_hook( __FILE__, function () {
|
160 |
+
$timestamp = wp_next_scheduled( 'pmw_tracking_accuracy_analysis' );
|
161 |
+
wp_unschedule_event( $timestamp, 'pmw_tracking_accuracy_analysis' );
|
162 |
+
} );
|
163 |
|
164 |
if ( $this->is_woocommerce_active() ) {
|
165 |
add_action( 'woocommerce_init', [ $this, 'init' ] );
|
275 |
// startup all functions
|
276 |
public function init()
|
277 |
{
|
278 |
+
add_action( 'pmw_tracking_accuracy_analysis', function () {
|
279 |
+
( new Debug_Info( $this->options ) )->run_tracking_accuracy_analysis();
|
280 |
+
} );
|
281 |
|
282 |
if ( is_admin() ) {
|
283 |
+
if ( !wp_next_scheduled( 'pmw_tracking_accuracy_analysis' ) ) {
|
284 |
+
wp_schedule_event( strtotime( '03:25:00' ), 'daily', 'pmw_tracking_accuracy_analysis' );
|
285 |
+
}
|
286 |
// display admin views
|
287 |
new Admin( $this->options );
|
288 |
// ask visitor for rating
|