__('General Settings', 'acoustic-connect-woo'), 'events' => __('Event Configuration', 'acoustic-connect-woo'), ); echo '
'; } /** * Get settings for current section * * @param string $current_section Current section ID. * @return array */ public function get_settings($current_section = '') { if ('events' === $current_section) { return $this->get_event_settings(); } return $this->get_general_settings(); } /** * Get general settings * * @return array */ private function get_general_settings() { $settings = array( array( 'title' => __('Acoustic Connect Configuration', 'acoustic-connect-woo'), 'type' => 'title', 'desc' => __('Configure your Acoustic Connect integration settings. You need an App Key and Collector URL from your Acoustic Connect account.', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_general_settings', ), array( 'title' => __('Enable Tracking', 'acoustic-connect-woo'), 'desc' => __('Enable Acoustic Connect tracking on your store', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_enabled', 'type' => 'checkbox', 'default' => 'no', ), array( 'title' => __('App Key', 'acoustic-connect-woo'), 'desc' => __('Enter your Acoustic Connect App Key. This key identifies your application.', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_app_key', 'type' => 'text', 'css' => 'min-width:400px;', 'placeholder' => __('Enter your App Key', 'acoustic-connect-woo'), 'desc_tip' => true, ), array( 'title' => __('Collector URL', 'acoustic-connect-woo'), 'desc' => __('Enter your Acoustic Connect Collector URL endpoint where events will be sent.', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_collector_url', 'type' => 'text', 'css' => 'min-width:400px;', 'placeholder' => 'https://lib-us-1.brilliantcollector.com/collector/collectorPost', 'desc_tip' => true, ), array( 'title' => __('Subscription Tier', 'acoustic-connect-woo'), 'desc' => __('Select your Acoustic Connect subscription tier. This determines which signals are available.', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_subscription_tier', 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => 'pro', 'options' => array( 'pro' => __('Pro - Basic signals (Identification, Add to Cart, Order)', 'acoustic-connect-woo'), 'premium' => __('Premium - All signals including Page View, Product View, Search', 'acoustic-connect-woo'), 'ultimate' => __('Ultimate - All signals including Page View, Product View, Search', 'acoustic-connect-woo'), ), 'desc_tip' => __('Pro tier: identification, addToCart, order signals only. Premium/Ultimate: all signal types including pageView, productView, onSiteSearch, productConfiguration, error, richMediaInteraction.', 'acoustic-connect-woo'), ), array( 'type' => 'sectionend', 'id' => 'acoustic_connect_general_settings', ), array( 'title' => __('Debug Options', 'acoustic-connect-woo'), 'type' => 'title', 'desc' => __('Enable debug mode to log events to the browser console. Disable in production.', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_debug_settings', ), array( 'title' => __('Enable Debug Mode', 'acoustic-connect-woo'), 'desc' => __('Log events to browser console for debugging (disable in production)', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_debug_mode', 'type' => 'checkbox', 'default' => 'no', ), array( 'type' => 'sectionend', 'id' => 'acoustic_connect_debug_settings', ), ); return apply_filters('acoustic_connect_general_settings', $settings); } /** * Get event settings * * @return array */ private function get_event_settings() { $settings = array( array( 'title' => __('Event Tracking Configuration', 'acoustic-connect-woo'), 'type' => 'title', 'desc' => __('Configure which events to track on your store.', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_event_settings', ), array( 'title' => __('Track Page Views', 'acoustic-connect-woo'), 'desc' => __('Track all page views on your store', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_track_page_view', 'type' => 'checkbox', 'default' => 'yes', ), array( 'title' => __('Track Product Views', 'acoustic-connect-woo'), 'desc' => __('Track when customers view product pages', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_track_product_view', 'type' => 'checkbox', 'default' => 'yes', ), array( 'title' => __('Track Search', 'acoustic-connect-woo'), 'desc' => __('Track product searches on your store', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_track_search', 'type' => 'checkbox', 'default' => 'yes', ), array( 'title' => __('Track Add to Cart', 'acoustic-connect-woo'), 'desc' => __('Track when products are added to cart', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_track_add_to_cart', 'type' => 'checkbox', 'default' => 'yes', ), array( 'title' => __('Track Remove from Cart', 'acoustic-connect-woo'), 'desc' => __('Track when products are removed from cart', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_track_remove_from_cart', 'type' => 'checkbox', 'default' => 'yes', ), array( 'title' => __('Track Checkout Steps', 'acoustic-connect-woo'), 'desc' => __('Track the checkout process and steps', 'acoustic-connect-woo'), 'id' => 'acoustic_connect_track_checkout', 'type' => 'checkbox', 'default' => 'yes', ), array( 'type' => 'sectionend', 'id' => 'acoustic_connect_event_settings', ), ); return apply_filters('acoustic_connect_event_settings', $settings); } /** * Output settings */ public function output_settings() { global $current_section; $settings = $this->get_settings($current_section); // Add custom connection test button if (empty($current_section)) { echo ''; } WC_Admin_Settings::output_fields($settings); } /** * Update settings */ public function update_settings() { global $current_section; $settings = $this->get_settings($current_section); // Validate and sanitize Collector URL before saving if (empty($current_section) && isset($_POST['acoustic_connect_collector_url'])) { // Verify nonce before processing form data check_admin_referer('woocommerce-settings'); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $collector_url = esc_url_raw(wp_unslash($_POST['acoustic_connect_collector_url'])); // Validate against allowed URLs if (!empty($collector_url) && !in_array($collector_url, self::$allowed_collector_urls, true)) { WC_Admin_Settings::add_error( __('Invalid Collector URL. Please use one of the following:', 'acoustic-connect-woo') . '
• lib-us-1.brilliantcollector.com (US-1)' . '
• lib-us-2.brilliantcollector.com (US-2)' . '
• lib-eu-1.brilliantcollector.com (EU-1)' . '
• lib-ap-1.brilliantcollector.com (AP-1)' ); // Keep the old value by not updating this field $_POST['acoustic_connect_collector_url'] = get_option('acoustic_connect_collector_url', ''); } else { $_POST['acoustic_connect_collector_url'] = $collector_url; } } WC_Admin_Settings::save_fields($settings); // Clear any caches if needed if (function_exists('wp_cache_flush')) { wp_cache_flush(); } } /** * Enqueue admin scripts * * @param string $hook Page hook. */ public function admin_scripts($hook) { // Only load on settings page if ('woocommerce_page_wc-settings' !== $hook) { return; } // Check if we're on our settings tab // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only check for current tab if (!isset($_GET['tab']) || 'acoustic_connect' !== sanitize_key($_GET['tab'])) { return; } // Enqueue admin styles wp_enqueue_style( 'acoustic-connect-admin', ACOUSTIC_CONNECT_WOO_PLUGIN_URL . 'assets/css/admin.css', array(), ACOUSTIC_CONNECT_WOO_VERSION ); // Enqueue admin scripts wp_enqueue_script( 'acoustic-connect-admin', ACOUSTIC_CONNECT_WOO_PLUGIN_URL . 'assets/js/admin.js', array('jquery'), ACOUSTIC_CONNECT_WOO_VERSION, true ); // Localize script wp_localize_script( 'acoustic-connect-admin', 'acousticConnectAdmin', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('acoustic_connect_admin'), 'testingText' => __('Testing connection...', 'acoustic-connect-woo'), 'successText' => __('Connection successful!', 'acoustic-connect-woo'), 'errorText' => __('Connection failed. Please check your Collector URL.', 'acoustic-connect-woo'), ) ); } }