Am I Placing The Code Wrong?
-
I have been trying the past few days to get this working and can’t seem to. I can get it to block cookies but then not re-activate them when the relevant switch is selected.
That or clicking the agree button redirects to an admin page.
I have the js for google analytics in my header.php, am I supposed to wrap it as such?
if ( is_allowed_cookie( '_ga' ) { <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXXXX'); } </script>
And place this in my functions.php?
add_action( ‘wp_head’, ‘my_google_opt_out’ );
function my_google_opt_out() {
if ( ! has_consent( ‘analytics’ ) || ! is_allowed_cookie( ‘_ga’ ) ) {
?>
<script>
window[‘ga-disable-UA-XXXXXXXX-X’] = true; // Don’t forget to replace X for your actual UA numbers.
</script>
<?php
}
}As certain variations of this seem to work for disabling but not enabling, and others flag up as errors in the code and I’ve been staring at this so long I’m going blind to it.
I’m sure it’s simple but if anyone can help it would be much appreciated
- The topic ‘Am I Placing The Code Wrong?’ is closed to new replies.