Setting up Google Analytics opt-out
-
I’m still wrestling with getting Google Analytics to opt out based on the GDPR plugin’s settings. I saw that the knowledge base for the plugin now suggests adding the following to functions.php:
add_action( 'wp_head', 'my_google_opt_out' ); function my_google_opt_out() { if ( ! is_allowed_cookie( '_ga' ) ) { ?> <script> window['ga-disable-UA-XXXXXXX-X'] = true; </script> <?php } }
This seems to work to insert the window[‘ga-disable-UA-XXXXXXX-X’] shortcode in the header after the Google Analytics script code, but does that actually mean it’s disabling the analytics script, or do I have to do something else to make this shortcode work to stop tracking?
Also, the knowledge base suggests using a JavaScript variation of the above with caching plugins (I am using WP Super Cache), but if I insert that version in my functions.php, the acceptance buttons on the GDPR banner stop working — clicking on them has no effect until I remove that script. Does the JavaScript version of this code need to go somewhere other than functions.php?
Thanks!
The page I need help with: [log in to see the link]
- The topic ‘Setting up Google Analytics opt-out’ is closed to new replies.