From 0b086c668ef9a306ebe95bf900f5035773ecfe34 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Brito Date: Mon, 17 Nov 2025 15:11:23 +0000 Subject: [PATCH 1/5] New Yoast Events for option changes --- includes/Listeners/Yoast.php | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/includes/Listeners/Yoast.php b/includes/Listeners/Yoast.php index 097ab78e..f602cf57 100644 --- a/includes/Listeners/Yoast.php +++ b/includes/Listeners/Yoast.php @@ -35,6 +35,15 @@ public function register_hooks() { add_action( 'wpseo_ftc_post_update_site_representation', array( $this, 'site_representation_updated' ), 10, 3 ); add_action( 'wpseo_ftc_post_update_social_profiles', array( $this, 'social_profiles_updated' ), 10, 3 ); add_action( 'wpseo_ftc_post_update_enable_tracking', array( $this, 'tracking_updated' ), 10, 3 ); + + // Upgrade database + add_action( 'wpseo_run_upgrade', array( $this, 'database_upgrade' ) ); + + // Updated options + add_action( 'update_option_wpseo_titles', array( $this, 'option_updated' ), 10, 3 ); + add_action( 'update_option_wpseo_social', array( $this, 'option_updated' ), 10, 3 ); + add_action( 'update_option_wpseo', array( $this, 'option_updated' ), 10, 3 ); + add_action( 'update_option_wpseo_ms', array( $this, 'option_updated' ), 10, 3 ); } /** @@ -349,4 +358,57 @@ private function clean_social_profiles_failures( $failures ) { return $cleaned_failures; } + + /** + * Yoast SEO database upgrade. + * + * @param string|null $previous_version The previous version of Yoast SEO. + * + * @return void + */ + public function database_upgrade( $previous_version ) { + + if ( ! $previous_version ) { + $previous_version = ''; + } + + $data = array( + 'category' => 'yoast_event', + 'data' => array( + 'previous_version' => $previous_version, + 'new_version' => WPSEO_VERSION, + ), + ); + + $this->push( + 'database_upgrade', + $data + ); + } + + /** + * Yoast SEO option updated. + * + * @param mixed $old_value The old value. + * @param mixed $new_value The new value. + * @param string $option The option name. + * + * @return void + */ + public function option_updated( $old_value, $new_value, $option ) { + if ( $old_value !== $new_value ) { + + $data = array( + 'category' => 'yoast_event', + 'data' => array( + 'old_value' => $old_value, + 'new_value' => $new_value, + ), + ); + $this->push( + $option, + $data + ); + } + } } From 93b860cb5dbe091b82ca29a2a03a1046f16e7a6b Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Brito Date: Mon, 17 Nov 2025 15:21:01 +0000 Subject: [PATCH 2/5] Lint --- includes/Listeners/Yoast.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/includes/Listeners/Yoast.php b/includes/Listeners/Yoast.php index f602cf57..9ecb2a2c 100644 --- a/includes/Listeners/Yoast.php +++ b/includes/Listeners/Yoast.php @@ -6,10 +6,19 @@ * Monitors Yoast events */ class Yoast extends Listener { - // We don't want to track these fields + + /** + * Fields to skip when tracking site representation changes + * + * @var array + */ private $site_representation_skip_fields = array( 'company_logo_id', 'person_logo_id', 'description' ); - // The names used for Hiive events tracking are different from the names used for the Yoast options + /** + * Mapping between Yoast site representation option names and Hiive event tracking names + * + * @var array + */ private $site_representation_map = array( 'company_or_person' => 'site_representation', 'company_name' => 'organization_name', @@ -19,6 +28,11 @@ class Yoast extends Listener { 'website_name' => 'website_name', ); + /** + * Mapping between Yoast social profiles option names and Hiive event tracking names + * + * @var array + */ private $social_profiles_map = array( 'facebook_site' => 'facebook_profile', 'twitter_site' => 'twitter_profile', @@ -153,8 +167,8 @@ private function maybe_push_site_representation_event( $key, $value, $old_value, // name is a special case, because it represents the company_or_person_user_id which is initialised to false, and the first time the user saves the site representation step // is set either to 0 if the site represents an organisation, or to an integer > 0 if the site represents a person - if ( $key === 'name' ) { - if ( $old_value === false && $value === 0 ) { + if ( 'name' === $key ) { + if ( false === $old_value && 0 === $value ) { return; } } @@ -163,7 +177,7 @@ private function maybe_push_site_representation_event( $key, $value, $old_value, // switched from organisation to person, and then the person id is being set. // Once the name is assigned an integer > 0, it can never go back to 0, even if the user switches back to organisation // ( it "caches" the last user id that was set) - if ( ( $this->is_param_empty( $old_value ) ) || ( $key === 'name' && $old_value === 0 ) ) { + if ( ( $this->is_param_empty( $old_value ) ) || ( 'name' === $key && 0 === $old_value ) ) { $this->push( "set_$key", array( 'category' => $category ) ); return; } @@ -205,7 +219,7 @@ private function maybe_push_social_profiles_event( $key, $value, $old_value, $fa // The option value changed if ( $value !== $old_value ) { - if ( $key === 'other_profiles' ) { + if ( 'other_profiles' === $key ) { $this->push_other_social_profiles( $key, $value, $old_value, $category ); return; } From cd5c3786c816fc057e82538de7ea76ba10a4a4a6 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Brito Date: Tue, 2 Dec 2025 12:32:28 +0000 Subject: [PATCH 3/5] Tweak send only the changed options --- includes/Listeners/Yoast.php | 39 +++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/includes/Listeners/Yoast.php b/includes/Listeners/Yoast.php index 9ecb2a2c..3b1c5a71 100644 --- a/includes/Listeners/Yoast.php +++ b/includes/Listeners/Yoast.php @@ -410,19 +410,44 @@ public function database_upgrade( $previous_version ) { * @return void */ public function option_updated( $old_value, $new_value, $option ) { - if ( $old_value !== $new_value ) { + $modified_values = array(); + $original_values = array(); + + if ( is_array( $old_value ) && is_array( $new_value ) ) { + foreach ( $new_value as $key => $value ) { + + if ( ! array_key_exists( $key, $old_value ) ) { + $modified_values[ $key ] = $value; + continue; + } + $old_val = $old_value[ $key ]; + $has_changed = ( is_array( $value ) || is_object( $value ) ) + ? json_encode( $value ) !== json_encode( $old_val ) + : $value !== $old_val; + + if ( $has_changed ) { + $modified_values[ $key ] = $value; + $original_values[ $key ] = $old_val; + } + } + } elseif ( $old_value !== $new_value ) { + $modified_values = $new_value; + $original_values = $old_value; + } + + if ( ! empty( $modified_values ) ) { $data = array( 'category' => 'yoast_event', 'data' => array( - 'old_value' => $old_value, - 'new_value' => $new_value, + 'old_value' => $original_values, + 'new_value' => $modified_values, ), ); - $this->push( - $option, - $data - ); + $this->push( + $option, + $data + ); } } } From 512dc8e6a57735dfaa5a591c037a1ec6ba2cb964 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Brito Date: Tue, 9 Dec 2025 14:01:32 +0000 Subject: [PATCH 4/5] Tweak send only the modified options --- includes/Listeners/Yoast.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/includes/Listeners/Yoast.php b/includes/Listeners/Yoast.php index 3b1c5a71..1548e496 100644 --- a/includes/Listeners/Yoast.php +++ b/includes/Listeners/Yoast.php @@ -412,7 +412,6 @@ public function database_upgrade( $previous_version ) { public function option_updated( $old_value, $new_value, $option ) { $modified_values = array(); - $original_values = array(); if ( is_array( $old_value ) && is_array( $new_value ) ) { foreach ( $new_value as $key => $value ) { @@ -428,20 +427,17 @@ public function option_updated( $old_value, $new_value, $option ) { if ( $has_changed ) { $modified_values[ $key ] = $value; - $original_values[ $key ] = $old_val; } } } elseif ( $old_value !== $new_value ) { $modified_values = $new_value; - $original_values = $old_value; } if ( ! empty( $modified_values ) ) { $data = array( 'category' => 'yoast_event', 'data' => array( - 'old_value' => $original_values, - 'new_value' => $modified_values, + $modified_values, ), ); $this->push( From 2c66beda63391d36e119e9b72614b9e135ef2ad4 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Brito Date: Tue, 9 Dec 2025 14:46:45 +0000 Subject: [PATCH 5/5] List data --- includes/Listeners/Yoast.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/Listeners/Yoast.php b/includes/Listeners/Yoast.php index 1548e496..2dc0ed56 100644 --- a/includes/Listeners/Yoast.php +++ b/includes/Listeners/Yoast.php @@ -436,14 +436,12 @@ public function option_updated( $old_value, $new_value, $option ) { if ( ! empty( $modified_values ) ) { $data = array( 'category' => 'yoast_event', - 'data' => array( - $modified_values, - ), + 'data' => $modified_values, + ); + $this->push( + $option, + $data ); - $this->push( - $option, - $data - ); } } }