@@ -34,10 +34,24 @@ class HelpScout_Beacon implements Integration_Interface {
3434 */
3535 protected $ beacon_id_tracking_users = '6b8e74c5-aa81-4295-b97b-c2a62a13ea7f ' ;
3636
37+ /**
38+ * The id for the beacon for Premium users.
39+ *
40+ * @var string
41+ */
42+ protected $ beacon_id_premium = '1ae02e91-5865-4f13-b220-7daed946ba25 ' ;
43+
44+ /**
45+ * The id for the beacon for WooCommerce SEO users.
46+ *
47+ * @var string
48+ */
49+ protected $ beacon_id_woocommerce = '8535d745-4e80-48b9-b211-087880aa857d ' ;
50+
3751 /**
3852 * The products the beacon is loaded for.
3953 *
40- * @var array
54+ * @var array<string>
4155 */
4256 protected $ products = [];
4357
@@ -55,17 +69,24 @@ class HelpScout_Beacon implements Integration_Interface {
5569 */
5670 protected $ options ;
5771
72+ /**
73+ * The addon manager.
74+ *
75+ * @var WPSEO_Addon_Manager
76+ */
77+ protected $ addon_manager ;
78+
5879 /**
5980 * The array of pages we need to show the beacon on with their respective beacon IDs.
6081 *
61- * @var array
82+ * @var array<string, string>
6283 */
6384 protected $ pages_ids ;
6485
6586 /**
6687 * The array of pages we need to show the beacon on.
6788 *
68- * @var array
89+ * @var array<string>
6990 */
7091 protected $ base_pages = [
7192 'wpseo_dashboard ' ,
@@ -106,10 +127,12 @@ class HelpScout_Beacon implements Integration_Interface {
106127 * @param Options_Helper $options The options helper.
107128 * @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
108129 * @param Migration_Status $migration_status The migrations status.
130+ * @param WPSEO_Addon_Manager $addon_manager The addon manager.
109131 */
110- public function __construct ( Options_Helper $ options , WPSEO_Admin_Asset_Manager $ asset_manager , Migration_Status $ migration_status ) {
132+ public function __construct ( Options_Helper $ options , WPSEO_Admin_Asset_Manager $ asset_manager , Migration_Status $ migration_status, WPSEO_Addon_Manager $ addon_manager ) {
111133 $ this ->options = $ options ;
112134 $ this ->asset_manager = $ asset_manager ;
135+ $ this ->addon_manager = $ addon_manager ;
113136 $ this ->ask_consent = ! $ this ->options ->get ( 'tracking ' );
114137 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
115138 if ( isset ( $ _GET ['page ' ] ) && \is_string ( $ _GET ['page ' ] ) ) {
@@ -121,19 +144,16 @@ public function __construct( Options_Helper $options, WPSEO_Admin_Asset_Manager
121144 }
122145 $ this ->migration_status = $ migration_status ;
123146
147+ $ beacon_id = $ this ->get_beacon_id ();
124148 foreach ( $ this ->base_pages as $ page ) {
125- if ( $ this ->ask_consent ) {
126- // We want to be able to show surveys to people who have tracking on, so we give them a different beacon.
127- $ this ->pages_ids [ $ page ] = $ this ->beacon_id_tracking_users ;
128- }
129- else {
130- $ this ->pages_ids [ $ page ] = $ this ->beacon_id ;
131- }
149+ $ this ->pages_ids [ $ page ] = $ beacon_id ;
132150 }
133151 }
134152
135153 /**
136154 * {@inheritDoc}
155+ *
156+ * @return void
137157 */
138158 public function register_hooks () {
139159 \add_action ( 'admin_enqueue_scripts ' , [ $ this , 'enqueue_help_scout_script ' ] );
@@ -247,7 +267,7 @@ protected function get_session_data() {
247267 /**
248268 * Returns basic info about the server software.
249269 *
250- * @return array
270+ * @return array<string, string>
251271 */
252272 private function get_server_info () {
253273 $ server_tracking_data = new WPSEO_Tracking_Server_Data ();
@@ -441,12 +461,37 @@ private function get_language_settings() {
441461 /**
442462 * Returns the conditionals based on which this integration should be active.
443463 *
444- * @return array The array of conditionals.
464+ * @return array<string> The array of conditionals.
445465 */
446466 public static function get_conditionals () {
447467 return [ Admin_Conditional::class ];
448468 }
449469
470+ /**
471+ * Get the beacon id to use based on the user's subscription and tracking settings.
472+ *
473+ * @return string The beacon id to use.
474+ */
475+ private function get_beacon_id () {
476+ // Case where the user has a Yoast WooCommerce SEO plan subscription (highest priority).
477+ if ( $ this ->addon_manager ->has_valid_subscription ( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ) {
478+ return $ this ->beacon_id_woocommerce ;
479+ }
480+
481+ // Case where the user has a Yoast SEO Premium plan subscription.
482+ if ( $ this ->addon_manager ->has_valid_subscription ( WPSEO_Addon_Manager::PREMIUM_SLUG ) ) {
483+ return $ this ->beacon_id_premium ;
484+ }
485+
486+ // Case where the user has no plan active and tracking enabled.
487+ if ( $ this ->ask_consent ) {
488+ return $ this ->beacon_id_tracking_users ;
489+ }
490+
491+ // Case where the user has no plan active and tracking disabled.
492+ return $ this ->beacon_id ;
493+ }
494+
450495 /**
451496 * Allows filtering of the HelpScout settings. Hooked to admin_head to prevent timing issues, not too early, not too late.
452497 *
@@ -464,8 +509,7 @@ protected function filter_settings() {
464509 * @param string $beacon_settings The HelpScout beacon settings.
465510 */
466511 $ helpscout_settings = \apply_filters ( 'wpseo_helpscout_beacon_settings ' , $ filterable_helpscout_setting );
467-
468- $ this ->products = $ helpscout_settings ['products ' ];
469- $ this ->pages_ids = $ helpscout_settings ['pages_ids ' ];
512+ $ this ->products = $ helpscout_settings ['products ' ];
513+ $ this ->pages_ids = $ helpscout_settings ['pages_ids ' ];
470514 }
471515}
0 commit comments