| @@ -9,10 +9,14 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace WCPOS\WooCommercePOS\Admin; |
| 12 | 12 | |
| 13 | +use WCPOS\WooCommercePOS\Logger; | |
| 13 | 14 | use WCPOS\WooCommercePOS\Services\Analytics; |
| 15 | +use WCPOS\WooCommercePOS\Services\Analytics_Profile; | |
| 14 | 16 | use WCPOS\WooCommercePOS\Services\Landing_Profile; |
| 17 | +use WCPOS\WooCommercePOS\Services\Lifecycle_Events; | |
| 18 | +use WCPOS\WooCommercePOS\Services\Settings; | |
| 15 | 19 | use const WCPOS\WooCommercePOS\PLUGIN_NAME; |
| 16 | 20 | use const WCPOS\WooCommercePOS\PLUGIN_URL; |
| 17 | 21 | use const WCPOS\WooCommercePOS\TRANSLATION_VERSION; |
| 18 | 22 | use const WCPOS\WooCommercePOS\VERSION as PLUGIN_VERSION; |
| @@ -232,9 +236,8 @@ | ||
| 232 | 236 | */ |
| 233 | 237 | public function enqueue_landing_scripts_and_styles( $hook_suffix ): void { |
| 234 | 238 | if ( $hook_suffix === $this->toplevel_screen_id ) { |
| 235 | 239 | $analytics = Analytics::instance(); |
| 236 | - $site_id = $analytics->get_site_id(); | |
| 237 | 240 | |
| 238 | 241 | $analytics->capture_once( |
| 239 | 242 | 'upgrade_cta_viewed', |
| 240 | 243 | array( |
| @@ -242,12 +245,22 @@ | ||
| 242 | 245 | ), |
| 243 | 246 | 'admin_landing_banner' |
| 244 | 247 | ); |
| 245 | 248 | |
| 246 | - if ( '' !== $site_id ) { | |
| 247 | - $analytics->group( 'site', $site_id, array() ); | |
| 248 | - } | |
| 249 | + // Bind this install to its `site` group and refresh the profile that | |
| 250 | + // hangs off it. Sending the properties matters: a bare group() call | |
| 251 | + // creates the group with an empty property set, which is what made | |
| 252 | + // every environment and store-size breakdown unqueryable (#793). | |
| 253 | + ( new Lifecycle_Events() )->maybe_refresh_group_properties(); | |
| 249 | 254 | |
| 255 | + // The activation funnel's middle step, carrying the feature-adoption | |
| 256 | + // snapshot. One snapshot per view answers "what share of stores | |
| 257 | + // enable X" without an event per settings toggle. | |
| 258 | + $analytics->capture( | |
| 259 | + 'admin_landing_viewed', | |
| 260 | + array( 'settings_summary' => ( new Analytics_Profile() )->get_settings_summary() ) | |
| 261 | + ); | |
| 262 | + | |
| 250 | 263 | $is_development = isset( $_ENV['DEVELOPMENT'] ) |
| 251 | 264 | && wp_validate_boolean( sanitize_text_field( wp_unslash( $_ENV['DEVELOPMENT'] ) ) ); |
| 252 | 265 | $url = $is_development ? 'http://localhost:9000/' : 'https://cdn.jsdelivr.net/gh/wcpos/wp-admin-landing@2/assets/'; |
| 253 | 266 | |
| @@ -454,9 +467,10 @@ | ||
| 454 | 467 | $json_flags = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT; |
| 455 | 468 | $profile = new Landing_Profile(); |
| 456 | 469 | $data = $profile->get_functional_data(); |
| 457 | 470 | |
| 458 | - $consent = woocommerce_pos_get_settings( 'general', 'tracking_consent' ); | |
| 471 | + // Send gate: the persisted answer, not the filtered read view. | |
| 472 | + $consent = Settings::instance()->raw_tracking_consent(); | |
| 459 | 473 | if ( 'allowed' === $consent ) { |
| 460 | 474 | $data = array_merge( $data, $profile->get_consented_data() ); |
| 461 | 475 | } |
| 462 | 476 | |
| @@ -462,10 +476,9 @@ | ||
| 462 | 476 | |
| 463 | 477 | $encoded = wp_json_encode( $data, $json_flags ); |
| 464 | 478 | |
| 465 | 479 | if ( false === $encoded ) { |
| 466 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 467 | - error_log( 'WCPOS landing data JSON encoding failed: ' . json_last_error_msg() ); | |
| 480 | + Logger::error( 'Landing data JSON encoding failed: ' . json_last_error_msg() ); | |
| 468 | 481 | $encoded = '{}'; |
| 469 | 482 | } |
| 470 | 483 | |
| 471 | 484 | return \sprintf( |
| @@ -557,9 +570,9 @@ | ||
| 557 | 570 | |
| 558 | 571 | wp_enqueue_script( |
| 559 | 572 | 'wcpos-template-gallery', |
| 560 | 573 | PLUGIN_URL . $dir . '/js/template-gallery.js', |
| 561 | - array( 'react', 'react-dom', 'wp-api-fetch', 'wp-url' ), | |
| 574 | + array( 'react', 'react-dom', 'wp-api-fetch', \WCPOS\WooCommercePOS\Admin::API_FETCH_METHOD_PARAM_HANDLE, 'wp-url' ), | |
| 562 | 575 | PLUGIN_VERSION, |
| 563 | 576 | true |
| 564 | 577 | ); |
| 565 | 578 | |
| @@ -573,9 +586,9 @@ | ||
| 573 | 586 | $json_encode_flags = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT; |
| 574 | 587 | |
| 575 | 588 | return \sprintf( |
| 576 | 589 | 'var wcpos = wcpos || {}; wcpos.templateGallery = { isProActive: %s, adminUrl: %s, hasPosOrders: %s, previewBaseUrl: %s }; wcpos.translationVersion = %s;', |
| 577 | - wp_json_encode( class_exists( '\WCPOS\WooCommercePOSPro\WooCommercePOSPro' ), $json_encode_flags ), | |
| 590 | + wp_json_encode( wcpos_is_pro_active(), $json_encode_flags ), | |
| 578 | 591 | wp_json_encode( untrailingslashit( admin_url() ), $json_encode_flags ), |
| 579 | 592 | wp_json_encode( |
| 580 | 593 | (bool) wc_get_orders( |
| 581 | 594 | array( |