Changeset 2664664
- Timestamp:
- 01/25/2022 03:12:58 PM (4 years ago)
- Location:
- opt-out-for-google-analytics
- Files:
-
- 39 added
- 9 edited
-
assets/banner-1544x500.png (modified) (previous)
-
assets/banner-772x250.png (modified) (previous)
-
tags/2.0 (added)
-
tags/2.0/assets (added)
-
tags/2.0/assets/admin.css (added)
-
tags/2.0/assets/admin.js (added)
-
tags/2.0/assets/icon.png (added)
-
tags/2.0/assets/index.php (added)
-
tags/2.0/assets/optout-block.js (added)
-
tags/2.0/assets/public.js (added)
-
tags/2.0/assets/public.min.js (added)
-
tags/2.0/assets/tinymce.js (added)
-
tags/2.0/constants.php (added)
-
tags/2.0/ga-opt-out.php (added)
-
tags/2.0/inc (added)
-
tags/2.0/inc/activator.class.php (added)
-
tags/2.0/inc/admin.class.php (added)
-
tags/2.0/inc/deactivator.class.php (added)
-
tags/2.0/inc/index.php (added)
-
tags/2.0/inc/messages.class.php (added)
-
tags/2.0/inc/promo.class.php (added)
-
tags/2.0/inc/public.class.php (added)
-
tags/2.0/inc/singleton.class.php (added)
-
tags/2.0/inc/utils.class.php (added)
-
tags/2.0/index.php (added)
-
tags/2.0/lib (added)
-
tags/2.0/lib/csstidy (added)
-
tags/2.0/lib/csstidy/class.csstidy.php (added)
-
tags/2.0/lib/csstidy/class.csstidy_optimise.php (added)
-
tags/2.0/lib/csstidy/class.csstidy_print.php (added)
-
tags/2.0/lib/csstidy/data.inc.php (added)
-
tags/2.0/lib/csstidy/index.php (added)
-
tags/2.0/lib/csstidy/lang.inc.php (added)
-
tags/2.0/lib/index.php (added)
-
tags/2.0/readme.txt (added)
-
tags/2.0/templates (added)
-
tags/2.0/templates/index.php (added)
-
tags/2.0/templates/promotion.php (added)
-
tags/2.0/templates/settings.php (added)
-
tags/2.0/uninstall.php (added)
-
tags/2.0/wpml-config.xml (added)
-
trunk/constants.php (modified) (1 diff)
-
trunk/ga-opt-out.php (modified) (1 diff)
-
trunk/inc/admin.class.php (modified) (1 diff)
-
trunk/inc/public.class.php (modified) (1 diff)
-
trunk/inc/utils.class.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/templates/settings.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
opt-out-for-google-analytics/trunk/constants.php
r2574575 r2664664 8 8 defined( 'GAOO_PLUGIN_URL' ) || define( 'GAOO_PLUGIN_URL', WP_PLUGIN_URL . DIRECTORY_SEPARATOR . GAOO_PLUGIN_NAME ); 9 9 defined( 'GAOO_PREFIX' ) || define( 'GAOO_PREFIX', '_gaoo_' ); 10 defined( 'GAOO_VERSION' ) || define( 'GAOO_VERSION', ' 1.9' );10 defined( 'GAOO_VERSION' ) || define( 'GAOO_VERSION', '2.0' ); 11 11 defined( 'GAOO_SHORTCODE' ) || define( 'GAOO_SHORTCODE', '[ga_optout]' ); 12 12 defined( 'GAOO_CAPABILITY' ) || define( 'GAOO_CAPABILITY', 'manage_options' ); -
opt-out-for-google-analytics/trunk/ga-opt-out.php
r2574575 r2664664 4 4 * Plugin URI: https://www.schweizersolutions.com/?utm_source=wordpress&utm_medium=plugin&utm_campaign=plugin_uri 5 5 * Description: Adds the possibility for the user to opt out from Google Analytics. The user will not be tracked by Google Analytics on this site until he allows it again, clears his cookies or uses a different browser. 6 * Version: 1.96 * Version: 2.0 7 7 * Author: Schweizer Solutions GmbH 8 8 * Author URI: https://www.schweizersolutions.com/?utm_source=wordpress&utm_medium=plugin&utm_campaign=author_uri -
opt-out-for-google-analytics/trunk/inc/admin.class.php
r2574575 r2664664 337 337 // Validate UA code if entered manually, otherwise empty field. 338 338 if ( $data[ 'ga_plugin' ] == 'manual' && ! empty( $data[ 'ua_code' ] ) ) { 339 $data[ 'ua_code' ] = GAOO_Utils::validate_ua_code( $data[ 'ua_code' ]);339 $data[ 'ua_code' ] = GAOO_Utils::validate_ua_code( strtoupper( $data[ 'ua_code' ] ) ); 340 340 341 341 if ( empty( $data[ 'ua_code' ] ) ) { 342 $this->messages->addError( esc_html__( "Please enter a valid UA Code. Format: UA-XXXXXX-Y", 'opt-out-for-google-analytics' ) );342 $this->messages->addError( esc_html__( "Please enter a valid UA- or G-Code (Google Analytics 4). Format: UA-XXXXXX-Y or G-XXXXXXXXXX", 'opt-out-for-google-analytics' ) ); 343 343 } 344 344 } 345 345 else { 346 $data[ 'ua_code' ] = ''; 346 $data[ 'ua_code' ] = ''; 347 $data[ 'tracking_code' ] = ''; 347 348 } 348 349 -
opt-out-for-google-analytics/trunk/inc/public.class.php
r2179559 r2664664 1 1 <?php 2 2 3 // If this file is called directly, abort.4 defined( 'WPINC' ) || die;3 // If this file is called directly, abort. 4 defined( 'WPINC' ) || die; 5 5 6 class GAOO_Public {7 private $csstidy;6 class GAOO_Public { 7 private $csstidy; 8 8 9 /**10 * GAOO_Public constructor.11 */12 public function __construct() {13 add_action( 'wp_head', array( $this, 'head_script' ), -1 );14 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );9 /** 10 * GAOO_Public constructor. 11 */ 12 public function __construct() { 13 add_action( 'wp_head', array( $this, 'head_script' ), -1 ); 14 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 15 15 16 add_shortcode( 'ga_optout', array( $this, 'shortcode' ) );16 add_shortcode( 'ga_optout', array( $this, 'shortcode' ) ); 17 17 18 if ( has_filter( 'widget_text', 'do_shortcode' ) !== false ) {19 add_filter( 'widget_text', 'do_shortcode' );20 }18 if ( has_filter( 'widget_text', 'do_shortcode' ) !== false ) { 19 add_filter( 'widget_text', 'do_shortcode' ); 20 } 21 21 22 $this->csstidy = new csstidy();23 $this->csstidy->load_template( 'highest_compression' );24 }22 $this->csstidy = new csstidy(); 23 $this->csstidy->load_template( 'highest_compression' ); 24 } 25 25 26 /**27 * Enqueue scripts and styles for the public pages.28 */29 public function enqueue_scripts() {30 $min = SCRIPT_DEBUG ? '' : '.min';26 /** 27 * Enqueue scripts and styles for the public pages. 28 */ 29 public function enqueue_scripts() { 30 $min = SCRIPT_DEBUG ? '' : '.min'; 31 31 32 wp_register_script( 'gaoo-public', GAOO_PLUGIN_URL . '/assets/public' . $min . '.js', array(), false, true );33 }32 wp_register_script( 'gaoo-public', GAOO_PLUGIN_URL . '/assets/public' . $min . '.js', array(), false, true ); 33 } 34 34 35 /**36 * Handle the shortcode.37 *38 * @return string HTML code or empty string on error.39 */40 public function shortcode() {41 $form_data = GAOO_Utils::get_options();42 $ua_code = GAOO_Utils::get_ua_code( $form_data['ga_plugin'], $form_data['ua_code'] );35 /** 36 * Handle the shortcode. 37 * 38 * @return string HTML code or empty string on error. 39 */ 40 public function shortcode() { 41 $form_data = GAOO_Utils::get_options(); 42 $ua_code = GAOO_Utils::get_code( $form_data[ 'ga_plugin' ], $form_data[ 'ua_code' ] ); 43 43 44 // Disable shortcode if status is deactivated or set to manual but empty UA-Code45 if ( $form_data['status'] == 'off' || empty( $ua_code ) ) {46 return '';47 }44 // Disable shortcode if status is deactivated or set to manual but empty UA-Code 45 if ( $form_data[ 'status' ] == 'off' || empty( $ua_code ) ) { 46 return ''; 47 } 48 48 49 $current_status = isset( $_COOKIE[ 'ga-disable-' . $ua_code ] ) && $_COOKIE[ 'ga-disable-' . $ua_code ] == true ? 'activate' : 'deactivate';50 $json_data = GAOO_Utils::get_json( $form_data, $ua_code );49 $current_status = isset( $_COOKIE[ 'ga-disable-' . $ua_code ] ) && $_COOKIE[ 'ga-disable-' . $ua_code ] == true ? 'activate' : 'deactivate'; 50 $json_data = GAOO_Utils::get_json( $form_data, $ua_code ); 51 51 52 if ( empty( $json_data ) ) {53 return '';54 }52 if ( empty( $json_data ) ) { 53 return ''; 54 } 55 55 56 wp_localize_script( 'gaoo-public', 'gaoo_data', $json_data );57 wp_enqueue_script( 'gaoo-public' );56 wp_localize_script( 'gaoo-public', 'gaoo_data', $json_data ); 57 wp_enqueue_script( 'gaoo-public' ); 58 58 59 do_action( 'gaoo_before_shortcode', $ua_code, $current_status );59 do_action( 'gaoo_before_shortcode', $ua_code, $current_status ); 60 60 61 $html = '<a href="javascript:gaoo_handle_optout();" id="gaoo-link" class="gaoo-link-' . esc_attr( $current_status ) . '">' . esc_html( $json_data[ "link_" . $current_status ] ) . '</a>';61 $html = '<a href="javascript:gaoo_handle_optout();" id="gaoo-link" class="gaoo-link-' . esc_attr( $current_status ) . '">' . esc_html( $json_data[ "link_" . $current_status ] ) . '</a>'; 62 62 63 if ( ! empty( $form_data['custom_css'] ) && $this->csstidy->parse( $form_data['custom_css'] ) ) {64 $html .= '<style type="text/css">' . $this->csstidy->print->plain() . '</style>';65 }63 if ( ! empty( $form_data[ 'custom_css' ] ) && $this->csstidy->parse( $form_data[ 'custom_css' ] ) ) { 64 $html .= '<style type="text/css">' . $this->csstidy->print->plain() . '</style>'; 65 } 66 66 67 do_action( 'gaoo_after_shortcode', $ua_code, $current_status );67 do_action( 'gaoo_after_shortcode', $ua_code, $current_status ); 68 68 69 return $html;70 }69 return $html; 70 } 71 71 72 /**73 * Adds the GA Opt-Out code to the header.74 */75 public function head_script() {76 $form_data = GAOO_Utils::get_options();77 $ua_code = GAOO_Utils::get_ua_code( $form_data['ga_plugin'], $form_data['ua_code'] );72 /** 73 * Adds the GA Opt-Out code to the header. 74 */ 75 public function head_script() { 76 $form_data = GAOO_Utils::get_options(); 77 $ua_code = GAOO_Utils::get_code( $form_data[ 'ga_plugin' ], $form_data[ 'ua_code' ] ); 78 78 79 do_action( 'gaoo_before_head_script', $ua_code );79 do_action( 'gaoo_before_head_script', $ua_code ); 80 80 81 if ( $form_data['status'] == 'on' && ! empty( $ua_code ) ) {82 echo "<script>var disableStr = 'ga-disable-{$ua_code}'; if (document.cookie.indexOf(disableStr + '=true') > -1) { window[disableStr] = true; }</script>";83 }81 if ( $form_data[ 'status' ] == 'on' && ! empty( $ua_code ) ) { 82 echo "<script>var disableStr = 'ga-disable-{$ua_code}'; if (document.cookie.indexOf(disableStr + '=true') > -1) { window[disableStr] = true; }</script>"; 83 } 84 84 85 if ( ! empty( $form_data['tracking_code'] ) ) {86 echo preg_replace( '/\s+/', '', stripslashes( $form_data['tracking_code'] ) );87 }85 if ( ! empty( $form_data[ 'tracking_code' ] ) ) { 86 echo preg_replace( '/\s+/', ' ', stripslashes( $form_data['tracking_code'] ) ); 87 } 88 88 89 do_action( 'gaoo_after_head_script', $ua_code );90 }89 do_action( 'gaoo_after_head_script', $ua_code ); 90 } 91 91 92 }92 } -
opt-out-for-google-analytics/trunk/inc/utils.class.php
r2574575 r2664664 38 38 39 39 if ( empty( $ua_code ) && ! empty( $form_data ) ) { 40 $ua_code = GAOO_Utils::get_ ua_code( $form_data[ 'ga_plugin' ], $form_data[ 'ua_code' ] );40 $ua_code = GAOO_Utils::get_code( $form_data[ 'ga_plugin' ], $form_data[ 'ua_code' ] ); 41 41 } 42 42 … … 128 128 129 129 /** 130 * Returns the UA- Code130 * Returns the UA- or G-Code 131 131 * 132 132 * @param string $ga_plugin Key (monsterinsights, gadash, analytify, manual) of choosen GA Plugin 133 133 * @param string $ua_code The UA-Code if GA Plugin is set to manual (Default: null) 134 134 * 135 * @return string The UA- Code (UA-XXXXXX-Y)136 */ 137 public static function get_ ua_code( $ga_plugin, $ua_code = null ) {135 * @return string The UA- or G-Code (UA-XXXXXX-Y or G-XXXXXXXXXX) 136 */ 137 public static function get_code( $ga_plugin, $ua_code = null ) { 138 138 139 139 switch ( $ga_plugin ) { 140 140 case 'monsterinsights': 141 142 if ( function_exists( 'monsterinsights_get_ua_to_output' ) ) { 141 $ua_code = null; 142 143 if ( function_exists( 'monsterinsights_get_v4_id_to_output' ) ) { 144 $ua_code = monsterinsights_get_v4_id_to_output(); 145 } 146 147 if ( function_exists( 'monsterinsights_get_ua_to_output' ) && empty( $ua_code ) ) { 143 148 $ua_code = monsterinsights_get_ua_to_output(); 144 149 } … … 147 152 148 153 case 'gadash': 154 $ua_code = null; 149 155 150 156 // backward compatibility to older versions … … 167 173 $ua_code = $profile_info[ 2 ]; 168 174 } 169 170 if ( function_exists( 'exactmetrics_get_ua' ) ) { 175 elseif ( function_exists( 'exactmetrics_get_v4_id' ) ) { 176 $ua_code = exactmetrics_get_v4_id(); 177 } 178 179 if ( function_exists( 'exactmetrics_get_ua' ) && empty( $ua_code ) ) { 171 180 $ua_code = exactmetrics_get_ua(); 172 181 } … … 268 277 $ua_code = str_replace( array( '–', '—', '−' ), '-', $ua_code ); 269 278 270 if ( preg_match( "/^ (UA|YT|MO)-\d{4,}-\d+$/", strval( $ua_code )) ) {279 if ( preg_match( "/^UA-\d{4,}-\d+$/", $ua_code ) || self::is_ga4_code( $ua_code ) ) { 271 280 return $ua_code; 272 281 } 273 282 274 283 return ''; 284 } 285 286 /** 287 * Check if the code is a Google Analytics 4 code. 288 * 289 * @param string $code Code to check. 290 * 291 * @return bool True if it is GA4, otherwise false. 292 */ 293 public static function is_ga4_code( $code ) { 294 return ( empty( $code ) ? false : boolval( preg_match( "/^G-[A-Za-z\d]+$/", $code ) ) ); 275 295 } 276 296 … … 393 413 $anonymip_enabled = $analytify->settings->get_option( 'anonymize_ip', 'wp-analytify-advanced' ); 394 414 $anonymip_url = admin_url( 'admin.php?page=analytify-settings#wp-analytify-advanced' ); 395 396 $uacode_url = admin_url( 'admin.php?page=analytify-settings#wp-analytify-advanced' ); 397 415 $uacode_url = admin_url( 'admin.php?page=analytify-settings#wp-analytify-authentication' ); 398 416 } 399 417 elseif ( $data[ 'ga_plugin' ] == 'gaga' && ! empty( $GLOBALS[ 'GA_Google_Analytics' ] ) ) { … … 403 421 $anonymip_enabled = ( ! empty( $options[ 'gap_anonymize' ] ) ) ? $options[ 'gap_anonymize' ] : false; 404 422 $anonymip_url = admin_url( 'options-general.php?page=ga-google-analytics#gap-panel-settings' ); 405 406 $uacode_url = admin_url( 'options-general.php?page=ga-google-analytics#gap-panel-settings' ); 423 $uacode_url = admin_url( 'options-general.php?page=ga-google-analytics#gap-panel-settings' ); 407 424 408 425 } 409 426 elseif ( $data[ 'ga_plugin' ] == 'sitekit' && ( $analytics = get_option( 'googlesitekit_analytics_settings' ) ) ) { 410 427 $anonymip_url = null; 411 $uacode_url = admin_url( 'admin.php?page=googlesitekit- module-analytics' );428 $uacode_url = admin_url( 'admin.php?page=googlesitekit-settings' ); 412 429 $anonymip_enabled = ! empty( $analytics[ 'anonymizeIP' ] ); 413 430 } … … 415 432 $anonymip_enabled = $anonymip_url = $uacode_url = null; 416 433 417 if ( ! empty( $data[ 'tracking_code' ] ) ) { 434 if ( GAOO_Utils::is_ga4_code( $data[ 'ua_code' ] ) ) { 435 $anonymip_enabled = true; 436 } 437 elseif ( ! empty( $data[ 'tracking_code' ] ) ) { 418 438 $anonymip_enabled = (bool) preg_match_all( '/(anonymizeIp|anonymize_ip).*true/mi', $data[ 'tracking_code' ] ); 419 439 } 420 440 } 421 441 422 $ua_code = GAOO_Utils::get_ ua_code( $data[ 'ga_plugin' ] );442 $ua_code = GAOO_Utils::get_code( $data[ 'ga_plugin' ] ); 423 443 $ua_code_txt = empty( $ua_code ) ? '' : " ($ua_code)"; 424 444 $checklist = array( … … 428 448 ), 429 449 array( 430 'label' => esc_html__( 'Found valid UA-Code', 'opt-out-for-google-analytics' ) . $ua_code_txt,450 'label' => esc_html__( 'Found valid code', 'opt-out-for-google-analytics' ) . $ua_code_txt, 431 451 'checked' => ( ! empty( $ua_code ) ), 432 452 'url' => $uacode_url, -
opt-out-for-google-analytics/trunk/readme.txt
r2574575 r2664664 3 3 Tags: google analytics, opt-out, dsgvo, gdpr, analytics 4 4 Requires at least: 3.5 5 Tested up to: 5. 85 Tested up to: 5.9 6 6 Requires PHP: 7.0 7 Stable tag: 1.97 Stable tag: 2.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 20 20 **Features** 21 21 22 * **Full integration of the new WordPress DSGVO / GDPR features** 22 * **Support for Google Analytics 4 (GA4)** 23 * Full integration of the new WordPress DSGVO / GDPR features 23 24 * Weekly check whether the settings are still data protection compliant! 24 25 * Compatible with Google Tag Manager. … … 287 288 == Changelog == 288 289 290 = 2.0 = 291 * Added: Support for Google Analytics 4 (GA4) 292 * Added: MonsterInsights GA4 support 293 * Added: ExactMetrics GA4 support 294 * Added: Analytify GA4 support 295 * Added: GA Google Analytics GA4 support 296 * Updated: Support for WordPress 5.9 297 * Tweaks: Several code tweaks & cleanup 298 289 299 = 1.9 = 290 300 * Updated: Support for WordPress 5.8 -
opt-out-for-google-analytics/trunk/templates/settings.php
r2524476 r2664664 23 23 <span class="gaoo-clipboard dashicons dashicons-admin-page" title="<?php esc_attr_e( 'Click to copy the shortcode!', 'opt-out-for-google-analytics' ); ?>" data-copy="<?php echo esc_attr( GAOO_SHORTCODE ); ?>"></span> 24 24 <br /> 25 <small><?php printf( __( "Do you have a data processing agreement for Google Analytics? <a href='%s' target='_blank'>More infos.</a>", 'opt-out-for-google-analytics' ), esc_url( 'https://support.google.com/analytics/answer/3379636?hl=' . ( empty( $language ) ?: $language ) ) ); ?></small> 25 26 <small><?php esc_html_e( "Do you have a data processing agreement for Google Analytics?", 'opt-out-for-google-analytics' ); ?> 27 <?php printf( "<a href='%s' target='_blank'>%s</a>", esc_url( 'https://support.google.com/analytics/answer/3379636?hl=' . ( empty( $language ) ?: $language ) ), esc_html__( 'More infos.', 'opt-out-for-google-analytics' ) ); ?></small> 26 28 </p> 27 29 … … 47 49 <tr> 48 50 <th scope="row"> 49 <label><?php esc_html_e( " UA-Code", 'opt-out-for-google-analytics' ); ?></label>51 <label><?php esc_html_e( "Tracking ID", 'opt-out-for-google-analytics' ); ?></label> 50 52 </th> 51 53 <td> … … 58 60 </label> 59 61 60 <p <?php echo $is_manual ? '' : 'class="hide"'; ?>> 61 <input type="text" id="gaoo-ua-code" name="gaoo[ua_code]" class="text" placeholder="UA-XXXXXX-Y" value="<?php echo esc_attr( $ua_code ); ?>" /><br> 62 <div <?php echo $is_manual ? '' : 'class="hide"'; ?>> 63 <input type="text" id="gaoo-ua-code" name="gaoo[ua_code]" class="regular-text" placeholder="<?php esc_attr_e( 'G-XXXXXXXXXX or UA-XXXXXX-Y', 'opt-out-for-google-analytics' ); ?>" value="<?php echo esc_attr( $ua_code ); ?>" /><br> 64 65 <p> 66 <small><?php esc_html_e( "Searching for your code?", 'opt-out-for-google-analytics' ); ?> 67 <?php printf( "<a href='%s' target='_blank'>%s</a>", esc_url( 'https://support.google.com/analytics/answer/9539598?hl=' . ( empty( $language ) ?: $language ) ), esc_html__( 'More infos.', 'opt-out-for-google-analytics' ) ); ?></small> 68 </p> 69 62 70 <textarea id="ga-plugin-tracking-code" class="regular-text" rows="10" name="gaoo[tracking_code]" placeholder="<?php esc_attr_e( 'Enter here your tracking code for Google Analytics to insert it on your whole website. Leave empty if you do not want it.', 'opt-out-for-google-analytics' ); ?>"><?php echo stripslashes( $tracking_code ); ?></textarea> 63 </ p>71 </div> 64 72 <br /> 65 73
Note: See TracChangeset
for help on using the changeset viewer.