Hi @mooveagency,
I had a similar question. Some other, similar plugins include functions that can be accessed in functions.php to check whether a user has accepted the cookie agreement, etc., so that you can disable GA using the ga-disable-xxxxx cookie.
As an example with monster insights, let’s imagine that your plugin included a function called moove_third_party_cookies_accepted
which would tell us if a user had accepted third party cookies. This code might look like:
add_action( 'init', 'toggle_monster_insights_based_on_moove' );
function toggle_monster_insights_based_on_moove() {
if ( function_exists( 'moove_third_party_cookies_accepted' ) && function_exists('monsterinsights_get_ua')) {
if ( moove_third_party_cookies_accepted() ) {
setCookie( 'ga-disable-'.monsterinsights_get_ua(), 'false' );
}else{
setCookie( 'ga-disable-'.monsterinsights_get_ua(), 'true' );
}
}
}
Otherwise, would it be recommended to do something such as:
$cookie = isset($_COOKIE) && isset($_COOKIE["moove_gdpr_popup"]) ? $_COOKIE["moove_gdpr_popup"] : "";
$decoded = urldecode($cookie);
$json = json_decode($decoded, true);
if(isset($json) && isset($json["thirdparty"]) && $json["thirdparty"] == "1"){
setCookie( 'ga-disable-XXXXXX-X', 'false' );
} else {
setCookie( 'ga-disable-XXXXXX-X', 'true' );
}
?
-
This reply was modified 6 years, 6 months ago by
cmborchert.