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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / tracks / events / class-wc-settings-tracking.php
woocommerce / includes / tracks / events Last commit date
class-wc-admin-setup-wizard-tracking.php 5 years ago class-wc-coupon-tracking.php 6 years ago class-wc-coupons-tracking.php 7 months ago class-wc-extensions-tracking.php 1 year ago class-wc-importer-tracking.php 3 years ago class-wc-order-tracking.php 6 years ago class-wc-orders-tracking.php 1 year ago class-wc-product-collection-block-tracking.php 7 months ago class-wc-products-tracking.php 1 month ago class-wc-settings-tracking.php 11 months ago class-wc-status-tracking.php 7 months ago class-wc-theme-tracking.php 1 year ago
class-wc-settings-tracking.php
240 lines
1 <?php
2 /**
3 * WooCommerce Settings Tracking
4 *
5 * @package WooCommerce\Tracks
6 */
7
8 use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * This class adds actions to track usage of WooCommerce Settings.
14 */
15 class WC_Settings_Tracking {
16
17 /**
18 * List of allowed WooCommerce settings to potentially track updates for.
19 *
20 * @var array
21 */
22 protected $allowed_options = array();
23
24 /**
25 * WooCommerce settings that have been updated (and will be tracked).
26 *
27 * @var array
28 */
29 protected $updated_options = array();
30
31 /**
32 * List of option names that are dropdown menus.
33 *
34 * @var array
35 */
36 protected $dropdown_menu_options = array();
37
38
39 /**
40 * List of options that have been modified.
41 *
42 * @var array
43 */
44 protected $modified_options = array();
45
46 /**
47 * List of options that have been deleted.
48 *
49 * @var array
50 */
51 protected $deleted_options = array();
52
53 /**
54 * List of options that have been added.
55 *
56 * @var array
57 */
58 protected $added_options = array();
59
60
61 /**
62 * Toggled options.
63 *
64 * @var array
65 */
66 protected $toggled_options = array(
67 'enabled' => array(),
68 'disabled' => array(),
69 );
70
71 /**
72 * Init tracking.
73 */
74 public function init() {
75 add_action( 'woocommerce_settings_page_init', array( $this, 'track_settings_page_view' ) );
76 add_action( 'woocommerce_update_option', array( $this, 'add_option_to_list' ) );
77 add_action( 'woocommerce_update_non_option_setting', array( $this, 'add_option_to_list_and_track_setting_change' ) );
78 add_action( 'woocommerce_update_options', array( $this, 'send_settings_change_event' ) );
79 add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_settings_tracking_scripts' ) );
80 }
81
82 /**
83 * Adds the option to the allowed and updated options directly.
84 * Currently used for settings that don't use update_option.
85 *
86 * @param array $option WooCommerce option that should be updated.
87 */
88 public function add_option_to_list_and_track_setting_change( $option ) {
89 if ( ! in_array( $option['id'], $this->allowed_options, true ) ) {
90 $this->allowed_options[] = $option['id'];
91 }
92 if ( isset( $option['action'] ) ) {
93 if ( 'add' === $option['action'] ) {
94 $this->added_options[] = $option['id'];
95 } elseif ( 'delete' === $option['action'] ) {
96 $this->deleted_options[] = $option['id'];
97 } elseif ( ! in_array( $option['id'], $this->updated_options, true ) ) {
98 $this->updated_options[] = $option['id'];
99 }
100 } elseif ( isset( $option['value'] ) ) {
101 if ( 'select' === $option['type'] ) {
102 $this->modified_options[ $option['id'] ] = $option['value'];
103
104 } elseif ( 'checkbox' === $option['type'] ) {
105 $option_state = 'yes' === $option['value'] ? 'enabled' : 'disabled';
106 $this->toggled_options[ $option_state ][] = $option['id'];
107 }
108 $this->updated_options[] = $option['id'];
109 }
110
111 }
112
113 /**
114 * Add a WooCommerce option name to our allowed options list and attach
115 * the `update_option` hook. Rather than inspecting every updated
116 * option and pattern matching for "woocommerce", just build a dynamic
117 * list for WooCommerce options that might get updated.
118 *
119 * See `woocommerce_update_option` hook.
120 *
121 * @param array $option WooCommerce option (config) that might get updated.
122 */
123 public function add_option_to_list( $option ) {
124 $this->allowed_options[] = $option['id'];
125
126 if ( isset( $option['options'] ) ) {
127 $this->dropdown_menu_options[] = $option['id'];
128 }
129
130 // Delay attaching this action since it could get fired a lot.
131 if ( false === has_action( 'update_option', array( $this, 'track_setting_change' ) ) ) {
132 add_action( 'update_option', array( $this, 'track_setting_change' ), 10, 3 );
133 }
134 }
135
136 /**
137 * Add WooCommerce option to a list of updated options.
138 *
139 * @param string $option_name Option being updated.
140 * @param mixed $old_value Old value of option.
141 * @param mixed $new_value New value of option.
142 */
143 public function track_setting_change( $option_name, $old_value, $new_value ) {
144 // Make sure this is a WooCommerce option.
145 if ( ! in_array( $option_name, $this->allowed_options, true ) ) {
146 return;
147 }
148
149 // Check to make sure the new value is truly different.
150 // `woocommerce_price_num_decimals` tends to trigger this
151 // because form values aren't coerced (e.g. '2' vs. 2).
152 if (
153 is_scalar( $old_value ) &&
154 is_scalar( $new_value ) &&
155 (string) $old_value === (string) $new_value
156 ) {
157 return;
158 }
159
160 if ( in_array( $option_name, $this->dropdown_menu_options, true ) ) {
161 $this->modified_options[ $option_name ] = $new_value;
162 } elseif ( in_array( $new_value, array( 'yes', 'no' ), true ) && in_array( $old_value, array( 'yes', 'no' ), true ) ) {
163 // Save toggled options.
164 $option_state = 'yes' === $new_value ? 'enabled' : 'disabled';
165 $this->toggled_options[ $option_state ][] = $option_name;
166 }
167
168 $this->updated_options[] = $option_name;
169 }
170
171 /**
172 * Send a Tracks event for WooCommerce options that changed values.
173 */
174 public function send_settings_change_event() {
175 global $current_tab, $current_section;
176
177 if ( empty( $this->updated_options ) && empty( $this->deleted_options ) && empty( $this->added_options ) ) {
178 return;
179 }
180
181 $properties = array();
182
183 if ( ! empty( $this->updated_options ) ) {
184 $properties['settings'] = implode( ',', $this->updated_options );
185 }
186
187 if ( ! empty( $this->deleted_options ) ) {
188 $properties['deleted'] = implode( ',', $this->deleted_options );
189 }
190
191 if ( ! empty( $this->added_options ) ) {
192 $properties['added'] = implode( ',', $this->added_options );
193 }
194
195 foreach ( $this->toggled_options as $state => $options ) {
196 if ( ! empty( $options ) ) {
197 $properties[ $state ] = implode( ',', $options );
198 }
199 }
200
201 if ( ! empty( $this->modified_options ) ) {
202 foreach ( $this->modified_options as $option_name => $selected_option ) {
203 $properties[ $option_name ] = $selected_option ?? '';
204 }
205 }
206
207 $properties['tab'] = $current_tab ?? '';
208 $properties['section'] = $current_section ?? '';
209
210 WC_Tracks::record_event( 'settings_change', $properties );
211 }
212
213 /**
214 * Send a Tracks event for WooCommerce settings page views.
215 */
216 public function track_settings_page_view() {
217 global $current_tab, $current_section;
218
219 $properties = array(
220 'tab' => $current_tab,
221 'section' => empty( $current_section ) ? null : $current_section,
222 );
223
224 WC_Tracks::record_event( 'settings_view', $properties );
225 }
226
227 /**
228 * Adds the tracking scripts for product setting pages.
229 *
230 * @param string $hook Page hook.
231 */
232 public function possibly_add_settings_tracking_scripts( $hook ) {
233 if ( ! is_wc_admin_settings_page() ) {
234 return;
235 }
236
237 WCAdminAssets::register_script( 'wp-admin-scripts', 'settings-tracking', false );
238 }
239 }
240