Title: Am I Placing The Code Wrong?
Last modified: May 22, 2018

---

# Am I Placing The Code Wrong?

 *  [geoggg19](https://wordpress.org/support/users/georgetotalize/)
 * (@georgetotalize)
 * [8 years ago](https://wordpress.org/support/topic/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

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [firefoxfx](https://wordpress.org/support/users/firefoxfx/)
 * (@firefoxfx)
 * [8 years ago](https://wordpress.org/support/topic/am-i-placing-the-code-wrong/#post-10309119)
 * Hi geoggg19,
 * You missed a ) on the first line, and the _ga cookie must been added in the plugin
   at the cookies used on this site section.
    You can use this code: (did not test
   this)
 *     ```
       add_action( 'wp_head', 'my_google_opt_out' );
       function my_google_opt_out() {
         if ( is_allowed_cookie( '_ga' ) ) {
           ?>
       <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
       <script>
         window.dataLayer = window.dataLayer || [];
         function gtag(){dataLayer.push(arguments);}
         gtag('js', new Date());
   
         gtag('config', 'GA_TRACKING_ID');
       </script>
           <?php
         }
       }
       ```
   
 *  Plugin Author [Fernando Claussen](https://wordpress.org/support/users/fclaussen/)
 * (@fclaussen)
 * [8 years ago](https://wordpress.org/support/topic/am-i-placing-the-code-wrong/#post-10309191)
 * This redirection to admin-post.php
 * Do you see an error or just a blank page?
 *  Thread Starter [geoggg19](https://wordpress.org/support/users/georgetotalize/)
 * (@georgetotalize)
 * [8 years ago](https://wordpress.org/support/topic/am-i-placing-the-code-wrong/#post-10309274)
 * [@fclaussen](https://wordpress.org/support/users/fclaussen/)
 * “We could not verify the the security token. Please try again.”
 * I think I may have seen something similar flagged while scanning the support 
   forum
 * Cheers
 *  Plugin Author [Fernando Claussen](https://wordpress.org/support/users/fclaussen/)
 * (@fclaussen)
 * [8 years ago](https://wordpress.org/support/topic/am-i-placing-the-code-wrong/#post-10309625)
 * Yea… I’m working on the next release that will hopefully get rid of this problem.
   Should come out today or tomorrow.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Am I Placing The Code Wrong?’ is closed to new replies.

 * ![](https://ps.w.org/gdpr/assets/icon.svg?rev=1837142)
 * [GDPR](https://wordpress.org/plugins/gdpr/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gdpr/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gdpr/)
 * [Active Topics](https://wordpress.org/support/plugin/gdpr/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gdpr/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gdpr/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [Fernando Claussen](https://wordpress.org/support/users/fclaussen/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/am-i-placing-the-code-wrong/#post-10309625)
 * Status: not resolved