VWO for more details. * Author: VWO * Version: 4.10 * visual-website-optimizer.php * Author URI: https://vwo.com/ * * @package VWO * @author VWO * @version 4.10 **/ /** * Generate Common Code * * @param integer $vwo_clicks integer. Defaults to 10. */ function get_vwo_clhf_script_common_code( $vwo_clicks = 10 ) { ob_start(); // @codingStandardsIgnoreStart ?> 'vwo_clhf_sanitize_settings', )); register_setting( 'clhf_vwo_options', 'code_type' ); register_setting( 'clhf_vwo_options', 'vwo_clicks' ); register_setting( 'clhf_vwo_options', 'ignore_js', 'boolval' ); register_setting( 'clhf_vwo_options', 'settings_tolerance', 'intval' ); register_setting( 'clhf_vwo_options', 'library_tolerance', 'intval' ); register_setting( 'clhf_vwo_options', 'use_existing_jquery', 'boolval' ); register_setting( 'clhf_vwo_options', 'enable_woocommerce_event_tracking', 'boolval'); register_setting( 'clhf_vwo_options', 'track_product_view', 'boolval' ); register_setting( 'clhf_vwo_options', 'track_add_to_cart', 'boolval' ); register_setting( 'clhf_vwo_options', 'track_remove_from_cart', 'boolval' ); register_setting( 'clhf_vwo_options', 'track_checkout', 'boolval' ); register_setting( 'clhf_vwo_options', 'track_purchase', 'boolval' ); register_setting( 'clhf_vwo_options', 'vwo_server_side_tracking', 'boolval' ); } // ------------------------------------------------------------------------// // ---Output Functions-----------------------------------------------------// // ------------------------------------------------------------------------// /** * Generates the action vwo_clhf_headercode function. * * @throws Exception Description of exception. * @return void */ function vwo_clhf_headercode() { // Runs in the header. $vwo_id = get_option( 'vwo_id' ); $code_type = get_option( 'code_type' ); if ( $vwo_id ) { if ( empty( get_option( 'vwo_clicks' ) ) ) { update_option( 'vwo_clicks', '10' ); } $vwo_clicks = get_option( 'vwo_clicks' ); // Common script code. // @codingStandardsIgnoreLine echo get_vwo_clhf_script_common_code( $vwo_clicks ); if ( 'SYNC' === $code_type ) { // Sync script code. // @codingStandardsIgnoreLine echo get_vwo_clhf_script_sync_code( $vwo_id ); } else { $settings_tolerance = get_option( 'settings_tolerance' ); if ( ! is_numeric( $settings_tolerance ) ) { $settings_tolerance = 2000; } $library_tolerance = get_option( 'library_tolerance' ); if ( ! is_numeric( $library_tolerance ) ) { $library_tolerance = 2500; } $use_existing_jquery = get_option( 'use_existing_jquery' ); $use_existing_jquery = ( '1' === $use_existing_jquery ) ? true : false; // Async script code. // @codingStandardsIgnoreLine echo get_vwo_clhf_script_async_code( $vwo_id, $settings_tolerance, $library_tolerance, $use_existing_jquery ); } } } // ------------------------------------------------------------------------// // ---Page Output Functions------------------------------------------------// // ------------------------------------------------------------------------// // options page /** * Generates the options page for the VWO plugin. * * @throws Exception Description of exception. * @return void */ function vwo_clhf_plugin_options() { ?>

VWO LogoConfiguration

'vwo_id', 'label' => 'Your VWO Account ID', 'type' => 'text', 'tooltip' => 'Enter your VWO Account ID here', ]); vwo_clhf_render_field([ 'id' => 'code_type', 'label' => 'Code Type', 'type' => 'radio', 'options' => [ [ 'label' => 'Asynchronous', 'value' => 'ASYNC', 'sublabel' => 'Loads faster without blocking other elements', ], [ 'label' => 'Synchronous', 'value' => 'SYNC', 'sublabel' => 'Executes immediately but may slow down page load', ], ], ]); ?>
New to VWO?
Create a free account to start optimising your website, no credit card required.
Get Started for Free
VWO Dashboard?
Visit our knowledge base to learn how to use the VWO dashboard.
Go to Dashboard
Need help? Visit our Knowledge Base for guides and FAQs.
'vwo_clicks', 'label' => 'No. of Heatmap Clicks', 'type' => 'number', 'tooltip' => 'Set the number of heatmap clicks to record', 'min' => 3, 'default' => 10, ]); vwo_clhf_render_field([ 'id' => 'settings_tolerance', 'label' => 'Settings Timeout', 'type' => 'number', 'tooltip' => 'Set the timeout for settings in milliseconds', 'default' => 2000, 'class' => 'async-option', 'suffix' => 'ms', ]); vwo_clhf_render_field([ 'id' => 'library_tolerance', 'label' => 'Library Timeout', 'type' => 'number', 'tooltip' => 'Set the timeout for library in milliseconds', 'default' => 2500, 'class' => 'async-option', 'suffix' => 'ms', ]); vwo_clhf_render_field([ 'id' => 'use_existing_jquery', 'label' => 'Use Existing jQuery', 'type' => 'checkbox', 'tooltip' => 'Use the existing jQuery library on your site', 'class' => 'async-option', ]); vwo_clhf_render_field([ 'id' => 'ignore_js', 'label' => 'Skip Deferred Execution', 'type' => 'checkbox', 'tooltip' => 'Skip deferred execution of the VWO script', ]); ?>
>

