Opt-Out for Google Analytics Dashboard for WordPress

The current Google Analytics Dashboard for WordPress integrates no Opt-Out to disable tracking, which is required in Europe. Here is a workaround for that.

Paste this into your theme function.php.

  1. if ( !is_user_logged_in() &&  class_exists('GADWP_Manager') ) {
  2.  add_action('wp_head', 'ga_optout_script', 1);
  3. }
  4.  
  5. function ga_optout_script(){
  6.  // Read GA Dashboard Settings
  7.  $options =  (array) json_decode(get_option('gadash_options'));
  8.  
  9.  // Get GA Dashboard profiles
  10.  foreach($options['ga_dash_profile_list'] as $profile){
  11.   $ga_ua_profile[$profile[1]] = $profile[2];
  12.  }     
  13.  
  14.  // Get active Analytics profile for the current website
  15.  $active = $options['ga_dash_tableid_jail'];
  16.  $activeUA = $ga_ua_profile[$active];
  17.  
  18.  // Add opt-out script + active UA
  19.  echo "<script>          
  20. var gaProperty = '".$activeUA."';
  21.                        
  22. var disableStr = 'ga-disable-' + gaProperty;
  23.  
  24. if (document.cookie.indexOf(disableStr + '=true') > -1) {
  25.  window[disableStr] = true;
  26.  }                     
  27.  
  28. function gaOptout() {
  29.  document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
  30.  window[disableStr] = true;
  31. }
  32. </script>";
  33. }

Then add this to your data privacy document:

  1. <a href="javascript:gaOptout()">Disable Google Analytics tracking</a>

 

Alex

I am a full-stack developer. I love programming,  design and know my way around server architecture as well.  I would never feel complete, with one of these missing. I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest. Apart from that, I am a peace loving guy who tries to have people around him that think the same.  I truly believe in the principle: “If you help someone, someone will help you, when you need it."

Recent Posts

Particle Network Animations in Javascript

What are particle animations? Particle network animations in JavaScript typically involve creating visual representations of… Read More

3 days ago

B&B / Hotel Booking Solutions for WordPress | 2024

BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More

1 month ago

WordPress Cron + WP-CLI + Ntfy

THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More

2 months ago

2024 is here and now :)

2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More

4 months ago

2023 ends and whats next !

Short look back at 2023 This has been a busy and interesting year. I am… Read More

4 months ago

cubicFUSION Grid Tweaker – Elementor Grid made easy.

Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More

5 months ago