|
<?php |
|
|
|
function monsterinsights_cookie_notice_tracking_fix() { |
|
if ( ! class_exists( 'Cookie_Notice' ) ) { |
|
return; |
|
} |
|
ob_start(); |
|
?> |
|
/* Compatibility with Cookie Notice */ |
|
if ( document.cookie.indexOf( 'hu-consent' ) === -1 ) { |
|
mi_track_user = false; |
|
mi_no_track_reason = '<?php echo esc_js( __( "Note: You have not accepted the Cookie Notice.", "monsterinsights-eu-compliance" ) );?>'; |
|
} else { |
|
var mi_cn_value = document.cookie; |
|
var mi_cn_name = 'hu-consent'; |
|
var mi_cn_starts_at = mi_cn_value.indexOf(" " + mi_cn_name + "="); |
|
if (mi_cn_starts_at == -1) { |
|
mi_cn_starts_at = mi_cn_value.indexOf(mi_cn_name + "="); |
|
} |
|
if (mi_cn_starts_at == -1) { |
|
mi_cn_value = null; |
|
} else { |
|
mi_cn_starts_at = mi_cn_value.indexOf("=", mi_cn_starts_at) + 1; |
|
var mi_cn_ends_at = mi_cn_value.indexOf(";", mi_cn_starts_at); |
|
if (mi_cn_ends_at == -1) { |
|
mi_cn_ends_at = mi_cn_value.length; |
|
} |
|
mi_cn_value = unescape(mi_cn_value.substring(mi_cn_starts_at,mi_cn_ends_at)); |
|
} |
|
var cookie_object = JSON.parse(mi_cn_value); |
|
|
|
if ( cookie_object.consent !== true || cookie_object.consentLevel < 2 ) { |
|
mi_track_user = false; |
|
mi_no_track_reason = '<?php echo esc_js( __( "Note: You declined cookies on the Cookie Notice consent bar.", "monsterinsights-eu-compliance" ) );?>'; |
|
} |
|
} |
|
<?php |
|
$output = ob_get_contents(); |
|
ob_end_clean(); |
|
echo $output; |
|
} |
|
|
|
add_action( 'monsterinsights_tracking_analytics_frontend_output_after_mi_track_user', 'monsterinsights_cookie_notice_tracking_fix', 9 ); |
|
add_action( 'monsterinsights_tracking_gtag_frontend_output_after_mi_track_user', 'monsterinsights_cookie_notice_tracking_fix', 9 ); |
|
|
|
function monsterinsights_remove_old_cookie_notice_action() { |
|
remove_action( 'monsterinsights_tracking_analytics_frontend_output_after_mi_track_user', 'monsterinsights_eu_compliance_cookie_notice_integration' ); |
|
remove_action( 'monsterinsights_tracking_gtag_frontend_output_after_mi_track_user', 'monsterinsights_eu_compliance_cookie_notice_integration' ); |
|
} |
|
|
|
add_action('init', 'monsterinsights_remove_old_cookie_notice_action'); |