Event tracking will not work unless WooCommerce is enabled on your WordPress site.

>

Enable server-side tracking instead of JavaScript-based tracking.

'track_product_view', 'label' => 'Product Viewed', 'description' => 'This event logs an instance where a customer views a product details page.', 'readmore_link' => 'https://help.vwo.com/hc/en-us/articles/360020745993-Integrating-VWO-With-WordPress' ]); vwo_clhf_render_woocommerce_event_tracking([ 'id' => 'track_add_to_cart', 'label' => 'Add To Cart', 'description' => 'This event logs an instance where a customer adds a product to their cart.', 'readmore_link' => 'https://help.vwo.com/hc/en-us/articles/360020745993-Integrating-VWO-With-WordPress' ]); vwo_clhf_render_woocommerce_event_tracking([ 'id' => 'track_remove_from_cart', 'label' => 'Product Removed From Cart', 'description' => 'This event logs an instance where a customer removes a product from their cart.', 'readmore_link' => 'https://help.vwo.com/hc/en-us/articles/360020745993-Integrating-VWO-With-WordPress' ]); // vwo_clhf_render_woocommerce_event_tracking([ // 'id' => 'track_checkout', // 'label' => 'Checkout Page', // 'description' => 'This event logs an instance where a customer visits the checkout page.', // 'readmore_link' => 'https://help.vwo.com/hc/en-us/articles/360020745993-Integrating-VWO-With-WordPress' // ]); vwo_clhf_render_woocommerce_event_tracking([ 'id' => 'track_purchase', 'label' => 'Purchase Order', 'description' => 'This event logs an instance where a customer completes a purchase.', 'readmore_link' => 'https://help.vwo.com/hc/en-us/articles/360020745993-Integrating-VWO-With-WordPress' ]); ?>

class="vwo-checkbox">

Read more

'; $label = ''; switch ($field['type']) { case 'text': case 'number': echo $label; echo ''; if (isset($field['suffix'])) echo ' ' . esc_html($field['suffix']); break; case 'radio': echo $label; foreach ($field['options'] as $options) { echo '
'; echo ' '; echo '
'; echo '

' . esc_html($options['sublabel']) . '

'; echo '
'; } break; case 'checkbox': echo '
'; echo ''; echo ''; echo ''; echo '
'; break; } if (isset($field['tooltip'])) { echo '

' . esc_html($field['tooltip']) . '

'; } echo ''; } function vwo_clhf_render_styles() { ?>

VWO is almost ready. You must enter your Account ID for it to work.

"; } } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'vwo_clhf_add_plugin_page_settings_link' ); /** * Function to add Settings Links on Plugin page * * @param array $links Array of links. * @return array */ function vwo_clhf_add_plugin_page_settings_link( $links ) { $links[] = '' . __( 'Settings' ) . ''; return $links; } /** * Disables VWO in Divi Builder. * * @throws Exception Description of exception. * @return void */ function disable_vwo_in_divi_builder() { if ( has_action( 'wp_head', 'vwo_clhf_headercode' ) && function_exists( 'et_core_is_fb_enabled' ) && et_core_is_fb_enabled() ) { remove_action( 'wp_head', 'vwo_clhf_headercode', 1 ); } } add_action( 'wp_head', 'disable_vwo_in_divi_builder', 0 ); // Add this new function to validate settings function vwo_clhf_validate_settings() { $has_errors = false; // Validate VWO Account ID $vwo_id = get_option('vwo_id'); if (empty($vwo_id) || !is_numeric($vwo_id)) { add_settings_error('vwo_clhf_options', 'vwo_id', 'Please enter a valid VWO Account ID.', 'error'); $has_errors = true; } // Add more validation for other fields as needed return $has_errors; } // Add this new function to sanitize and validate settings function vwo_clhf_sanitize_settings($input) { // Sanitize and validate VWO Account ID $vwo_id = sanitize_text_field($input); if (empty($vwo_id) || !is_numeric($vwo_id)) { add_settings_error('vwo_clhf_options', 'vwo_id', 'Please enter a valid VWO Account ID.', 'error'); } // Add more sanitization and validation for other fields as needed // Check if vwo_id is changed $current_vwo_id = get_option('vwo_id'); if ($current_vwo_id !== $vwo_id) { update_option('vwo_coll_url',''); } return $vwo_id; } function enqueue_jquery_script() { wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'enqueue_jquery_script'); if (file_exists(plugin_dir_path(__FILE__) . 'woocommerce-events.php')) { include_once plugin_dir_path(__FILE__) . 'woocommerce-events.php'; } ?>