| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | use Calotes\Component\Request; |
| 12 | 12 | use Calotes\Component\Response; |
| 13 | 13 | use WP_Defender\Model\Setting\Main_Setting; |
| 14 | 14 | use WP_Defender\Component\Product_Analytics; |
| 15 | +use WP_Defender\Traits\Array_Utils; | |
| 15 | 16 | |
| 16 | 17 | /** |
| 17 | 18 | * Abstract class for Mixpanel Events. |
| 18 | 19 | */ |
| @@ -17,8 +18,10 @@ | ||
| 17 | 18 | * Abstract class for Mixpanel Events. |
| 18 | 19 | */ |
| 19 | 20 | abstract class Event extends Controller { |
| 20 | 21 | |
| 22 | + use Array_Utils; | |
| 23 | + | |
| 21 | 24 | /** |
| 22 | 25 | * Location of the event |
| 23 | 26 | * |
| 24 | 27 | * @var string |
| @@ -50,9 +53,9 @@ | ||
| 50 | 53 | return ! defender_is_wp_cli() && $this->is_tracking_active(); |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | /** |
| 54 | - * Has the data changed? | |
| 57 | + * Has the data changed? | |
| 55 | 58 | * |
| 56 | 59 | * @param array $old_data Old data to compare. |
| 57 | 60 | * @param array $new_data New data to compare. |
| 58 | 61 | * |
| @@ -58,9 +61,10 @@ | ||
| 58 | 61 | * |
| 59 | 62 | * @return bool |
| 60 | 63 | */ |
| 61 | 64 | protected function is_feature_state_changed( $old_data, $new_data ) { |
| 62 | - return ! empty( array_diff( $old_data, $new_data ) ); | |
| 65 | + // Handle arrays with nested arrays or objects by using deep comparison. | |
| 66 | + return $this->arrays_differ_deeply( $old_data, $new_data ); | |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | 69 | /** |
| 66 | 70 | * Track data tracking opt in and opt out. |
| @@ -93,8 +97,20 @@ | ||
| 93 | 97 | } |
| 94 | 98 | } |
| 95 | 99 | |
| 96 | 100 | /** |
| 101 | + * Forced tracking. | |
| 102 | + * | |
| 103 | + * @param string $event The event to track. | |
| 104 | + * @param array $data The data associated with the event. | |
| 105 | + * | |
| 106 | + * @return void | |
| 107 | + */ | |
| 108 | + public function forced_track( $event, $data ) { | |
| 109 | + $this->tracker()->track( $event, $data ); | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 97 | 113 | * Save tracking state. |
| 98 | 114 | * |
| 99 | 115 | * @param Request $request Request object. |
| 100 | 116 | * |
| @@ -104,9 +120,9 @@ | ||
| 104 | 120 | public function track_feature_handler( Request $request ): Response { |
| 105 | 121 | // Forced tracking. |
| 106 | 122 | $data = $request->get_data(); |
| 107 | 123 | if ( isset( $data['force'] ) ) { |
| 108 | - $this->tracker()->track( $data['event'], $data['data'] ); | |
| 124 | + $this->forced_track( $data['event'], $data['data'] ); | |
| 109 | 125 | |
| 110 | 126 | return new Response( true, array() ); |
| 111 | 127 | } |
| 112 | 128 | // Otherwise it's a normal process. |