has_tracking_consent() || $this->is_installation_tracked()) { return; } $client_id = wp_generate_uuid4(); $timestamp_micros = (int)(microtime(true) * 1000000); $data = [ 'client_id' => $client_id, 'events' => [ [ 'name' => 'plugin_installation', 'params' => [ 'plugin_name' => 'QuickBundles for WooCommerce', 'site_url' => get_site_url() ] ] ] ]; $url = sprintf( 'https://www.google-analytics.com/mp/collect?measurement_id=%s&api_secret=%s', $this->measurement_id, $this->api_secret ); $response = wp_remote_post($url, [ 'body' => wp_json_encode($data), 'headers' => ['Content-Type' => 'application/json'], 'timeout' => 5, 'sslverify' => true, ]); if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) { update_option('quickbundles_installation_tracked', true); } } public function handle_consent_ajax(): void { check_ajax_referer('quickbundles_nonce', 'nonce'); $consent = isset($_POST['consent']) ? sanitize_text_field($_POST['consent']) : ''; $valid_values = ['allowed', 'denied']; if (!in_array($consent, $valid_values)) { wp_send_json_error(['message' => __('Invalid consent value', 'quickbundles')]); } update_option('quickbundles_tracking_consent', $consent === 'allowed'); update_option('quickbundles_tracking_consent_shown', $consent); if ($consent === 'allowed') { $this->track_installation(); wp_send_json_success([ 'message' => __('Thank you for helping us improve QuickBundles!', 'quickbundles') ]); } else { wp_send_json_success([ 'message' => __('Your preference has been saved.', 'quickbundles') ]); } } private function has_tracking_consent(): bool { return get_option('quickbundles_tracking_consent', false); } private function is_installation_tracked(): bool { return get_option('quickbundles_installation_tracked', false); } }