| @@ -14,8 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | namespace WCPOS\WooCommercePOS\Admin; |
| 16 | 16 | |
| 17 | 17 | use WCPOS\WooCommercePOS\Services\Settings as SettingsService; |
| 18 | +use WCPOS\WooCommercePOS\Services\Lifecycle_Events; | |
| 18 | 19 | use WP_Error; |
| 19 | 20 | use WP_REST_Request; |
| 20 | 21 | use WP_REST_Response; |
| 21 | 22 | use WP_REST_Server; |
| @@ -148,9 +149,9 @@ | ||
| 148 | 149 | * Keeps the transient from piling up for users who have already |
| 149 | 150 | * opted in or out. |
| 150 | 151 | */ |
| 151 | 152 | private function maybe_set_modal_transient(): void { |
| 152 | - if ( 'undecided' !== woocommerce_pos_get_settings( 'general', 'tracking_consent' ) ) { | |
| 153 | + if ( 'undecided' !== SettingsService::instance()->tracking_consent() ) { | |
| 153 | 154 | return; |
| 154 | 155 | } |
| 155 | 156 | |
| 156 | 157 | set_transient( self::MODAL_TRANSIENT, 1, self::MODAL_TRANSIENT_TTL ); |
| @@ -351,8 +352,21 @@ | ||
| 351 | 352 | if ( $user_id ) { |
| 352 | 353 | delete_user_meta( $user_id, self::CALLOUT_HIDE_META ); |
| 353 | 354 | } |
| 354 | 355 | |
| 356 | + // Only a yes is reported. A no is answered by sending nothing at all. | |
| 357 | + // No surface is attached here: the server cannot tell which prompt the | |
| 358 | + // user answered in, and the paired consent_notice_viewed already | |
| 359 | + // carries the surface that was shown. | |
| 360 | + if ( 'allowed' === $choice ) { | |
| 361 | + ( new Lifecycle_Events() )->report_consent_granted(); | |
| 362 | + } else { | |
| 363 | + // Discard the queued prompt view now rather than leaving it in the | |
| 364 | + // options table until some later admin_init notices the refusal. | |
| 365 | + // A no should take effect in the request that records it. | |
| 366 | + ( new Lifecycle_Events() )->discard_pending(); | |
| 367 | + } | |
| 368 | + | |
| 355 | 369 | return new WP_REST_Response( array( 'consent' => $choice ), 200 ); |
| 356 | 370 | } |
| 357 | 371 | |
| 358 | 372 | /** |
| @@ -393,9 +407,9 @@ | ||
| 393 | 407 | if ( ! current_user_can( 'manage_woocommerce_pos' ) ) { |
| 394 | 408 | return false; |
| 395 | 409 | } |
| 396 | 410 | |
| 397 | - if ( 'undecided' !== woocommerce_pos_get_settings( 'general', 'tracking_consent' ) ) { | |
| 411 | + if ( 'undecided' !== SettingsService::instance()->tracking_consent() ) { | |
| 398 | 412 | return false; |
| 399 | 413 | } |
| 400 | 414 | |
| 401 | 415 | if ( $this->is_callout_hidden_for_user( get_current_user_id() ) ) { |
| @@ -418,8 +432,18 @@ | ||
| 418 | 432 | if ( 'plugins.php' === $hook_suffix && get_transient( self::MODAL_TRANSIENT ) ) { |
| 419 | 433 | $show_modal = true; |
| 420 | 434 | delete_transient( self::MODAL_TRANSIENT ); |
| 421 | 435 | } |
| 436 | + | |
| 437 | + // Record the sighting HERE, not at render time: this is the only place | |
| 438 | + // that knows which surface the user actually gets, and it consumes the | |
| 439 | + // transient that decides it. Reading the transient later reports the | |
| 440 | + // opposite surface every time. | |
| 441 | + // | |
| 442 | + // Queued, never sent — maybe_enqueue() only reaches this while the | |
| 443 | + // answer is undecided, so nothing may leave the site yet. It arrives at | |
| 444 | + // PostHog only if this user goes on to allow tracking. | |
| 445 | + ( new Lifecycle_Events() )->record_consent_prompt_viewed( $show_modal ? 'modal' : 'callout' ); | |
| 422 | 446 | |
| 423 | 447 | // Append the WCPOS request flag so the bundle's REST calls register the |
| 424 | 448 | // now-gated consent routes (see register_routes / Init::init_rest_api). |
| 425 | 449 | $config = array( |