WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics
Removed analytics code for logged in users (2 posts)

  1. dake84
    Member
    Posted 1 year ago #

    Thanks alot for that simple plugin. However I wanted to remove the analytics code when a user was logged into wordpress.

    I achieved this by replacing the lines 55-bottom from the current release (1.0.5) with this code:

    function add_analytics_code(){
      if (!is_user_logged_in()) {
       add_action('wp_head', 'googleanalytics');
     }
    }
    
    register_activation_hook(__FILE__, 'activate_googleanalytics');
    register_deactivation_hook(__FILE__, 'deactive_googleanalytics');
    
    if (is_admin()) {
      add_action('admin_init', 'admin_init_googleanalytics');
      add_action('admin_menu', 'admin_menu_googleanalytics');
    } else {
      add_action('init', 'add_analytics_code');
    }
    
    ?>

    Would be glad if this change could make it to the code base (maybe the more sophisticated developer might introduce a checkbox in the options dialog or so...).

    http://wordpress.org/plugins/googleanalytics/

  2. ClaytonL
    Member
    Posted 1 year ago #

    You could put the following in your functions.php if you wanted.

    remove_action( 'wp_head', 'googleanalytics');
    if (!is_admin() && !is_user_logged_in()) {
      add_action('wp_head', 'googleanalytics');
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.