Title: Make opt out JavaScript function available globally
Last modified: May 30, 2018

---

# Make opt out JavaScript function available globally

 *  Resolved [Philipp Bammes](https://wordpress.org/support/users/tyrannous/)
 * (@tyrannous)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/make-opt-out-javascript-functions-available-globally/)
 * Hi,
    great plugin!
 * Please consider making the `gaoo_handle_optout()` function available on every
   page (for example in the footer). The reason is that sometimes it’s necessary
   to access it from third party scripts (like cookie consent management plugins)
   to provide a quick way to handle opt in/opt out functionality.
 * Also, you probably should minify the JavaScript code.
 * What do you think? Thanks!

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

 *  Plugin Author [Schweizer Solutions GmbH](https://wordpress.org/support/users/schweizersolutions/)
 * (@schweizersolutions)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/make-opt-out-javascript-functions-available-globally/#post-10344496)
 * Hi Philipp,
 * thank you for the feature request!
 * You’ll find this in our next update. We added a local storage support as a fallback
   for the cookie. That’s why we had to store the code in a separate file, of course
   minified 😉
 *  Thread Starter [Philipp Bammes](https://wordpress.org/support/users/tyrannous/)
 * (@tyrannous)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/make-opt-out-javascript-functions-available-globally/#post-10378043)
 * Hi [@schweizersolutions](https://wordpress.org/support/users/schweizersolutions/),
 * > You’ll find this in our next update.
 * In v1.3 `gaoo_handle_optout()` still doesn’t seem to be available globally, because
   the JavaScript file is only enqueued on the privacy page.
 * If you do not want to enqueue it on all pages, at least please consider setting
   up `$json_data` variable in a independet method. This would allow third party
   scripts to enqueue the script when needed like this:
 *     ```
       $json_data = GAOO_Public::json_data();
       wp_localize_script( 'gaoo-public', 'gaoo_data', $json_data );
       wp_enqueue_script( 'gaoo-public' );
       ```
   
 * Thanks!
 *  Plugin Author [Schweizer Solutions GmbH](https://wordpress.org/support/users/schweizersolutions/)
 * (@schweizersolutions)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/make-opt-out-javascript-functions-available-globally/#post-10393097)
 * Hi [@tyrannous](https://wordpress.org/support/users/tyrannous/),
 * yes, you are right. We have implemented your suggestion and will release it in
   the next update.
 * The code will be:
 *     ```
       $json_data = GAOO_Utils::get_json();
   
       if ( ! empty( $json_data ) ) {
         wp_localize_script( 'gaoo-public', 'gaoo_data', $json_data );
         wp_enqueue_script( 'gaoo-public' );
       }		
       ```
   
 * Thank you 🙂

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

The topic ‘Make opt out JavaScript function available globally’ is closed to new
replies.

 * ![](https://ps.w.org/opt-out-for-google-analytics/assets/icon-256x256.png?rev
   =2518394)
 * [Opt-Out for Google Analytics (DSGVO / GDPR)](https://wordpress.org/plugins/opt-out-for-google-analytics/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/opt-out-for-google-analytics/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/opt-out-for-google-analytics/)
 * [Active Topics](https://wordpress.org/support/plugin/opt-out-for-google-analytics/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/opt-out-for-google-analytics/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/opt-out-for-google-analytics/reviews/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [opt-out](https://wordpress.org/support/topic-tag/opt-out/)
 * [script](https://wordpress.org/support/topic-tag/script/)

 * 3 replies
 * 2 participants
 * Last reply from: [Schweizer Solutions GmbH](https://wordpress.org/support/users/schweizersolutions/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/make-opt-out-javascript-functions-available-globally/#post-10393097)
 * Status: resolved