has_tracking_consent() || $this->is_installation_tracked()) { return; } $client_id = wp_generate_uuid4(); $data = array( 'client_id' => $client_id, 'events' => array( array( 'name' => 'plugin_installation', 'params' => array( 'plugin_name' => 'QuickBundles', 'plugin_version' => QBND_VERSION, 'wp_version' => get_bloginfo('version'), 'php_version' => phpversion(), 'site_language' => get_bloginfo('language'), 'is_multisite' => is_multisite() ? 'yes' : 'no', 'wc_version' => defined('WC_VERSION') ? WC_VERSION : 'unknown', '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, array( 'body' => json_encode($data), 'headers' => array('Content-Type' => 'application/json'), 'timeout' => 5, 'sslverify' => true, )); if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) { update_option('qbnd_installation_tracked', true); } } /** * Handle ajax consent */ public function handle_consent_ajax() { check_ajax_referer('qbnd_nonce', 'nonce'); $consent = isset($_POST['consent']) ? sanitize_text_field($_POST['consent']) : ''; $valid_values = array('allowed', 'denied'); if (!in_array($consent, $valid_values)) { wp_send_json_error(array('message' => __('Invalid consent value', 'quickbundles'))); } update_option('qbnd_tracking_consent', $consent === 'allowed'); update_option('qbnd_tracking_consent_shown', $consent); if ($consent === 'allowed') { $this->track_installation(); wp_send_json_success(array( 'message' => __('Thank you for helping us improve QuickBundles!', 'quickbundles') )); } else { wp_send_json_success(array( 'message' => __('Your preference has been saved.', 'quickbundles') )); } } /** * Check if tracking consent has been given */ private function has_tracking_consent() { return get_option('qbnd_tracking_consent', false); } /** * Check if installation has been tracked */ private function is_installation_tracked() { return get_option('qbnd_installation_tracked', false); } }