Disable cookies using Cookiebot plugin with Convert Pro for GDPR regulations

Might you be concerned about cookie consent rule from GDPR regulations? You might need to disable cookies from plugin according to users Consent. Here is how you can manage with Convert Pro plugin.

Prerequisites

Cookiebot plugin helps to disable cookies from your site.  Cookiebot works with script data attribute to disable loading of scripts which prevent tracking cookie. To add such script attribute for Convert Pro plugin, you need to use filter hooks provided.

Add following code to your theme’s functions.php file

add_filter( 'script_loader_tag', 'cpro_add_extra_atts', 999, 3 );

// Function to add extra attributes to cp-popup.js script loaded on front end.
function cpro_add_extra_atts( $tag, $handle, $src ) {
	
	//The handles of the enqueued scripts.
    $scripts = array(
		'cp-ideal-timer-script',
		'cp-popup-script',
    );

    if ( in_array( $handle, $scripts ) ) {
        $tag = str_replace( 'src', 'data-cookieconsent="marketing" src', $tag );
        $tag = str_replace( 'text/javascript', 'text/plain', $tag );
        $tag = str_replace( 'defer="defer"', '', $tag );
    }

    return $tag;
}

add_filter( 'cpro_ga_manual_script_atts', 'cpro_ga_script_atts', 999, 1 );

// Function to add extra attributes to cp-popup.js script loaded on front end.
function cpro_ga_script_atts( $atts ) {

    $atts = 'type="text/plain" data-cookieconsent="marketing"';

    return $atts;
}

add_filter( 'cpro_ga_analytics_script_atts', 'cpro_ga_custom_script_atts', 999, 1 );

// Function to add extra attributes to GA event creation script.
function cpro_ga_custom_script_atts( $atts ) {

    $atts = 'type="text/plain" data-cookieconsent="marketing"';

    return $atts;
}

Important Note: As Convert Pro functionality depends on JavaScript, depending on users consent, major functionality from Convert Pro might affect.

Not the solution you are looking for? Check other articles, or open a support ticket.